diff options
| author | ruki <[email protected]> | 2025-10-04 17:39:12 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-10-04 17:39:12 +0800 |
| commit | cde688f2021845a23751eeb25aecd3b5194c6952 (patch) | |
| tree | 216507f90d4294b81bbc3c26ef9e26883b3a149e | |
| parent | 3abd796be60f8b5b69a2c61e36d2e67197328359 (diff) | |
fix os.getenvs compat
| -rw-r--r-- | xmake/core/base/os.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 988d9e4bf..8f56aa8e0 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -42,6 +42,7 @@ os._tmpdir = os._tmpdir or os.tmpdir os._curdir = os._curdir or os.curdir os._fscase = os._fscase or os.fscase os._setenv = os._setenv or os.setenv +os._getenvs = os._getenvs or os.getenvs os._cpuinfo = os._cpuinfo or os.cpuinfo os._meminfo = os._meminfo or os.meminfo os._readlink = os._readlink or os.readlink @@ -1300,6 +1301,33 @@ function os.term() return require("base/tty").term() end +-- get all current environments variables +function os.getenvs() + local envs = os._getenvs() + if envs then + if envs[1] ~= nil then + local result = {} + for _, line in ipairs(envs) do + local p = line:find('=', 1, true) + if p then + local key = line:sub(1, p - 1):trim() + -- only translate Path to PATH on windows + -- @see https://github.com/xmake-io/xmake/issues/3752 + if os.host() == "windows" and key:lower() == "path" then + key = key:upper() + end + local values = line:sub(p + 1):trim() + if #key > 0 then + result[key] = values + end + end + end + envs = result + end + end + return envs +end + -- set all current environment variables -- e.g. envs["PATH"] = "/xxx:/yyy/foo" function os.setenvs(envs) |
