From 0d7249df69154a86f4e4697aca85ee89ca5c3293 Mon Sep 17 00:00:00 2001 From: Joseph Brill <48932340+jcbrill@users.noreply.github.com> Date: Mon, 15 Jun 2020 08:57:22 -0400 Subject: The order of results from the vswhere query using "products *" is unreliable when multiple versions of msvc are installed. Modify the vswhere queries by version to detect the appropriate products: 14.2 [default, BuildTools], 14.1 [default, BuildTools], 14.1Exp [WDExpress]. The default is Enterprise, Professional, Community. The order is unknown. With only Build Tools installed, 14.2 and 14.1 require two calls to vswhere. --- SCons/Tool/MSCommon/vc.py | 59 ++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/SCons/Tool/MSCommon/vc.py b/SCons/Tool/MSCommon/vc.py index 91265d2..5acada4 100644 --- a/SCons/Tool/MSCommon/vc.py +++ b/SCons/Tool/MSCommon/vc.py @@ -231,9 +231,17 @@ _VCVER = ["14.2", "14.1", "14.1Exp", "14.0", "14.0Exp", "12.0", "12.0Exp", "11.0 # if using vswhere, a further mapping is needed _VCVER_TO_VSWHERE_VER = { - '14.2': '[16.0, 17.0)', - '14.1': '[15.0, 16.0)', - '14.1Exp': '[15.0, 16.0)', + '14.2': [ + ["-version", "[16.0, 17.0)", ], # default: Enterprise, Professional, Community (order unpredictable?) + ["-version", "[16.0, 17.0)", "-products", "Microsoft.VisualStudio.Product.BuildTools"], # BuildTools + ], + '14.1': [ + ["-version", "[15.0, 16.0)", ], # default: Enterprise, Professional, Community (order unpredictable?) + ["-version", "[15.0, 16.0)", "-products", "Microsoft.VisualStudio.Product.BuildTools"], # BuildTools + ], + '14.1Exp': [ + ["-version", "[15.0, 16.0)", "-products", "Microsoft.VisualStudio.Product.WDExpress"], # Express + ], } _VCVER_TO_PRODUCT_DIR = { @@ -377,29 +385,28 @@ def find_vc_pdir_vswhere(msvc_version, env=None): return None debug('VSWHERE: %s' % vswhere_path) - vswhere_cmd = [ - vswhere_path, - "-products", "*", - "-version", vswhere_version, - "-property", "installationPath", - ] - - debug("running: %s" % vswhere_cmd) - - #cp = subprocess.run(vswhere_cmd, capture_output=True) # 3.7+ only - cp = subprocess.run(vswhere_cmd, stdout=PIPE, stderr=PIPE) - - if cp.stdout: - # vswhere could return multiple lines, e.g. if Build Tools - # and {Community,Professional,Enterprise} are both installed. - # We could define a way to pick the one we prefer, but since - # this data is currently only used to make a check for existence, - # returning the first hit should be good enough. - lines = cp.stdout.decode("mbcs").splitlines() - return os.path.join(lines[0], 'VC') - else: - # We found vswhere, but no install info available for this version - return None + for vswhere_version_args in vswhere_version: + + vswhere_cmd = [vswhere_path] + vswhere_version_args + ["-property", "installationPath"] + + debug("running: %s" % vswhere_cmd) + + #cp = subprocess.run(vswhere_cmd, capture_output=True) # 3.7+ only + cp = subprocess.run(vswhere_cmd, stdout=PIPE, stderr=PIPE) + + if cp.stdout: + # vswhere could return multiple lines, e.g. if Build Tools + # and {Community,Professional,Enterprise} are both installed. + # We could define a way to pick the one we prefer, but since + # this data is currently only used to make a check for existence, + # returning the first hit should be good enough. + lines = cp.stdout.decode("mbcs").splitlines() + return os.path.join(lines[0], 'VC') + else: + # We found vswhere, but no install info available for this version + return None + + return None def find_vc_pdir(env, msvc_version): -- cgit v0.12