diff options
| author | ruki <[email protected]> | 2021-07-03 00:34:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-07-03 00:34:08 +0800 |
| commit | 9068e48983a41c30a020c302913fbdb4e4c66f9e (patch) | |
| tree | 1ef415646d3b6e2765c51b4393661575ed90c6ee | |
| parent | c44d6060e82fc332e0f7370398bcbbaed7278543 (diff) | |
add os.joinenvs
| -rw-r--r-- | xmake/core/base/os.lua | 19 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/package/tools/gn.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/package/tools/meson.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/package/tools/msbuild.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/package/tools/nmake.lua | 17 |
7 files changed, 47 insertions, 22 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 071db0dfa..10b6d0bcc 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -696,7 +696,6 @@ function os.execv(program, argv, opt) if opt.envs then local envars = os.getenvs() for k, v in pairs(opt.envs) do - -- TODO if type(v) == "table" then v = path.joinenv(v) end @@ -1066,6 +1065,24 @@ function os.addenvs(envs) return oldenvs end +-- join environment variables +function os.joinenvs(envs, oldenvs) + oldenvs = oldenvs or os.getenvs() + local newenvs = oldenvs + if envs then + newenvs = table.copy(oldenvs) + for name, values in pairs(envs) do + local oldenv = oldenvs[name] + if oldenv == "" or oldenv == nil then + newenvs[name] = values + elseif not oldenv:startswith(values) then + newenvs[name] = values .. path.envsep() .. oldenv + end + end + end + return newenvs +end + -- set values to environment variable function os.setenv(name, ...) local ok diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index d84ca64a1..beb60ddab 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -61,6 +61,7 @@ sandbox_os.addenvp = os.addenvp sandbox_os.getenvs = os.getenvs sandbox_os.setenvs = os.setenvs sandbox_os.addenvs = os.addenvs +sandbox_os.joinenvs = os.joinenvs sandbox_os.pbpaste = os.pbpaste sandbox_os.pbcopy = os.pbcopy sandbox_os.cpuinfo = os.cpuinfo diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 680d29a9b..f41bf0052 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -71,7 +71,7 @@ end -- get msvc run environments function _get_msvc_runenvs(package) - return _get_msvc(package):runenvs() + return os.joinenvs(_get_msvc(package):runenvs()) end -- get cflags from package deps @@ -491,7 +491,7 @@ function buildenvs(package, opt) local envs = {} local cmake_generator = opt.cmake_generator if cmake_generator and cmake_generator == "Ninja" and package:is_plat("windows") then - table.join2(envs, _get_msvc_runenvs(package)) + envs = _get_msvc_runenvs(package) end -- add environments for cmake/find_packages diff --git a/xmake/modules/package/tools/gn.lua b/xmake/modules/package/tools/gn.lua index 2c5341476..362373c2c 100644 --- a/xmake/modules/package/tools/gn.lua +++ b/xmake/modules/package/tools/gn.lua @@ -39,11 +39,18 @@ function _get_configs(package, configs, opt) return configs end +-- get msvc +function _get_msvc(package) + local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()}) + assert(msvc:check(), "vs not found!") -- we need check vs envs if it has been not checked yet + return msvc +end + -- get the build environments function buildenvs(package, opt) local envs = {} if package:is_plat("windows") then - table.join2(envs, toolchain.load("msvc"):runenvs()) + envs = os.joinenvs(_get_msvc(package):runenvs()) end return envs end diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index a6bdec48a..6361f2a0e 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -69,7 +69,7 @@ end -- get msvc run environments function _get_msvc_runenvs(package) - return _get_msvc(package):runenvs() + return os.joinenvs(_get_msvc(package):runenvs()) end -- fix libname on windows @@ -89,13 +89,7 @@ function buildenvs(package) envs.CXXFLAGS = table.concat(cxxflags, ' ') envs.ASFLAGS = table.concat(table.wrap(package:config("asflags")), ' ') if package:is_plat("windows") then - for name, values in pairs(_get_msvc_runenvs(package)) do - local oldvalues = os.getenv(name) - if oldvalues then - values = values .. path.envsep() .. oldvalues - end - envs[name] = values - end + envs = os.joinenvs(envs, _get_msvc_runenvs(package)) end else local cflags = table.join(table.wrap(package:build_getenv("cxflags")), package:build_getenv("cflags")) diff --git a/xmake/modules/package/tools/msbuild.lua b/xmake/modules/package/tools/msbuild.lua index 4c322c1f6..b9794a4e3 100644 --- a/xmake/modules/package/tools/msbuild.lua +++ b/xmake/modules/package/tools/msbuild.lua @@ -23,9 +23,16 @@ import("core.base.option") import("core.tool.toolchain") import("lib.detect.find_tool") +-- get msvc +function _get_msvc(package) + local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()}) + assert(msvc:check(), "vs not found!") -- we need check vs envs if it has been not checked yet + return msvc +end + -- get the build environments function buildenvs(package, opt) - return table.copy(toolchain.load("msvc"):runenvs()) + return os.joinenvs(_get_msvc(package):runenvs()) end -- build package diff --git a/xmake/modules/package/tools/nmake.lua b/xmake/modules/package/tools/nmake.lua index d8c40efca..c618531ce 100644 --- a/xmake/modules/package/tools/nmake.lua +++ b/xmake/modules/package/tools/nmake.lua @@ -24,17 +24,16 @@ import("core.project.config") import("core.tool.toolchain") import("lib.detect.find_tool") +-- get msvc +function _get_msvc(package) + local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()}) + assert(msvc:check(), "vs not found!") -- we need check vs envs if it has been not checked yet + return msvc +end + -- get the build environments function buildenvs(package, opt) - local envs = {} - for name, values in pairs(toolchain.load("msvc"):runenvs()) do - local oldvalues = os.getenv(name) - if oldvalues then - values = values .. path.envsep() .. oldvalues - end - envs[name] = values - end - return envs + return os.joinenvs(_get_msvc(package):runenvs()) end -- build package |
