diff options
| author | xiaobfly <[email protected]> | 2025-05-22 14:58:03 +0800 |
|---|---|---|
| committer | xiaobfly <[email protected]> | 2025-05-22 14:58:03 +0800 |
| commit | 18046833f44c1531b33d4361397216ec7fe4f8ca (patch) | |
| tree | 370ea9903a7d27d5c592d54c6715d28104b4415e | |
| parent | d558ace9f0d9daa3c51d3ac6b56147a67e995149 (diff) | |
Fixed the issue where vstudio cannot be found when there are more versions of the same vstudio in the system.
vswhere echo string:
D:\Microsoft Visual Studio\2022\Professional2
D:\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build
xmake thought it was a string, but in fact, it was two.
so, should split it by "\n":
{
"D:\Microsoft Visual Studio\2022\Professional2",
"D:\Microsoft Visual Studio\2022\Professional"
}
| -rw-r--r-- | xmake/modules/detect/sdks/find_vstudio.lua | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index 3e687228a..d58886521 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -491,15 +491,17 @@ function _find_vstudio(opt) -- find VC install path (and aux build path) using `vswhere` (for version >= 15.0) -- * version > 15.0 eschews registry entries; but `vswhere` (included with version >= 15.2) can be used to find VC install path -- ref: https://github.com/Microsoft/vswhere/blob/master/README.md @@ https://archive.is/mEmdu - local vswhere_VCAuxiliaryBuildDir = nil - local vswhere_Common7ToolsDir = nil + local vswhere_VCAuxiliaryBuildDir = {} + local vswhere_Common7ToolsDir = {} if (tonumber(version) >= 15) and vswhere then local vswhere_vrange = format("%s,%s)", version, (version + 1)) -- build tools: https://github.com/microsoft/vswhere/issues/22 @@ https://aka.ms/vs/workloads local result = os.iorunv(vswhere.program, {"-products", "*", "-prerelease", "-property", "installationpath", "-version", vswhere_vrange}) if result then - vswhere_VCAuxiliaryBuildDir = path.join(result:trim(), "VC", "Auxiliary", "Build") - vswhere_Common7ToolsDir = path.join(result:trim(), "Common7", "Tools") + for _, vc_path in ipairs(result:split("\n")) do + table.insert(vswhere_VCAuxiliaryBuildDir, path.join(vc_path:trim(), "VC", "Auxiliary", "Build")) + table.insert(vswhere_Common7ToolsDir, path.join(vc_path:trim(), "Common7", "Tools")) + end end end @@ -514,8 +516,13 @@ function _find_vstudio(opt) if vsenvs[version] then table.insert(paths, format("$(env %s)\\..\\..\\VC", vsenvs[version])) end - if vswhere_VCAuxiliaryBuildDir and os.isdir(vswhere_VCAuxiliaryBuildDir) then - table.insert(paths, 1, vswhere_VCAuxiliaryBuildDir) + + if vswhere_VCAuxiliaryBuildDir then + for i, vc_path in ipairs(vswhere_VCAuxiliaryBuildDir) do + if os.isdir(vc_path) then + table.insert(paths, 1, vc_path) + end + end end if version == "6.0" and os.arch() == "x64" then table.insert(paths, "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\DevStudio\\6.0\\Products\\Microsoft Visual C++;ProductDir)\\Bin") @@ -557,8 +564,12 @@ function _find_vstudio(opt) format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\Common7\\Tools", version), format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\Common7\\Tools", version) } - if vswhere_Common7ToolsDir and os.isdir(vswhere_Common7ToolsDir) then - table.insert(paths, 1, vswhere_Common7ToolsDir) + if vswhere_Common7ToolsDir then + for _, vc_path in ipairs(vswhere_Common7ToolsDir) do + if os.isdir(vc_path) then + table.insert(paths, 1, vc_path) + end + end end vcvarsall = find_file("VsDevCmd.bat", paths) end |
