diff options
| author | ruki <[email protected]> | 2019-08-20 22:21:50 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-08-20 22:21:50 +0800 |
| commit | 928607630eb03a5afcf63f3076fc2a99e859bdd7 (patch) | |
| tree | 9a63e0eb36f1543e6c55b9d0bf610eedb1238eb9 | |
| parent | 22a22766a667c3273fc4a4a2e58ce55aba8466b3 (diff) | |
| parent | b515795919b7eb114032a441564512645fae489c (diff) | |
Merge pull request #537 from OpportunityLiu/dev
support set_runenv
| -rw-r--r-- | xmake/actions/run/main.lua | 110 | ||||
| -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 | 49 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/Xmake.Defaults.props | 20 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/Xmake.targets | 1 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj | 1 | ||||
| -rw-r--r-- | xmake/rules/qt/env/xmake.lua | 4 |
8 files changed, 149 insertions, 51 deletions
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 41614f879..a3c1d5702 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,60 +29,81 @@ import("core.platform.platform") import("core.platform.environment") import("devel.debugger") --- run target -function _do_run_target(target) - if target:targetkind() == "binary" then +-- add search directories for all dependent shared libraries on windows +function _make_runpath(target) - -- get the run directory of target - local rundir = target:rundir() - - -- get the absolute target file path - local targetfile = path.absolute(target:targetfile()) + if not (is_plat("windows") or (is_plat("mingw") and is_host("windows"))) then + return {} + end - -- enter the run directory - local oldir = os.cd(rundir) + local searchdirs = hashset.new() + local pathenv = {} - -- add run environments - local runenvs = target:get("runenvs") - if runenvs then - for name, values in pairs(runenvs) do - os.addenv(name, unpack(table.wrap(values))) - end + local function insert(dir) + if not path.is_absolute(dir) then + dir = path.absolute(dir, os.projectdir()) + end + if searchdirs:insert(dir) then + table.insert(pathenv, dir) 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 = {} - for _, linkdir in ipairs(target:get("linkdirs")) do - if not searchdirs[linkdir] then - searchdirs[linkdir] = true - os.addenv("PATH", linkdir) - end - end - for _, dep in ipairs(target:orderdeps()) do - if dep:targetkind() == "shared" then - local depdir = dep:targetdir() - 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) - end - end - end + for _, linkdir in ipairs(target:get("linkdirs")) do + insert(linkdir) + end + for _, opt in ipairs(target:orderopts()) do + for _, linkdir in ipairs(opt:get("linkdirs")) do + insert(linkdir) end + end + for _, dep in ipairs(target:orderdeps()) do + if dep:targetkind() == "shared" then + insert(dep:targetdir()) + end + end + return pathenv +end + +-- run target +function _do_run_target(target) + if target:targetkind() ~= "binary" then + return + end + + -- get the run directory of target + local rundir = target:rundir() + + -- get the absolute target file path + local targetfile = path.absolute(target:targetfile()) + + -- enter the run directory + local oldir = os.cd(rundir) - -- debugging? - if option.get("debug") then - debugger.run(targetfile, option.get("arguments")) - else - os.execv(targetfile, option.get("arguments")) + -- add run environments + local runenvs = target:get("runenvs") + if runenvs then + for name, values in pairs(runenvs) do + 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 + + os.addenv("PATH", table.unpack(_make_runpath(target))) - -- restore the previous directory - os.cd(oldir) + -- debugging? + if option.get("debug") then + debugger.run(targetfile, option.get("arguments")) + else + os.execv(targetfile, option.get("arguments")) end + + -- restore the previous directory + os.cd(oldir) end -- run target 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..b0d24b04e 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.base.semver") +import("core.base.hashset") import("core.project.config") import("core.project.cache") import("core.project.project") @@ -79,7 +80,7 @@ function _make_dirs(dir) r[k] = _make_dirs(v) end r = table.unique(r) - return table.concat(r, ";") + return path.joinenv(r) end function _make_arrs(arr) @@ -129,6 +130,37 @@ function _get_values(target, name) return table.unique(values) end +-- add search directories for all dependent shared libraries on windows +function _make_runpath(target) + + local searchdirs = hashset.new() + local pathenv = {} + + local function insert(dir) + if not path.is_absolute(dir) then + dir = path.absolute(dir, os.projectdir()) + end + if searchdirs:insert(dir) then + table.insert(pathenv, dir) + end + end + + for _, linkdir in ipairs(target:get("linkdirs")) do + insert(linkdir) + end + for _, opt in ipairs(target:orderopts()) do + for _, linkdir in ipairs(opt:get("linkdirs")) do + insert(linkdir) + end + end + for _, dep in ipairs(target:orderdeps()) do + if dep:targetkind() == "shared" then + insert(dep:targetdir()) + end + end + return pathenv +end + -- make target info function _make_targetinfo(mode, arch, target) @@ -176,10 +208,19 @@ 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 + 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 + runenvs["PATH"] = _make_dirs(_make_runpath(target)) .. ";" .. (runenvs["PATH"] or "$([System.Environment]::GetEnvironmentVariable('PATH'))") + local runenvstr = {} + for k, v in pairs(runenvs) do + table.insert(runenvstr, k .. "=" .. v) end - targetinfo.runenvs = table.concat(runenvs, "\n") + 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.Defaults.props b/xmake/plugins/project/vsxmake/vsproj/Xmake.Defaults.props new file mode 100644 index 000000000..df0b5f9e5 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.Defaults.props @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + + <PropertyGroup Label="XmakePathsResolve"> + <XmakeProgramDirResolved>$(XmakeProgramDir)</XmakeProgramDirResolved> + <XmakeProjectDirResolved>$(XmakeProjectDir)</XmakeProjectDirResolved> + <XmakeScriptDirResolved>$(XmakeScriptDir)</XmakeScriptDirResolved> + + <!-- resolve if they are relative paths --> + <XmakeProjectDirResolved Condition="!$([System.IO.Path]::IsPathRooted('$(XmakeProjectDirResolved)'))">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeProjectDirResolved)'))</XmakeProjectDirResolved> + <XmakeScriptDirResolved Condition="!$([System.IO.Path]::IsPathRooted('$(XmakeScriptDirResolved)'))">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeScriptDirResolved)'))</XmakeScriptDirResolved> + <XmakeBuilDirResolved Condition="!$([System.IO.Path]::IsPathRooted('$(XmakeBuilDirResolved)'))">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeBuilDirResolved)'))</XmakeBuilDirResolved> + + <!-- normalize paths --> + <XmakeProgramDir>$([System.IO.Path]::GetFullPath('$(XmakeProgramDirResolved)'))</XmakeProgramDir> + <XmakeProjectDir>$([System.IO.Path]::GetFullPath('$(XmakeProjectDirResolved)'))</XmakeProjectDir> + <XmakeScriptDir>$([System.IO.Path]::GetFullPath('$(XmakeScriptDirResolved)'))</XmakeScriptDir> + </PropertyGroup> + +</Project> 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/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj index 8df23001e..cb47d68db 100644 --- a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj @@ -25,6 +25,7 @@ <XmakeProjectFile>#projectfile#</XmakeProjectFile> <XmakeTarget>#target#</XmakeTarget> </PropertyGroup> + <Import Project="$(XmakeProgramDir)\plugins\project\vsxmake\vsproj\xmake.Defaults.props" /> #Import(XmakeConfig)# #Import(XmakePath)# <Import Project="$(XmakeProgramDir)\plugins\project\vsxmake\vsproj\xmake.props" /> 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) |
