summaryrefslogtreecommitdiff
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
parent56bc58325b10e39b8278e81e1852997334716efb (diff)
Refactor runenvs so renderdoc can store envs
-rw-r--r--xmake/actions/run/main.lua17
-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
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua4
-rw-r--r--xmake/plugins/project/vsxmake/getinfo.lua6
-rw-r--r--xmake/rules/xcode/application/run.lua14
7 files changed, 99 insertions, 32 deletions
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index e2f754846..25e2d905b 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -27,7 +27,7 @@ import("core.project.project")
import("core.platform.platform")
import("devel.debugger")
import("private.async.runjobs")
-import("private.action.run.make_runenvs")
+import("private.action.run.runenvs")
import("private.service.remote_build.action", {alias = "remote_build_action"})
-- run target
@@ -44,23 +44,18 @@ function _do_run_target(target)
-- get the absolute target file path
local targetfile = path.absolute(target:targetfile())
- -- add run environments
- local addrunenvs, setrunenvs = make_runenvs(target)
- for name, values in pairs(addrunenvs) do
- os.addenv(name, table.unpack(table.wrap(values)))
- end
- for name, value in pairs(setrunenvs) do
- os.setenv(name, table.unpack(table.wrap(value)))
- end
+ -- build run environments
+ local addrunenvs, setrunenvs = runenvs.make(target)
-- get run arguments
local args = table.wrap(option.get("arguments") or target:get("runargs"))
-- debugging?
if option.get("debug") then
- debugger.run(targetfile, args, {curdir = rundir})
+ debugger.run(targetfile, args, {curdir = rundir, addrunenvs = addrunenvs, setrunenvs = setrunenvs})
else
- os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach")})
+ local envs = runenvs.join(addrunenvs, setrunenvs)
+ os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach"), envs = envs})
end
end
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
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 0b491ad65..0bb65c994 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -36,7 +36,7 @@ import("vsutils")
import("core.cache.memcache")
import("core.cache.localcache")
import("private.action.require.install", {alias = "install_requires"})
-import("private.action.run.make_runenvs")
+import("private.action.run.runenvs")
import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()})
import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()})
import("private.utils.batchcmds")
@@ -324,7 +324,7 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
-- save runenvs
local runenvs = {}
- local addrunenvs, setrunenvs = make_runenvs(target)
+ local addrunenvs, setrunenvs = runenvs.make(target)
for k, v in table.orderpairs(target:pkgenvs()) do
addrunenvs = addrunenvs or {}
addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), path.splitenv(v))
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua
index 6fe8c7f90..354b44ec8 100644
--- a/xmake/plugins/project/vsxmake/getinfo.lua
+++ b/xmake/plugins/project/vsxmake/getinfo.lua
@@ -31,7 +31,7 @@ import("core.tool.toolchain")
import("core.cache.memcache")
import("core.cache.localcache")
import("lib.detect.find_tool")
-import("private.action.run.make_runenvs")
+import("private.action.run.runenvs")
import("private.action.require.install", {alias = "install_requires"})
import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()})
import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()})
@@ -165,7 +165,7 @@ function _make_targetinfo(mode, arch, target)
-- save runenvs
local runenvs = {}
- local addrunenvs, setrunenvs = make_runenvs(target)
+ local addrunenvs, setrunenvs = runenvs.make(target)
for k, v in table.orderpairs(target:pkgenvs()) do
addrunenvs = addrunenvs or {}
addrunenvs[k] = table.join(table.wrap(addrunenvs[k]), path.splitenv(v))
@@ -541,7 +541,7 @@ function main(outputdir, vsinfo)
end
end
- -- we need to set startup project for default or binary target
+ -- we need set startup project for default or binary target
-- @see https://github.com/xmake-io/xmake/issues/1249
local targetnames = {}
for targetname, target in table.orderpairs(project.targets()) do
diff --git a/xmake/rules/xcode/application/run.lua b/xmake/rules/xcode/application/run.lua
index 0e0663207..5f7d1585d 100644
--- a/xmake/rules/xcode/application/run.lua
+++ b/xmake/rules/xcode/application/run.lua
@@ -21,7 +21,7 @@
-- imports
import("core.base.option")
import("devel.debugger")
-import("private.action.run.make_runenvs")
+import("private.action.run.runenvs")
-- run on macosx
function _run_on_macosx(target, opt)
@@ -38,19 +38,13 @@ function _run_on_macosx(target, opt)
local oldir = os.cd(rundir)
-- add run environments
- local addrunenvs, setrunenvs = make_runenvs(target)
- for name, values in pairs(addrunenvs) do
- os.addenv(name, table.unpack(table.wrap(values)))
- end
- for name, value in pairs(setrunenvs) do
- os.setenv(name, table.unpack(table.wrap(value)))
- end
+ local addrunenvs, setrunenvs = runenvs.make(target)
-- debugging?
if option.get("debug") then
- debugger.run(targetfile, option.get("arguments"))
+ debugger.run(targetfile, option.get("arguments"), {addrunenvs = addrunenvs, setrunenvs = setrunenvs})
else
- os.execv(targetfile, option.get("arguments"))
+ os.execv(targetfile, option.get("arguments"), {envs = runenvs.join()})
end
-- restore the previous directory