From c01407a8571338bba642dc38cceeff118ac6d671 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Feb 2024 23:32:34 +0800 Subject: improve msvc envs --- xmake/modules/package/tools/cmake.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 4c73cd5d1..e302eaf98 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -93,7 +93,15 @@ end -- get msvc run environments function _get_msvc_runenvs(package) - return os.joinenvs(_get_msvc(package):runenvs()) + local envs = {} + for k, v in pairs(os.joinenvs(_get_msvc(package):runenvs())) do + if k:upper() ~= k and os.getenv(k:upper()) then + envs[k:upper()] = v + else + envs[k] = v + end + end + return envs end -- get vs arch -- cgit v1.3.1 From add07b3a9316f96adbf7519e10cc2a7e52f3cd4f Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Feb 2024 23:33:06 +0800 Subject: improve msvc envs --- xmake/modules/package/tools/cmake.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index e302eaf98..5183f80c1 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -95,8 +95,12 @@ end function _get_msvc_runenvs(package) local envs = {} for k, v in pairs(os.joinenvs(_get_msvc(package):runenvs())) do - if k:upper() ~= k and os.getenv(k:upper()) then - envs[k:upper()] = v + local k_upper = k:upper() + local k_lower = k:lower() + if k_upper ~= k and os.getenv(k_upper) then + envs[k_upper] = v + elseif k_lower ~= k and os.getenv(k_lower) then + envs[k_lower] = v else envs[k] = v end -- cgit v1.3.1 From c2c25429dcca196253183a83388306bb1716a5c3 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Feb 2024 23:34:05 +0800 Subject: find current msvc envs --- xmake/modules/package/tools/cmake.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 5183f80c1..77520b6a3 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -94,13 +94,17 @@ end -- get msvc run environments function _get_msvc_runenvs(package) local envs = {} + local curenvs = os.getenvs() for k, v in pairs(os.joinenvs(_get_msvc(package):runenvs())) do - local k_upper = k:upper() - local k_lower = k:lower() - if k_upper ~= k and os.getenv(k_upper) then - envs[k_upper] = v - elseif k_lower ~= k and os.getenv(k_lower) then - envs[k_lower] = v + local ck_found + for ck, cv in pairs(curenvs) do + if k:lower() == ck:lower() and k ~= ck then + ck_found = ck + break + end + end + if ck_found then + envs[ck_found] = v else envs[k] = v end -- cgit v1.3.1 From f74e4e078d63bd5a7ccf699729c9f4852a4f5e33 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Feb 2024 23:35:32 +0800 Subject: add some comments --- xmake/modules/package/tools/cmake.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 77520b6a3..f0786091c 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -96,6 +96,8 @@ function _get_msvc_runenvs(package) local envs = {} local curenvs = os.getenvs() for k, v in pairs(os.joinenvs(_get_msvc(package):runenvs())) do + -- fix case naming conflict for msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. + -- @see https://github.com/xmake-io/xmake/issues/4751 local ck_found for ck, cv in pairs(curenvs) do if k:lower() == ck:lower() and k ~= ck then -- cgit v1.3.1 From 2104e5927ecad9eb17180590c53875e1ee15b711 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Feb 2024 23:37:26 +0800 Subject: improve to load msvc envs --- xmake/modules/package/tools/cmake.lua | 20 +------------------ xmake/toolchains/msvc/load.lua | 36 ++++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index f0786091c..4c73cd5d1 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -93,25 +93,7 @@ end -- get msvc run environments function _get_msvc_runenvs(package) - local envs = {} - local curenvs = os.getenvs() - for k, v in pairs(os.joinenvs(_get_msvc(package):runenvs())) do - -- fix case naming conflict for msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - local ck_found - for ck, cv in pairs(curenvs) do - if k:lower() == ck:lower() and k ~= ck then - ck_found = ck - break - end - end - if ck_found then - envs[ck_found] = v - else - envs[k] = v - end - end - return envs + return os.joinenvs(_get_msvc(package):runenvs()) end -- get vs arch diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index 51b851c00..c77132e30 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -22,9 +22,30 @@ import("core.base.option") import("core.project.config") import("detect.sdks.find_vstudio") +function _get_msvc_runenvs(package) + local envs = {} + local curenvs = os.getenvs() + for k, v in pairs(os.joinenvs(_get_msvc(package):runenvs())) do + -- fix case naming conflict for msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. + -- @see https://github.com/xmake-io/xmake/issues/4751 + local ck_found + for ck, cv in pairs(curenvs) do + if k:lower() == ck:lower() and k ~= ck then + ck_found = ck + break + end + end + if ck_found then + envs[ck_found] = v + else + envs[k] = v + end + end + return envs +end -- add the given vs environment -function _add_vsenv(toolchain, name) +function _add_vsenv(toolchain, name, curenvs) -- get vcvars local vcvars = toolchain:config("vcvars") @@ -35,6 +56,14 @@ function _add_vsenv(toolchain, name) -- get the paths for the vs environment local new = vcvars[name] if new then + -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. + -- @see https://github.com/xmake-io/xmake/issues/4751 + for k, c in pairs(curenvs) do + if name:lower() == k:lower() and name ~= k then + name = k + break + end + end toolchain:add("runenvs", name, table.unwrap(path.splitenv(new))) end end @@ -61,12 +90,13 @@ function main(toolchain) -- add vs environments local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} + local curenvs = os.getenvs() for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name) + _add_vsenv(toolchain, name, curenvs) end for _, name in ipairs(find_vstudio.get_vcvars()) do if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name) + _add_vsenv(toolchain, name, curenvs) end end end -- cgit v1.3.1 From 4785dbaf7dc11ff84ccdc2b0943618950363d1c5 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Feb 2024 23:37:43 +0800 Subject: improve clang-cl envs --- xmake/toolchains/clang-cl/load.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/xmake/toolchains/clang-cl/load.lua b/xmake/toolchains/clang-cl/load.lua index 3b0da0e0a..3763b8d2e 100644 --- a/xmake/toolchains/clang-cl/load.lua +++ b/xmake/toolchains/clang-cl/load.lua @@ -24,7 +24,7 @@ import("core.project.config") import("detect.sdks.find_vstudio") -- add the given vs environment -function _add_vsenv(toolchain, name) +function _add_vsenv(toolchain, name, curenvs) -- get vcvars local vcvars = toolchain:config("vcvars") @@ -35,6 +35,14 @@ function _add_vsenv(toolchain, name) -- get the paths for the vs environment local new = vcvars[name] if new then + -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. + -- @see https://github.com/xmake-io/xmake/issues/4751 + for k, c in pairs(curenvs) do + if name:lower() == k:lower() and name ~= k then + name = k + break + end + end toolchain:add("runenvs", name, table.unwrap(path.splitenv(new))) end end @@ -57,12 +65,13 @@ function main(toolchain) -- add vs environments local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} + local curenvs = os.getenvs() for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name) + _add_vsenv(toolchain, name, curenvs) end for _, name in ipairs(find_vstudio.get_vcvars()) do if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name) + _add_vsenv(toolchain, name, curenvs) end end -- cgit v1.3.1 From e283b55ac049f45685d78399f50178cdb03f448d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 Feb 2024 23:38:24 +0800 Subject: remove unused code --- xmake/toolchains/msvc/load.lua | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index c77132e30..90aec06a9 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -22,27 +22,6 @@ import("core.base.option") import("core.project.config") import("detect.sdks.find_vstudio") -function _get_msvc_runenvs(package) - local envs = {} - local curenvs = os.getenvs() - for k, v in pairs(os.joinenvs(_get_msvc(package):runenvs())) do - -- fix case naming conflict for msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - local ck_found - for ck, cv in pairs(curenvs) do - if k:lower() == ck:lower() and k ~= ck then - ck_found = ck - break - end - end - if ck_found then - envs[ck_found] = v - else - envs[k] = v - end - end - return envs -end -- add the given vs environment function _add_vsenv(toolchain, name, curenvs) -- cgit v1.3.1