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 /xmake/core/base/os.lua | |
| parent | ae533cdc5bcee78d7a24b64eac430d9197d0e043 (diff) | |
add path.splitenv
Diffstat (limited to 'xmake/core/base/os.lua')
| -rw-r--r-- | xmake/core/base/os.lua | 35 |
1 files changed, 27 insertions, 8 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 |
