Skip to content

Implement workaround for missing -requiresAny (only available on VS 2017 > 15.6) #3950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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