From fe0c464cfdf0498bf6df69a8965931255e94884b Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 13 Oct 2018 01:23:26 -0500 Subject: fix detection strategy for MSVC/VS2017+ * fixes the MSVC/VS 2017 detection problem discussed within .# 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: @@ --- xmake/modules/detect/sdks/find_vstudio.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index 7cf4dca17..9baf50bc6 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -24,6 +24,7 @@ -- imports import("lib.detect.find_file") +import("detect.tools.find_vswhere") -- init vc variables local vcvars = {"path", @@ -193,6 +194,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 = { @@ -201,7 +215,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 -- cgit v1.3.1