summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-07-13 22:45:15 +0800
committerruki <[email protected]>2021-07-13 22:45:15 +0800
commiteaa76b42ea28054bb96643c21e2bc729850b5359 (patch)
treead91454b277858d5b6ebd93127373565fb96b9c0
parent52f17b5f01e5ae4be5f50b0d8f9e8338dd87879d (diff)
improve os.execv
-rw-r--r--xmake/core/base/os.lua37
1 files changed, 14 insertions, 23 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index a2856fd66..2b8773163 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -243,32 +243,24 @@ end
-- @see https://github.com/xmake-io/xmake-repo/pull/489
-- https://stackoverflow.com/questions/34491244/environment-variable-is-too-large-on-windows-10
--
-function os._split_long_pathenv(envs, name)
- local value = envs[name]
+function os._remove_repeat_pathenv(value)
if value and #value > 4096 then
- local value_more = {}
- local value_left = {}
- local more_length = 0
+ local itemset = {}
+ local results = {}
for _, item in ipairs(path.splitenv(value)) do
- if #value - more_length > 4096 then
- table.insert(value_more, item)
- more_length = more_length + #item + 1
- else
- table.insert(value_left, item)
+ if not itemset[item] then
+ table.insert(results, item)
+ itemset[item] = true
end
end
- if #value_left > 0 and #value_more > 0 then
- -- fix long path
- -- PATH="%__MORE_PATH__%;left values"
- -- __MORE_PATH__="more values"
- local morename = "__MORE_" .. name:upper() .. "__"
- table.insert(value_left, 1, "%" .. morename .. "%")
- envs[morename] = path.joinenv(value_more)
- envs[name] = path.joinenv(value_left)
+ if #results > 0 then
+ value = path.joinenv(results)
end
end
+ return value
end
+
-- match files or directories
--
-- @param pattern the search pattern
@@ -730,12 +722,11 @@ function os.execv(program, argv, opt)
if type(v) == "table" then
v = path.joinenv(v)
end
- envars[k] = v
- -- we need fix too long value before running process
- --[[
+ -- we try to fix too long value before running process
if type(v) == "string" and #v > 4096 and os.host() == "windows" then
- os._split_long_pathenv(envars, k)
- end]]
+ v = os._remove_repeat_pathenv(v)
+ end
+ envars[k] = v
end
envs = {}
for k, v in pairs(envars) do