diff options
| author | OpportunityLiu <[email protected]> | 2019-07-17 08:48:11 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-19 11:48:31 +0800 |
| commit | 0a771e41e5057d2f6dc9dce3cbe2078cbc19aa83 (patch) | |
| tree | 3478c553fbee0e2842dbe05196f5d742d518bf1b | |
| parent | ae533cdc5bcee78d7a24b64eac430d9197d0e043 (diff) | |
add path.splitenv
| -rw-r--r-- | xmake/core/base/os.lua | 35 | ||||
| -rw-r--r-- | xmake/core/base/path.lua | 27 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/package/tools/autoconf.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/package/tools/make.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/package/tools/meson.lua | 4 |
7 files changed, 65 insertions, 19 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index ee5979b2e..fe88c65bb 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -943,34 +943,53 @@ function os.getenvs() return envs end --- set values to environment variable +-- set values to environment variable function os.setenv(name, ...) - return os._setenv(name, table.concat({...}, path.envsep())) + local values = {...} + if #values <= 1 then + -- keep compatible with original implementation + os._setenv(name, values[1] or "") + else + os._setenv(path.joinenv(values)) + end end --- add values to environment variable +-- add values to environment variable function os.addenv(name, ...) - local sep = path.envsep() local values = {...} if #values > 0 then - return os._setenv(name, table.concat(values, sep) .. sep .. (os.getenv(name) or "")) + local oldenv = os.getenv(name) + local appendenv = path.joinenv(values) + if oldenv == "" or oldenv == nil then + return os._setenv(name, appendenv) + else + return os._setenv(name, appendenv .. path.envsep() .. oldenv) + end else return true end end --- set values to environment variable with the given seperator +-- set values to environment variable with the given seperator function os.setenvp(name, values, sep) sep = sep or path.envsep() return os._setenv(name, table.concat(table.wrap(values), sep)) end --- add values to environment variable with the given seperator +-- add values to environment variable with the given seperator function os.addenvp(name, values, sep) sep = sep or path.envsep() values = table.wrap(values) if #values > 0 then - return os._setenv(name, table.concat(values, sep) .. sep .. (os.getenv(name) or "")) + local oldenv = os.getenv(name) + local appendenv = table.concat(values, sep) + local newenv + if oldenv == "" or oldenv == nil then + newenv = appendenv + else + newenv = appendenv .. sep .. oldenv + end + return os._setenv(name, newenv) else return true end diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index c1222ffc6..d15c42fc4 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -158,6 +158,33 @@ function path.splitenv(env_path) return result end +-- concat environment variable with `path.envsep()`, +-- also handles more speical cases such as posix flags and windows quoted pathes +function path.joinenv(env_table) + + -- check + env_table = env_table or {} + + local envsep = path.envsep() + + if xmake._HOST == "windows" then + local tab = {} + for _, v in ipairs(env_table) do + if v ~= "" then + if v:find(envsep, 1, true) then + v = '"' .. v .. '"' + end + table.insert(tab, v) + end + end + return table.concat(tab, envsep) + else + return table.concat(env_table, envsep) + end + + return result +end + -- the last character is the path seperator? function path.islastsep(p) diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 472d5be76..51e284ad5 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -380,8 +380,8 @@ function builder:_add_flags_from_language(flags, target, getters) { config = function (name) local values = config.get(name) - if values and name:endswith("dirs") then - values = values:split(path.envsep(), {plain = true}) + if values and name:endswith("dirs") then + values = path.splitenv(values) end return values end diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index 7705c3bca..349b2c5b5 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -106,8 +106,8 @@ function buildenvs(package) table.insert(ACLOCAL_PATH, aclocal) end end - envs.ACLOCAL_PATH = table.concat(ACLOCAL_PATH, path.envsep()) - envs.PKG_CONFIG_PATH = table.concat(PKG_CONFIG_PATH, path.envsep()) + envs.ACLOCAL_PATH = path.joinenv(ACLOCAL_PATH) + envs.PKG_CONFIG_PATH = path.joinenv(PKG_CONFIG_PATH) return envs end diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 7c21947d1..75b38eaf1 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -71,9 +71,9 @@ function buildenvs(package) table.join2(CMAKE_PREFIX_PATH, dep:installdir()) end end - envs.CMAKE_LIBRARY_PATH = table.concat(CMAKE_LIBRARY_PATH, path.envsep()) - envs.CMAKE_INCLUDE_PATH = table.concat(CMAKE_INCLUDE_PATH, path.envsep()) - envs.CMAKE_PREFIX_PATH = table.concat(CMAKE_PREFIX_PATH, path.envsep()) + envs.CMAKE_LIBRARY_PATH = path.joinenv(CMAKE_LIBRARY_PATH) + envs.CMAKE_INCLUDE_PATH = path.joinenv(CMAKE_INCLUDE_PATH) + envs.CMAKE_PREFIX_PATH = path.joinenv(CMAKE_PREFIX_PATH) return envs end diff --git a/xmake/modules/package/tools/make.lua b/xmake/modules/package/tools/make.lua index 13e72b310..4a7850185 100644 --- a/xmake/modules/package/tools/make.lua +++ b/xmake/modules/package/tools/make.lua @@ -59,8 +59,8 @@ function buildenvs(package) table.insert(ACLOCAL_PATH, aclocal) end end - envs.ACLOCAL_PATH = table.concat(ACLOCAL_PATH, path.envsep()) - envs.PKG_CONFIG_PATH = table.concat(PKG_CONFIG_PATH, path.envsep()) + envs.ACLOCAL_PATH = path.joinenv(ACLOCAL_PATH) + envs.PKG_CONFIG_PATH = path.joinenv(PKG_CONFIG_PATH) return envs end diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index f977475ab..e5b25c450 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -78,8 +78,8 @@ function buildenvs(package) table.insert(ACLOCAL_PATH, aclocal) end end - envs.ACLOCAL_PATH = table.concat(ACLOCAL_PATH, path.envsep()) - envs.PKG_CONFIG_PATH = table.concat(PKG_CONFIG_PATH, path.envsep()) + envs.ACLOCAL_PATH = path.joinenv(ACLOCAL_PATH) + envs.PKG_CONFIG_PATH = path.joinenv(PKG_CONFIG_PATH) return envs end |
