diff options
| author | OpportunityLiu <[email protected]> | 2019-08-20 14:38:39 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-08-20 14:38:39 +0800 |
| commit | a0d6bcacb190ce0538ded1c15336b6abdafbb7c2 (patch) | |
| tree | 1249c19309cdc30f3a99c9dd7180c7ca5065d798 | |
| parent | 22a22766a667c3273fc4a4a2e58ce55aba8466b3 (diff) | |
support set_runenv
| -rw-r--r-- | xmake/actions/run/main.lua | 27 | ||||
| -rw-r--r-- | xmake/core/base/table.lua | 12 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 3 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 14 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/Xmake.targets | 1 | ||||
| -rw-r--r-- | xmake/rules/qt/env/xmake.lua | 4 |
6 files changed, 47 insertions, 14 deletions
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 41614f879..358b28fbe 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.base.task") +import("core.base.hashset") import("core.project.config") import("core.base.global") import("core.project.project") @@ -28,7 +29,7 @@ import("core.platform.platform") import("core.platform.environment") import("devel.debugger") --- run target +-- run target function _do_run_target(target) if target:targetkind() == "binary" then @@ -48,14 +49,23 @@ function _do_run_target(target) os.addenv(name, unpack(table.wrap(values))) end end + local runenv = target:get("runenv") + if runenv then + for name, value in pairs(runenv) do + os.setenv(name, unpack(table.wrap(value))) + end + end -- add search directories for all dependent shared libraries on windows if is_plat("windows") or (is_plat("mingw") and is_host("windows")) then - local searchdirs = {} + local searchdirs = hashset.new() + local pathenv = {} for _, linkdir in ipairs(target:get("linkdirs")) do - if not searchdirs[linkdir] then - searchdirs[linkdir] = true - os.addenv("PATH", linkdir) + if not path.is_absolute(linkdir) then + linkdir = path.absolute(linkdir, os.projectdir()) + end + if searchdirs:insert(linkdir) then + table.insert(pathenv, linkdir) end end for _, dep in ipairs(target:orderdeps()) do @@ -64,12 +74,13 @@ function _do_run_target(target) if not path.is_absolute(depdir) then depdir = path.absolute(depdir, os.projectdir()) end - if not searchdirs[depdir] then - searchdirs[depdir] = true - os.addenv("PATH", depdir) + if searchdirs:insert(depdir) then + table.insert(pathenv, depdir) end end end + pathenv = table.reverse(pathenv) + os.addenv("PATH", table.unpack(pathenv)) end -- debugging? diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index c08526c34..7d6717816 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -335,5 +335,17 @@ function table.imap(arr, mapper) return newarr end +function table.reverse(arr) + + assert(arr) + + local revarr = {} + local l = #arr + for i = 1, l do + revarr[i] = arr[l - i + 1] + end + return revarr +end + -- return module: table return table diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 8011ff313..7cf262262 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1674,11 +1674,12 @@ function target.apis() -- target.set_xxx "target.set_values" , "target.set_configvar" + , "target.set_runenv" -- target.add_xxx , "target.add_values" , "target.add_runenvs" } - , pathes = + , pathes = { -- target.set_xxx "target.set_targetdir" diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index d029a8a4b..53200dd2c 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -176,10 +176,18 @@ function _make_targetinfo(mode, arch, target) -- save runenvs local runenvs = {} for k, v in pairs(target:get("runenvs")) do - local defs = table.imap(v, function(_, v) return vformat(v) end) - table.insert(runenvs, format("%s=%s", k, path.joinenv(defs))) + local defs = table.imap(table.wrap(v), function(_, v) return vformat(v) end) + runenvs[k] = format("%s;$([System.Environment]::GetEnvironmentVariable('%s'))", path.joinenv(defs), k) end - targetinfo.runenvs = table.concat(runenvs, "\n") + for k, v in pairs(target:get("runenv")) do + local defs = table.imap(table.wrap(v), function(_, v) return vformat(v) end) + runenvs[k] = path.joinenv(defs) + end + local runenvstr = {} + for k, v in pairs(runenvs) do + table.insert(runenvstr, k .. "=" .. v) + end + targetinfo.runenvs = table.concat(runenvstr, "\n") -- use mfc? save the mfc runtime kind if target:rule("win.sdk.mfc.shared_app") or target:rule("win.sdk.mfc.shared") then diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets index 0a74e5f45..99583bf74 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets @@ -130,6 +130,7 @@ MSBuild Properties: XmakeIncludeDirs: $(XmakeIncludeDirs) XmakeLinkDirs: $(XmakeLinkDirs) XmakeSourceDirs: $(XmakeSourceDirs) + XmakeRunEnvs: $(XmakeRunEnvs) Xmake Path: XmakeProgramDir: $(XmakeProgramDir) XmakeProjectDir: $(XmakeProjectDir) diff --git a/xmake/rules/qt/env/xmake.lua b/xmake/rules/qt/env/xmake.lua index a18a8671f..50806c059 100644 --- a/xmake/rules/qt/env/xmake.lua +++ b/xmake/rules/qt/env/xmake.lua @@ -35,8 +35,8 @@ rule("qt.env") end if is_plat("windows") or (is_plat("mingw") and is_host("windows")) then target:add("runenvs", "PATH", qt.bindir) - target:add("runenvs", "QML2_IMPORT_PATH", path.join(qt.sdkdir, "qml")) - target:add("runenvs", "QML_IMPORT_TRACE", "1") + target:set("runenv", "QML2_IMPORT_PATH", path.join(qt.sdkdir, "qml")) + target:set("runenv", "QML_IMPORT_TRACE", "1") end end) |
