From 708d5964ee9cf1325892dff5f1c1c47f2a202bb1 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 24 Sep 2025 23:45:06 +0800 Subject: improve os.getenvs --- xmake/core/base/os.lua | 31 ++++++++++++++++++------------- 1 file 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 -- cgit v1.3.1