Skip to content

Commit

Permalink
fix detection strategy for MSVC/VS2017+
Browse files Browse the repository at this point in the history
* fixes the MSVC/VS 2017 detection problem discussed within <xmake-io#225>

.# Discussion

MSVC/VS versions >= 15.0 will no longer be setting registry entries for tool location
purposes. But `vswhere` (included with MSVC/VS versions >= 15.2, and placed in a
guaranteed location) can instead be used to find the needed path.

`os.runv(...)` is used as the tool to gather `vswhere` output instead of `($shell ...)`
in order to avoid some `($shell ...)` limitations. Commands containing white space and/or
special characters (eg, '[', ')') are difficult or impossible to pass through the current
`($shell ...)` implementation, causing application exceptions. Both white space and the
noted special characters are needed to construct the required `vswhere` command.

ref: <https://github.com/Microsoft/vswhere/blob/master/README.md> @@ <https://archive.is/mEmdu>
  • Loading branch information
rivy committed Oct 14, 2018
1 parent 65f9897 commit 4b2d032
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion xmake/modules/detect/sdks/find_vstudio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ function main()
local results = {}
for _, version in ipairs({"15.0", "14.0", "12.0", "11.0", "10.0", "9.0", "8.0", "7.1", "7.0", "6.0", "5.0", "4.2"}) do

-- 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
if ((version+0) >= 15) then
local vswhere = find_vswhere()
if vswhere then
local vswhere_vrange = format("%s,%s)", version, (version+1))
local out, err = os.iorunv(vswhere, {"-property", "installationpath", "-products", "Microsoft.VisualStudio.Product.BuildTools", "-version", vswhere_vrange})
if out then vswhere_VCAuxiliaryBuildDir = out:trim().."\\VC\\Auxiliary\\Build" end
end
end

-- init pathes
local pathes =
{
Expand All @@ -201,7 +214,8 @@ function main()
format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC", version),
format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC\\Auxiliary\\Build", version),
format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC\\Auxiliary\\Build", version),
format("$(env %s)\\..\\..\\VC", vsenvs[version] or "")
format("$(env %s)\\..\\..\\VC", vsenvs[version] or ""),
(vswhere_VCAuxiliaryBuildDir or "")
}

-- find vcvarsall.bat, vcvars32.bat for vs7.1
Expand Down

0 comments on commit 4b2d032

Please sign in to comment.