Skip to content

Commit

Permalink
Implement workaround for missing -requiresAny (#3950)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Jun 19, 2023
2 parents 66cbd98 + d4626bf commit 26231f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
2 changes: 2 additions & 0 deletions changelog.d/3950.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Implemented workaround for old versions of ``vswhere``, which miss the
``-requiresAny`` parameter, such as the ones distributed together with Visual Studio 2017 < 15.6.
42 changes: 23 additions & 19 deletions setuptools/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from io import open
from os import listdir, pathsep
from os.path import join, isfile, isdir, dirname
from subprocess import CalledProcessError
import contextlib
import platform
import itertools
Expand Down Expand Up @@ -83,25 +84,28 @@ def _msvc14_find_vc2017():
if not root:
return None, None

try:
path = subprocess.check_output([
join(root, "Microsoft Visual Studio", "Installer", "vswhere.exe"),
"-latest",
"-prerelease",
"-requiresAny",
"-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"-requires", "Microsoft.VisualStudio.Workload.WDExpress",
"-property", "installationPath",
"-products", "*",
]).decode(encoding="mbcs", errors="strict").strip()
except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
return None, None

path = join(path, "VC", "Auxiliary", "Build")
if isdir(path):
return 15, path

return None, None
suitable_components = (
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.Workload.WDExpress",
)

for component in suitable_components:
# Workaround for `-requiresAny` (only available on VS 2017 > 15.6)
with contextlib.suppress(CalledProcessError, OSError, UnicodeDecodeError):
path = subprocess.check_output([
join(root, "Microsoft Visual Studio", "Installer", "vswhere.exe"),
"-latest",
"-prerelease",
"-requires", component,
"-property", "installationPath",
"-products", "*",
]).decode(encoding="mbcs", errors="strict").strip()

path = join(path, "VC", "Auxiliary", "Build")
if isdir(path):
return 15, path

return None, None # no suitable component found


PLAT_SPEC_TO_RUNTIME = {
Expand Down

0 comments on commit 26231f4

Please sign in to comment.