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 /xmake/core/base/os.lua | |
| parent | c44d6060e82fc332e0f7370398bcbbaed7278543 (diff) | |
add os.joinenvs
Diffstat (limited to 'xmake/core/base/os.lua')
| -rw-r--r-- | xmake/core/base/os.lua | 19 |
1 files changed, 18 insertions, 1 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 |
