diff options
| author | ruki <[email protected]> | 2023-07-24 09:57:04 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-24 09:57:04 +0800 |
| commit | a66ddd6fca5c2334a5d812730857b3a2665866be (patch) | |
| tree | d63f718719078869e9d0bc86165acd21ea7b7dc2 | |
| parent | 22cd7c1f77d5db69e474026e195388fd52f8a84d (diff) | |
| parent | 9dc81de82d74021532baa648df4a0007acbb0d2f (diff) | |
Merge pull request #3989 from SirLynix/renderdoc_envs
Refactor runenvs so renderdoc can store envs
| -rw-r--r-- | xmake/actions/run/main.lua | 17 | ||||
| -rw-r--r-- | xmake/modules/devel/debugger/run.lua | 61 | ||||
| -rw-r--r-- | xmake/modules/private/action/run/runenvs.lua (renamed from xmake/modules/private/action/run/make_runenvs.lua) | 24 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/action/env.lua | 4 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 18 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 18 | ||||
| -rw-r--r-- | xmake/rules/xcode/application/run.lua | 14 |
7 files changed, 111 insertions, 45 deletions
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index e2f754846..eca4d8e29 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 addenvs, setenvs = 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, addenvs = addenvs, setenvs = setenvs}) else - os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach")}) + local envs = runenvs.join(addenvs, setenvs) + 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..6befa017e 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.addenvs, opt.setenvs) + -- 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.addenvs, opt.setenvs) + -- 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.addenvs, opt.setenvs) + -- 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.addenvs, opt.setenvs) + -- 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.addenvs, opt.setenvs) + -- 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.addenvs, opt.setenvs) + -- 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.addenvs, opt.setenvs) + -- 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.addenvs, opt.setenvs) + -- 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.addenvs, opt.setenvs) + -- 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.addenvs then + for name, values in pairs(opt.addenvs) do + table.insert(environment, { + separator = "Platform style", + type = "Append", + value = path.joinenv(values), + variable = name + }) + end + end + + if opt.setenvs then + for name, values in pairs(opt.setenvs) do + table.insert(environment, { + separator = "Platform style", + type = "Set", + value = path.joinenv(values), + 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.addenvs = nil + opt.setenvs = 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.addenvs, opt.setenvs) + -- 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.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/make_runenvs.lua b/xmake/modules/private/action/run/runenvs.lua index 8b804e3fc..9f1473335 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,25 @@ 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] = path.joinenv(values) + end + return flatten_envs +end + +-- join addenvs and setenvs in a common envs table +function join(addenvs, setenvs) + local envs = os.joinenvs(addenvs and _flatten_envs(addenvs) or {}) + if setenvs then + envs = os.joinenvs(envs, _flatten_envs(setenvs)) + 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..39cfcc65c 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") @@ -323,8 +323,8 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) targetinfo.rundir = target:rundir() -- save runenvs - local runenvs = {} - local addrunenvs, setrunenvs = make_runenvs(target) + local targetrunenvs = {} + 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)) @@ -337,25 +337,25 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) end for k, v in table.orderpairs(addrunenvs) do if k:upper() == "PATH" then - runenvs[k] = _translate_path(v, vcxprojdir) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .. "'))" + targetrunenvs[k] = _translate_path(v, vcxprojdir) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .. "'))" else - runenvs[k] = path.joinenv(v) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .."'))" + targetrunenvs[k] = path.joinenv(v) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .."'))" end end for k, v in table.orderpairs(setrunenvs) do if #v == 1 then v = v[1] if path.is_absolute(v) and v:startswith(project.directory()) then - runenvs[k] = _translate_path(v, vcxprojdir) + targetrunenvs[k] = _translate_path(v, vcxprojdir) else - runenvs[k] = v[1] + targetrunenvs[k] = v[1] end else - runenvs[k] = path.joinenv(v) + targetrunenvs[k] = path.joinenv(v) end end local runenvstr = {} - for k, v in table.orderpairs(runenvs) do + for k, v in table.orderpairs(targetrunenvs) do table.insert(runenvstr, k .. "=" .. v) end targetinfo.runenvs = table.concat(runenvstr, "\n") diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 6fe8c7f90..031cbd66c 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()}) @@ -164,8 +164,8 @@ function _make_targetinfo(mode, arch, target) end -- save runenvs - local runenvs = {} - local addrunenvs, setrunenvs = make_runenvs(target) + local targetrunenvs = {} + 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)) @@ -180,25 +180,25 @@ function _make_targetinfo(mode, arch, target) -- https://github.com/xmake-io/xmake/issues/3391 v = table.unique(v) if k:upper() == "PATH" then - runenvs[k] = _make_dirs(v) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .. "'))" + targetrunenvs[k] = _make_dirs(v) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .. "'))" else - runenvs[k] = path.joinenv(v) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .."'))" + targetrunenvs[k] = path.joinenv(v) .. ";$([System.Environment]::GetEnvironmentVariable('" .. k .."'))" end end for k, v in table.orderpairs(setrunenvs) do if #v == 1 then v = v[1] if path.is_absolute(v) and v:startswith(project.directory()) then - runenvs[k] = _make_dirs(v) + targetrunenvs[k] = _make_dirs(v) else - runenvs[k] = v[1] + targetrunenvs[k] = v[1] end else - runenvs[k] = path.joinenv(v) + targetrunenvs[k] = path.joinenv(v) end end local runenvstr = {} - for k, v in table.orderpairs(runenvs) do + for k, v in table.orderpairs(targetrunenvs) do table.insert(runenvstr, k .. "=" .. v) end targetinfo.runenvs = table.concat(runenvstr, "\n") diff --git a/xmake/rules/xcode/application/run.lua b/xmake/rules/xcode/application/run.lua index 0e0663207..9859321bc 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(addrunenvs, setrunenvs)}) end -- restore the previous directory |
