Skip to content

Commit 26231f4

Browse files
committed
Implement workaround for missing -requiresAny (#3950)
2 parents 66cbd98 + d4626bf commit 26231f4

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

changelog.d/3950.change.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Implemented workaround for old versions of ``vswhere``, which miss the
2+
``-requiresAny`` parameter, such as the ones distributed together with Visual Studio 2017 < 15.6.

setuptools/msvc.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from io import open
1616
from os import listdir, pathsep
1717
from os.path import join, isfile, isdir, dirname
18+
from subprocess import CalledProcessError
1819
import contextlib
1920
import platform
2021
import itertools
@@ -83,25 +84,28 @@ def _msvc14_find_vc2017():
8384
if not root:
8485
return None, None
8586

86-
try:
87-
path = subprocess.check_output([
88-
join(root, "Microsoft Visual Studio", "Installer", "vswhere.exe"),
89-
"-latest",
90-
"-prerelease",
91-
"-requiresAny",
92-
"-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
93-
"-requires", "Microsoft.VisualStudio.Workload.WDExpress",
94-
"-property", "installationPath",
95-
"-products", "*",
96-
]).decode(encoding="mbcs", errors="strict").strip()
97-
except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
98-
return None, None
99-
100-
path = join(path, "VC", "Auxiliary", "Build")
101-
if isdir(path):
102-
return 15, path
103-
104-
return None, None
87+
suitable_components = (
88+
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
89+
"Microsoft.VisualStudio.Workload.WDExpress",
90+
)
91+
92+
for component in suitable_components:
93+
# Workaround for `-requiresAny` (only available on VS 2017 > 15.6)
94+
with contextlib.suppress(CalledProcessError, OSError, UnicodeDecodeError):
95+
path = subprocess.check_output([
96+
join(root, "Microsoft Visual Studio", "Installer", "vswhere.exe"),
97+
"-latest",
98+
"-prerelease",
99+
"-requires", component,
100+
"-property", "installationPath",
101+
"-products", "*",
102+
]).decode(encoding="mbcs", errors="strict").strip()
103+
104+
path = join(path, "VC", "Auxiliary", "Build")
105+
if isdir(path):
106+
return 15, path
107+
108+
return None, None # no suitable component found
105109

106110

107111
PLAT_SPEC_TO_RUNTIME = {

0 commit comments

Comments
 (0)