summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-18 00:00:35 +0800
committerruki <[email protected]>2024-04-18 00:00:35 +0800
commit42786255ed8b8ba449415185eba6a765a5084513 (patch)
treed29f6ace2776f2af852fe3b241338bdbcc914949
parent5f33d0c880336729839ba7737fecfc73e9eb7207 (diff)
improve os.execv and runenvs #4980
-rw-r--r--xmake/actions/run/main.lua3
-rw-r--r--xmake/core/base/os.lua36
-rw-r--r--xmake/modules/devel/debugger/run.lua33
-rw-r--r--xmake/modules/private/action/run/runenvs.lua6
4 files changed, 29 insertions, 49 deletions
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index 217f87c66..0c519473b 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -54,8 +54,7 @@ function _do_run_target(target)
if option.get("debug") then
debugger.run(targetfile, args, {curdir = rundir, addenvs = addenvs, setenvs = setenvs})
else
- local envs = runenvs.join(addenvs, setenvs)
- os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach"), envs = envs})
+ os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach"), addenvs = addenvs, setenvs = setenvs})
end
end
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 2d7023ac4..967c02097 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -830,17 +830,37 @@ function os.execv(program, argv, opt)
-- uses the given environments?
local envs = nil
- if opt.envs then
+ local setenvs = opt.setenvs or opt.envs
+ local addenvs = opt.addenvs
+ if setenvs or addenvs then
local envars = os.getenvs()
- for k, v in pairs(opt.envs) do
- if type(v) == "table" then
- v = path.joinenv(v)
+ if setenvs then
+ for k, v in pairs(setenvs) do
+ 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
- -- 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
+ if addenvs then
+ for k, v in pairs(addenvs) do
+ 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
+ end
end
- envars[k] = v
end
envs = {}
for k, v in pairs(envars) do
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..7349b1d69 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
@@ -94,9 +91,6 @@ end
function make(target)
- -- check
- assert(target)
-
-- add run environments
local set = {}
local add = {}