summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-24 23:45:06 +0800
committerruki <[email protected]>2025-09-24 23:45:06 +0800
commit708d5964ee9cf1325892dff5f1c1c47f2a202bb1 (patch)
tree7910b9fd0e50145b40f6f189b476ea79d5383d6e
parent106d342f0e555c209bf73a3a736038904110d06b (diff)
improve os.getenvs
-rw-r--r--xmake/core/base/os.lua31
1 files changed, 18 insertions, 13 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index cecf38dd2..f65f47edf 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -199,6 +199,7 @@ end
-- notify envs have been changed
function os._notify_envs_changed(envs)
+ os._ENVS = nil
if os._SCHED_CHENVS then
os._SCHED_CHENVS(envs)
end
@@ -1292,21 +1293,25 @@ end
-- get all current environment variables
-- e.g. envs["PATH"] = "/xxx:/yyy/foo"
function os.getenvs()
- local envs = {}
- for _, line in ipairs(os._getenvs()) 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
- envs[key] = values
+ local envs = os._ENVS
+ if envs == nil then
+ envs = {}
+ for _, line in ipairs(os._getenvs()) 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
+ envs[key] = values
+ end
end
end
+ os._ENVS = envs
end
return envs
end