summaryrefslogtreecommitdiff
path: root/xmake/core/base/os.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-07-13 00:11:40 +0800
committerruki <[email protected]>2021-07-13 00:11:40 +0800
commit6382ff0ea787970774a8658b0e4c5e1d5a546672 (patch)
tree9ef5d6b883268e134f8f9237701cf6117729c7a2 /xmake/core/base/os.lua
parent4d62362c12ec2c3dbf387cbee561574c051d4bcf (diff)
fix long env path
Diffstat (limited to 'xmake/core/base/os.lua')
-rw-r--r--xmake/core/base/os.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 10b6d0bcc..15883dffc 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -238,6 +238,37 @@ function os._match_wildcard_pathes(v)
return v
end
+-- split too long path environment variable for windows
+--
+-- @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]
+ if value and #value > 4096 then
+ local value_more = {}
+ local value_left = {}
+ local more_length = 0
+ 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)
+ 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)
+ end
+ end
+end
+
-- match files or directories
--
-- @param pattern the search pattern
@@ -700,6 +731,10 @@ function os.execv(program, argv, opt)
v = path.joinenv(v)
end
envars[k] = v
+ -- we need fix too long value before running process
+ if os.host() == "windows" and #v > 4096 then
+ os._split_long_pathenv(envars, k)
+ end
end
envs = {}
for k, v in pairs(envars) do