summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorSirLynix <[email protected]>2023-07-21 17:24:04 +0200
committerSirLynix <[email protected]>2023-07-21 17:24:04 +0200
commit30f29b8dd316cfee6404b1fa4ca9815a4f02c9a8 (patch)
tree25b49be91e2d220c627618a69e92e77aae5bd5ef /xmake/modules
parent56bc58325b10e39b8278e81e1852997334716efb (diff)
Refactor runenvs so renderdoc can store envs
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/devel/debugger/run.lua61
-rw-r--r--xmake/modules/private/action/run/runenvs.lua (renamed from xmake/modules/private/action/run/make_runenvs.lua)25
-rw-r--r--xmake/modules/private/xrepo/action/env.lua4
3 files changed, 84 insertions, 6 deletions
diff --git a/xmake/modules/devel/debugger/run.lua b/xmake/modules/devel/debugger/run.lua
index 37ed22d97..ea92ede2c 100644
--- a/xmake/modules/devel/debugger/run.lua
+++ b/xmake/modules/devel/debugger/run.lua
@@ -33,6 +33,7 @@ import("detect.tools.find_devenv")
import("detect.tools.find_vsjitdebugger")
import("detect.tools.find_renderdoc")
import("lib.detect.find_tool")
+import("private.action.run.runenvs")
-- run gdb
function _run_gdb(program, argv, opt)
@@ -49,6 +50,9 @@ function _run_gdb(program, argv, opt)
table.insert(argv, 1, program)
table.insert(argv, 1, "--args")
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
os.execv(gdb, argv, table.join(opt, {exclusive = true}))
return true
@@ -69,6 +73,9 @@ function _run_cudagdb(program, argv, opt)
table.insert(argv, 1, program)
table.insert(argv, 1, "--args")
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
os.execv(gdb, argv, table.join(opt, {exclusive = true}))
return true
@@ -96,6 +103,9 @@ function _run_lldb(program, argv, opt)
table.insert(argv, 1, names[i])
end
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
os.execv(names[1], argv, table.join(opt, {exclusive = true}))
return true
@@ -114,6 +124,9 @@ function _run_windbg(program, argv, opt)
argv = argv or {}
table.insert(argv, 1, program)
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
opt.detach = true
os.execv(windbg, argv, opt)
@@ -133,6 +146,9 @@ function _run_cudamemcheck(program, argv, opt)
argv = argv or {}
table.insert(argv, 1, program)
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
os.execv(cudamemcheck, argv, opt)
return true
@@ -151,6 +167,9 @@ function _run_x64dbg(program, argv, opt)
argv = argv or {}
table.insert(argv, 1, program)
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
opt.detach = true
os.execv(x64dbg, argv, opt)
@@ -170,6 +189,9 @@ function _run_ollydbg(program, argv, opt)
argv = argv or {}
table.insert(argv, 1, program)
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
opt.detach = true
os.execv(ollydbg, argv, opt)
@@ -189,6 +211,9 @@ function _run_vsjitdebugger(program, argv, opt)
argv = argv or {}
table.insert(argv, 1, program)
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
opt.detach = true
os.execv(vsjitdebugger, argv, opt)
@@ -209,6 +234,9 @@ function _run_devenv(program, argv, opt)
table.insert(argv, 1, "/DebugExe")
table.insert(argv, 2, program)
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
opt.detach = true
os.execv(devenv, argv, opt)
@@ -225,12 +253,35 @@ function _run_renderdoc(program, argv, opt)
end
-- build capture settings
+ local environment = {}
+ if opt.addrunenvs then
+ for name, values in pairs(opt.addrunenvs) do
+ table.insert(environment, {
+ separator = "Platform style",
+ type = "Append",
+ value = table.concat(values, path.envsep()),
+ variable = name
+ })
+ end
+ end
+
+ if opt.setrunenvs then
+ for name, values in pairs(opt.setrunenvs) do
+ table.insert(environment, {
+ separator = "Platform style",
+ type = "Set",
+ value = table.concat(values, path.envsep()),
+ variable = name
+ })
+ end
+ end
+
local settings = {
rdocCaptureSettings = 1,
settings = {
autoStart = false,
commandLine = table.concat(table.wrap(argv), " "),
- environment = json.mark_as_array({}),
+ environment = json.mark_as_array(environment),
executable = program,
inject = false,
numQueuedFrames = 0,
@@ -258,6 +309,8 @@ function _run_renderdoc(program, argv, opt)
-- run renderdoc
opt.detach = true
+ opt.addrunenvs = nil
+ opt.setrunenvs = nil
os.execv(renderdoc, { capturefile }, opt)
return true
end
@@ -279,6 +332,9 @@ 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.addrunenvs, opt.setrunenvs)
+
-- run it
os.execv(gede.program, argv, table.join(opt, {exclusive = true}))
return true
@@ -299,6 +355,9 @@ function _run_seergdb(program, argv, opt)
table.insert(argv, 1, program)
table.insert(argv, 1, "--start")
+ -- handle envs
+ opt.envs = runenvs.join(opt.addrunenvs, opt.setrunenvs)
+
-- run it
os.execv(seergdb.program, argv, table.join(opt, {exclusive = true}))
return true
diff --git a/xmake/modules/private/action/run/make_runenvs.lua b/xmake/modules/private/action/run/runenvs.lua
index 8b804e3fc..425b119c5 100644
--- a/xmake/modules/private/action/run/make_runenvs.lua
+++ b/xmake/modules/private/action/run/runenvs.lua
@@ -14,8 +14,8 @@
--
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
--- @author ruki, OpportunityLiu
--- @file make_runenvs.lua
+-- @author ruki, OpportunityLiu, SirLynix
+-- @file runenvs.lua
--
-- imports
@@ -66,7 +66,26 @@ function _make_runpath_on_windows(target)
return pathenv
end
-function main(target)
+-- flatten envs ({PATH = {"A", "B"}} => {PATH = "A;B"})
+function _flatten_envs(envs)
+ local flatten_envs = {}
+ for name, values in pairs(envs) do
+ flatten_envs[name] = table.concat(values, path.envsep())
+ end
+
+ return flatten_envs
+end
+
+function join(addrunenvs, setrunenvs)
+ local envs = addrunenvs and _flatten_envs(addrunenvs) or {}
+ if setrunenvs then
+ table.join2(envs, _flatten_envs(setrunenvs))
+ end
+
+ return envs
+end
+
+function make(target)
-- check
assert(target)
diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua
index 4a092df54..fb4c0ea68 100644
--- a/xmake/modules/private/xrepo/action/env.lua
+++ b/xmake/modules/private/xrepo/action/env.lua
@@ -27,7 +27,7 @@ import("core.project.config")
import("core.project.project")
import("core.tool.toolchain")
import("lib.detect.find_tool")
-import("private.action.run.make_runenvs")
+import("private.action.run.runenvs")
import("private.action.require.impl.package")
import("private.action.require.impl.utils.get_requires")
@@ -234,7 +234,7 @@ function _target_addenvs(envs)
end
end
-- add run environments
- local addrunenvs = make_runenvs(target)
+ local addrunenvs = runenvs.make(target)
for name, values in pairs(addrunenvs) do
_addenvs(envs, name, table.unpack(table.wrap(values)))
end