summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-18 23:45:14 +0800
committerruki <[email protected]>2024-04-18 23:45:14 +0800
commitf00427931ec4125ba42325e03d306b377f3d9b1d (patch)
tree60f92d1fc99c39a5ee288109575d58c506130896
parent42786255ed8b8ba449415185eba6a765a5084513 (diff)
improve to make runenvs
-rw-r--r--xmake/core/base/os.lua16
-rw-r--r--xmake/modules/private/action/run/runenvs.lua47
2 files changed, 42 insertions, 21 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 967c02097..b0545afc8 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -839,10 +839,6 @@ function os.execv(program, argv, opt)
if type(v) == "table" then
v = path.joinenv(v)
end
- -- we try to fix too long value before running process
- if type(v) == "string" and #v > 4096 and os.host() == "windows" then
- v = os._deduplicate_pathenv(v)
- end
envars[k] = v
end
end
@@ -851,19 +847,19 @@ function os.execv(program, argv, opt)
if type(v) == "table" then
v = path.joinenv(v)
end
- if type(v) == "string" and #v > 4096 and os.host() == "windows" then
- v = os._deduplicate_pathenv(v)
- end
local o = envars[k]
if o then
- envars[k] = v .. path.envsep() .. o
- else
- envars[k] = v
+ v = v .. path.envsep() .. o
end
+ envars[k] = v
end
end
envs = {}
for k, v in pairs(envars) do
+ -- we try to fix too long value before running process
+ if type(v) == "string" and #v > 4096 and os.host() == "windows" then
+ v = os._deduplicate_pathenv(v)
+ end
table.insert(envs, k .. '=' .. v)
end
end
diff --git a/xmake/modules/private/action/run/runenvs.lua b/xmake/modules/private/action/run/runenvs.lua
index 7349b1d69..da22f6c72 100644
--- a/xmake/modules/private/action/run/runenvs.lua
+++ b/xmake/modules/private/action/run/runenvs.lua
@@ -89,38 +89,63 @@ function join(addenvs, setenvs)
return envs
end
+-- recursively add package envs
+function _add_target_pkgenvs(addenvs, target, targets_added)
+ if targets_added[target:name()] then
+ return
+ end
+ targets_added[target:name()] = true
+ local pkgenvs = target:pkgenvs()
+ if pkgenvs then
+ for name, values in pairs(pkgenvs) do
+ values = path.splitenv(values)
+ local oldenvs = addenvs[name]
+ if oldenvs then
+ table.join2(oldenvs, values)
+ else
+ addenvs[name] = values
+ end
+ end
+ end
+ for _, dep in ipairs(target:orderdeps()) do
+ _add_target_pkgenvs(addenvs, dep, targets_added)
+ end
+end
+
function make(target)
-- add run environments
- local set = {}
- local add = {}
+ local setenvs = {}
+ local addenvs = {}
local runenvs = target:get("runenvs")
if runenvs then
for name, values in pairs(runenvs) do
- add[name] = table.wrap(values)
+ addenvs[name] = table.wrap(values)
end
end
local runenv = target:get("runenv")
if runenv then
for name, value in pairs(runenv) do
- set[name] = table.wrap(value)
- if add[name] then
+ setenvs[name] = table.wrap(value)
+ if addenvs[name] then
utils.warning(format("both add_runenvs and set_runenv called on environment variable \"%s\", the former one will be ignored.", name))
- add[name] = nil
+ addenvs[name] = nil
end
end
end
+ -- add package run environments
+ _add_target_pkgenvs(addenvs, target, {})
+
-- add search directories for all dependent shared libraries on windows
if target:is_plat("windows") or (target:is_plat("mingw") and is_host("windows")) then
- -- get PATH table
- local pathenv = add["PATH"] or set["PATH"]
+ local pathenv = addenvs["PATH"] or setenvs["PATH"]
local runpath = _make_runpath_on_windows(target)
if pathenv == nil then
- add["PATH"] = runpath
+ addenvs["PATH"] = runpath
else
- table.append(pathenv, table.unpack(runpath))
+ table.join2(pathenv, runpath)
end
end
- return add, set
+ return addenvs, setenvs
end