diff options
Diffstat (limited to 'xmake/modules/private/action/run/runenvs.lua')
| -rw-r--r-- | xmake/modules/private/action/run/runenvs.lua | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/xmake/modules/private/action/run/runenvs.lua b/xmake/modules/private/action/run/runenvs.lua index 1a7ba05ac..da22f6c72 100644 --- a/xmake/modules/private/action/run/runenvs.lua +++ b/xmake/modules/private/action/run/runenvs.lua @@ -23,7 +23,6 @@ import("core.base.hashset") -- add search directories for all dependent shared libraries on windows function _make_runpath_on_windows(target) - local pathenv = {} local searchdirs = hashset.new() local function insert(dir) @@ -68,9 +67,7 @@ function _make_runpath_on_windows(target) end end end - insert_target(target) - return pathenv end @@ -92,41 +89,63 @@ function join(addenvs, setenvs) return envs end -function make(target) +-- 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 - -- check - assert(target) +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 |
