diff options
| author | ruki <[email protected]> | 2024-04-18 17:19:13 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-04-18 17:19:13 +0800 |
| commit | e170a82a9f79f0331d22e66fc4ec35d05a784d8a (patch) | |
| tree | c704874b6789cc27fa634a41b6f4722eed3a72a7 /xmake/modules | |
| parent | 78627bc254c1c9c798f802fa15ddda4cff37da87 (diff) | |
| parent | f00427931ec4125ba42325e03d306b377f3d9b1d (diff) | |
Merge pull request #4986 from xmake-io/runenvs
Improve runenvs
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/devel/debugger/run.lua | 33 | ||||
| -rw-r--r-- | xmake/modules/private/action/run/runenvs.lua | 53 |
2 files changed, 36 insertions, 50 deletions
diff --git a/xmake/modules/devel/debugger/run.lua b/xmake/modules/devel/debugger/run.lua index 6befa017e..29c3f8c45 100644 --- a/xmake/modules/devel/debugger/run.lua +++ b/xmake/modules/devel/debugger/run.lua @@ -50,9 +50,6 @@ function _run_gdb(program, argv, opt) table.insert(argv, 1, program) table.insert(argv, 1, "--args") - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it os.execv(gdb, argv, table.join(opt, {exclusive = true})) return true @@ -73,9 +70,6 @@ function _run_cudagdb(program, argv, opt) table.insert(argv, 1, program) table.insert(argv, 1, "--args") - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it os.execv(gdb, argv, table.join(opt, {exclusive = true})) return true @@ -103,9 +97,6 @@ function _run_lldb(program, argv, opt) table.insert(argv, 1, names[i]) end - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it os.execv(names[1], argv, table.join(opt, {exclusive = true})) return true @@ -124,9 +115,6 @@ function _run_windbg(program, argv, opt) argv = argv or {} table.insert(argv, 1, program) - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it opt.detach = true os.execv(windbg, argv, opt) @@ -146,9 +134,6 @@ function _run_cudamemcheck(program, argv, opt) argv = argv or {} table.insert(argv, 1, program) - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it os.execv(cudamemcheck, argv, opt) return true @@ -167,9 +152,6 @@ function _run_x64dbg(program, argv, opt) argv = argv or {} table.insert(argv, 1, program) - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it opt.detach = true os.execv(x64dbg, argv, opt) @@ -189,9 +171,6 @@ function _run_ollydbg(program, argv, opt) argv = argv or {} table.insert(argv, 1, program) - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it opt.detach = true os.execv(ollydbg, argv, opt) @@ -211,9 +190,6 @@ function _run_vsjitdebugger(program, argv, opt) argv = argv or {} table.insert(argv, 1, program) - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it opt.detach = true os.execv(vsjitdebugger, argv, opt) @@ -234,9 +210,6 @@ function _run_devenv(program, argv, opt) table.insert(argv, 1, "/DebugExe") table.insert(argv, 2, program) - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it opt.detach = true os.execv(devenv, argv, opt) @@ -332,9 +305,6 @@ function _run_gede(program, argv, opt) table.insert(argv, 1, "--args") table.insert(argv, 1, "--no-show-config") - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it os.execv(gede.program, argv, table.join(opt, {exclusive = true})) return true @@ -355,9 +325,6 @@ function _run_seergdb(program, argv, opt) table.insert(argv, 1, program) table.insert(argv, 1, "--start") - -- handle envs - opt.envs = runenvs.join(opt.addenvs, opt.setenvs) - -- run it os.execv(seergdb.program, argv, table.join(opt, {exclusive = true})) return true 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 |
