|
15 | 15 | from io import open
|
16 | 16 | from os import listdir, pathsep
|
17 | 17 | from os.path import join, isfile, isdir, dirname
|
| 18 | +from subprocess import CalledProcessError |
18 | 19 | import contextlib
|
19 | 20 | import platform
|
20 | 21 | import itertools
|
@@ -83,25 +84,28 @@ def _msvc14_find_vc2017():
|
83 | 84 | if not root:
|
84 | 85 | return None, None
|
85 | 86 |
|
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 |
105 | 109 |
|
106 | 110 |
|
107 | 111 | PLAT_SPEC_TO_RUNTIME = {
|
|
0 commit comments