Skip to content
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

[WIP] MSVC: detection fixes and changes #4409

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7d0f804
MSVC: detection fixes and changes
jcbrill Sep 8, 2023
caf8b0f
Temporarily disable command-line argument and keep original case of v…
jcbrill Sep 8, 2023
1867d37
Update verification of vswhere executable and temporary removal of vs…
jcbrill Sep 8, 2023
7a9c336
Remove vswhere command-line option and replace retrieval with stub re…
jcbrill Sep 10, 2023
8b4fcde
Update MSCommon/README.rst documentation [ci skip]
jcbrill Sep 10, 2023
3fbef22
Initial additions for CHANGES.txt. [ci skip]
jcbrill Sep 10, 2023
0fc09ba
Initial additions for RELEASE.txt. [ci skip]
jcbrill Sep 10, 2023
0d37f06
Initial update for SCons/Tool/msvc.xml. [ci skip]
jcbrill Sep 10, 2023
518fd13
Second update for SCons/Tool/msvc.xml. [ci skip]
jcbrill Sep 11, 2023
6424fe3
Third update for SCons/Tool/msvc.xml (remove hard tabs). [ci skip]
jcbrill Sep 11, 2023
0d1aaa7
Update for SCons/Tool/msvc.xml (remove hard tabs). [ci skip]
jcbrill Sep 11, 2023
fd2ec85
Merge branch 'master' into jbrill-msvc-fixes
jcbrill Oct 5, 2023
813b8d2
Internal changes to support channel (preview/release) and component q…
jcbrill Oct 5, 2023
38de91a
Add vs/vc configuration data structures and group related data/functi…
jcbrill Oct 10, 2023
9b6d7f3
Remove MSCommon/MSVC/Kind.py
jcbrill Oct 10, 2023
0d68786
Update msvs/msvc query implementation.
jcbrill Oct 11, 2023
f89eb5a
Remove unnecessary imports from MSVC/Config.py
jcbrill Oct 11, 2023
98f6b3f
Move AutoInitialize from common.py to MSVC/Util.py and fix log record…
jcbrill Oct 11, 2023
1563ae0
Reorder changes and release blurbs based on sequence of smaller PRs.
jcbrill Oct 11, 2023
5e63e55
Remove key.upper() in'PATH' literal comparison when searching for cl.…
jcbrill Oct 11, 2023
98dd971
New code movement to MSVC modules.
jcbrill Oct 12, 2023
26bdb85
Changes:
jcbrill Oct 14, 2023
7e55fdb
Temporarily use SCONS_MSVS_CHANNEL_DEFAULT environment variable to se…
jcbrill Oct 14, 2023
2036f17
Merge branch 'master' into jbrill-msvc-channel
jcbrill Oct 15, 2023
e56efcc
Changes:
jcbrill Oct 16, 2023
62a626b
Rework msvc options for running the test suite with preview-only msvc…
jcbrill Oct 20, 2023
2e0259c
Merge branch 'master' into jbrill-msvc-channel
jcbrill Oct 20, 2023
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
671 changes: 671 additions & 0 deletions SCons/Tool/MSCommon/MSVC/Kind.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions SCons/Tool/MSCommon/MSVC/Registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def windows_kit_query_paths(version):
q = windows_kits(version)
return microsoft_query_paths(q)

def vstudio_sxs_vs7(version):
return '\\'.join([r'VisualStudio\SxS\VS7', version])

def vstudio_sxs_vc7(version):
return '\\'.join([r'VisualStudio\SxS\VC7', version])

Expand Down
52 changes: 47 additions & 5 deletions SCons/Tool/MSCommon/MSVC/ScriptArguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from . import Config
from . import Registry
from . import WinSDK
from . import Kind

from .Exceptions import (
MSVCInternalError,
Expand Down Expand Up @@ -196,7 +197,7 @@ def _toolset_version(version):

return version_args

def _msvc_script_argument_uwp(env, msvc, arglist):
def _msvc_script_argument_uwp(env, msvc, arglist, target_arch):

uwp_app = env['MSVC_UWP_APP']
debug('MSVC_VERSION=%s, MSVC_UWP_APP=%s', repr(msvc.version), repr(uwp_app))
Expand All @@ -218,6 +219,23 @@ def _msvc_script_argument_uwp(env, msvc, arglist):
)
raise MSVCArgumentError(err_msg)

is_supported, is_target = Kind.msvc_version_uwp_is_supported(msvc.version, target_arch, env)
if not is_supported:
_, kind_str = Kind.get_msvc_version_kind(msvc.version)
debug(
'invalid: msvc_version constraint: %s %s %s',
repr(msvc.version), repr(kind_str), repr(target_arch)
)
if is_target and target_arch:
err_msg = "MSVC_UWP_APP ({}) TARGET_ARCH ({}) is not supported for MSVC_VERSION {} ({})".format(
repr(uwp_app), repr(target_arch), repr(msvc.version), repr(kind_str)
)
else:
err_msg = "MSVC_UWP_APP ({}) is not supported for MSVC_VERSION {} ({})".format(
repr(uwp_app), repr(msvc.version), repr(kind_str)
)
raise MSVCArgumentError(err_msg)

# VS2017+ rewrites uwp => store for 14.0 toolset
uwp_arg = msvc.vs_def.vc_uwp

Expand Down Expand Up @@ -250,7 +268,7 @@ def _user_script_argument_uwp(env, uwp, user_argstr) -> bool:

raise MSVCArgumentError(err_msg)

def _msvc_script_argument_sdk_constraints(msvc, sdk_version):
def _msvc_script_argument_sdk_constraints(msvc, sdk_version, env):

if msvc.vs_def.vc_buildtools_def.vc_version_numeric < VS2015.vc_buildtools_def.vc_version_numeric:
debug(
Expand All @@ -263,6 +281,14 @@ def _msvc_script_argument_sdk_constraints(msvc, sdk_version):
)
return err_msg

if not Kind.msvc_version_sdk_version_is_supported(msvc.version, env):
_, kind_str = Kind.get_msvc_version_kind(msvc.version)
debug('invalid: msvc_version constraint: %s %s', repr(msvc.version), repr(kind_str))
err_msg = "MSVC_SDK_VERSION ({}) is not supported for MSVC_VERSION {} ({})".format(
repr(sdk_version), repr(msvc.version), repr(kind_str)
)
return err_msg

for msvc_sdk_version in msvc.vs_def.vc_sdk_versions:
re_sdk_version = re_sdk_dispatch_map[msvc_sdk_version]
if re_sdk_version.match(sdk_version):
Expand Down Expand Up @@ -310,7 +336,7 @@ def _msvc_script_argument_sdk(env, msvc, toolset, platform_def, arglist):
if not sdk_version:
return None

err_msg = _msvc_script_argument_sdk_constraints(msvc, sdk_version)
err_msg = _msvc_script_argument_sdk_constraints(msvc, sdk_version, env)
if err_msg:
raise MSVCArgumentError(err_msg)

Expand All @@ -336,6 +362,9 @@ def _msvc_script_default_sdk(env, msvc, platform_def, arglist, force_sdk: bool=F
if msvc.vs_def.vc_buildtools_def.vc_version_numeric < VS2015.vc_buildtools_def.vc_version_numeric:
return None

if not Kind.msvc_version_sdk_version_is_supported(msvc.version, env):
return None

sdk_list = WinSDK.get_sdk_version_list(msvc.vs_def, platform_def)
if not len(sdk_list):
return None
Expand Down Expand Up @@ -873,7 +902,18 @@ def _msvc_process_construction_variables(env) -> bool:

return False

def msvc_script_arguments(env, version, vc_dir, arg):
def msvc_script_arguments_has_uwp(env):

if not _msvc_process_construction_variables(env):
return False

uwp_app = env.get('MSVC_UWP_APP')
is_uwp = bool(uwp_app and uwp_app in _ARGUMENT_BOOLEAN_TRUE_LEGACY)

debug('is_uwp=%s', is_uwp)
return is_uwp

def msvc_script_arguments(env, version, vc_dir, arg=None):

arguments = [arg] if arg else []

Expand All @@ -889,10 +929,12 @@ def msvc_script_arguments(env, version, vc_dir, arg):

if _msvc_process_construction_variables(env):

target_arch = env.get('TARGET_ARCH')

# MSVC_UWP_APP

if 'MSVC_UWP_APP' in env:
uwp = _msvc_script_argument_uwp(env, msvc, arglist)
uwp = _msvc_script_argument_uwp(env, msvc, arglist, target_arch)
else:
uwp = None

Expand Down
127 changes: 101 additions & 26 deletions SCons/Tool/MSCommon/MSVC/ScriptArgumentsTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
from SCons.Tool.MSCommon.MSVC import Util
from SCons.Tool.MSCommon.MSVC import WinSDK
from SCons.Tool.MSCommon.MSVC import ScriptArguments
from SCons.Tool.MSCommon.MSVC.Kind import (
msvc_version_is_express,
msvc_version_is_btdispatch,
)

from SCons.Tool.MSCommon.MSVC.Exceptions import (
MSVCInternalError,
Expand Down Expand Up @@ -127,7 +131,7 @@ class Data:

for vcver in Config.MSVC_VERSION_SUFFIX.keys():
version_def = Util.msvc_version_components(vcver)
vc_dir = vc.find_vc_pdir(None, vcver)
vc_dir = vc.find_vc_pdir(vcver)
t = (version_def, vc_dir)
ALL_VERSIONS_PAIRS.append(t)
if vc_dir:
Expand Down Expand Up @@ -229,7 +233,13 @@ def test_msvc_script_arguments_defaults(self) -> None:
for version_def, vc_dir in Data.INSTALLED_VERSIONS_PAIRS:
for arg in ('', 'arch'):
scriptargs = func(env, version_def.msvc_version, vc_dir, arg)
if version_def.msvc_vernum >= 14.0:
sdk_supported = True
if version_def.msvc_verstr == '14.0':
if msvc_version_is_express(version_def.msvc_version):
sdk_supported = False
elif msvc_version_is_btdispatch(version_def.msvc_version):
sdk_supported = False
if version_def.msvc_vernum >= 14.0 and sdk_supported:
if arg and scriptargs.startswith(arg):
testargs = scriptargs[len(arg):].lstrip()
else:
Expand Down Expand Up @@ -289,7 +299,7 @@ def run_msvc_script_args_none(self) -> None:
{'MSVC_SCRIPT_ARGS': None, 'MSVC_SPECTRE_LIBS': None},
]:
env = Environment(**kwargs)
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

def run_msvc_script_args(self) -> None:
func = ScriptArguments.msvc_script_arguments
Expand All @@ -312,7 +322,7 @@ def run_msvc_script_args(self) -> None:

# should not raise exception (argument not validated)
env = Environment(MSVC_SCRIPT_ARGS='undefinedsymbol')
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

for kwargs in [
{'MSVC_UWP_APP': False, 'MSVC_SCRIPT_ARGS': None},
Expand All @@ -323,7 +333,7 @@ def run_msvc_script_args(self) -> None:
{'MSVC_SPECTRE_LIBS': 'True', 'MSVC_SCRIPT_ARGS': '-vcvars_spectre_libs=spectre'}, # not boolean ignored
]:
env = Environment(**kwargs)
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

for msvc_uwp_app in (True, False):

Expand Down Expand Up @@ -368,9 +378,9 @@ def run_msvc_script_args(self) -> None:
env = Environment(**kwargs)
if exc:
with self.assertRaises(MSVCArgumentError):
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)
else:
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

else:

Expand All @@ -379,14 +389,14 @@ def run_msvc_script_args(self) -> None:
{'MSVC_SDK_VERSION': sdk_def.sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
]:
env = Environment(**kwargs)
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

for kwargs in [
{'MSVC_SCRIPT_ARGS': '-vcvars_ver={}'.format(version_def.msvc_verstr)},
{'MSVC_TOOLSET_VERSION': version_def.msvc_verstr},
]:
env = Environment(**kwargs)
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

msvc_toolset_notfound_version = Data.msvc_toolset_notfound_version(version_def.msvc_version)

Expand All @@ -398,7 +408,7 @@ def run_msvc_script_args(self) -> None:
]:
env = Environment(**kwargs)
with self.assertRaises(MSVCToolsetVersionNotFound):
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

msvc_sdk_notfound_version = Data.msvc_sdk_notfound_version(version_def.msvc_version)

Expand All @@ -407,15 +417,15 @@ def run_msvc_script_args(self) -> None:
]:
env = Environment(**kwargs)
with self.assertRaises(MSVCSDKVersionNotFound):
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

have_spectre = toolset_def.msvc_toolset_version in Data.SPECTRE_TOOLSET_VERSIONS.get(version_def.msvc_version,[])
env = Environment(MSVC_SPECTRE_LIBS=True, MSVC_TOOLSET_VERSION=toolset_def.msvc_toolset_version)
if not have_spectre:
with self.assertRaises(MSVCSpectreLibsNotFound):
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)
else:
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

msvc_sdk_version = Data.msvc_sdk_version(version_def.msvc_version)

Expand Down Expand Up @@ -519,40 +529,105 @@ def run_msvc_script_args(self) -> None:
] + more_tests:
env = Environment(**kwargs)
with self.assertRaises(exc_t):
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

elif version_def.msvc_verstr == '14.0':
# VS2015: MSVC_SDK_VERSION and MSVC_UWP_APP

if msvc_version_is_express(version_def.msvc_version):
sdk_supported = False
uwp_supported = True # based on target arch
elif msvc_version_is_btdispatch(version_def.msvc_version):
sdk_supported = False
uwp_supported = False
else:
sdk_supported = True
uwp_supported = True

env = Environment(MSVC_SCRIPT_ARGS='undefinedsymbol')
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

for msvc_uwp_app in (True, False):
if sdk_supported:
# VS2015: MSVC_SDK_VERSION

if uwp_supported:
# VS2015: MSVC_UWP_APP

for msvc_uwp_app in (True, False):

sdk_list = WinSDK.get_msvc_sdk_version_list(version_def.msvc_version, msvc_uwp_app=msvc_uwp_app)
for sdk_version in sdk_list:

for kwargs in [
{'MSVC_SCRIPT_ARGS': sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
{'MSVC_SDK_VERSION': sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
]:
env = Environment(**kwargs)
_ = func(env, version_def.msvc_version, vc_dir)

else:
# VS2015: MSVC_UWP_APP error

for msvc_uwp_app in (True,):

sdk_list = WinSDK.get_msvc_sdk_version_list(version_def.msvc_version, msvc_uwp_app=msvc_uwp_app)
for sdk_version in sdk_list:

for kwargs in [
{'MSVC_SCRIPT_ARGS': sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
{'MSVC_SDK_VERSION': sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
]:
env = Environment(**kwargs)
with self.assertRaises(MSVCArgumentError):
_ = func(env, version_def.msvc_version, vc_dir)

else:
# VS2015: MSVC_SDK_VERSION error

sdk_list = WinSDK.get_msvc_sdk_version_list(version_def.msvc_version, msvc_uwp_app=msvc_uwp_app)
for sdk_version in sdk_list:

for kwargs in [
{'MSVC_SCRIPT_ARGS': sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
{'MSVC_SDK_VERSION': sdk_version, 'MSVC_UWP_APP': msvc_uwp_app},
]:
env = Environment(**kwargs)
_ = func(env, version_def.msvc_version, vc_dir, '')
env = Environment(MSVC_SDK_VERSION=sdk_version)
with self.assertRaises(MSVCArgumentError):
_ = func(env, version_def.msvc_version, vc_dir)

# MSVC_SCRIPT_ARGS sdk_version not validated
env = Environment(MSVC_SCRIPT_ARGS=sdk_version)
_ = func(env, version_def.msvc_version, vc_dir)

if uwp_supported:
# VS2015: MSVC_UWP_APP

for msvc_uwp_app in (True, False):
env = Environment(MSVC_UWP_APP=msvc_uwp_app)
_ = func(env, version_def.msvc_version, vc_dir)

else:
# VS2015: MSVC_UWP_APP error

for msvc_uwp_app in (True,):

env = Environment(MSVC_UWP_APP=msvc_uwp_app)
with self.assertRaises(MSVCArgumentError):
_ = func(env, version_def.msvc_version, vc_dir)

# MSVC_SCRIPT_ARGS store not validated
env = Environment(MSVC_SCRIPT_ARGS='store')
_ = func(env, version_def.msvc_version, vc_dir)

for kwargs in [
{'MSVC_SPECTRE_LIBS': True, 'MSVC_SCRIPT_ARGS': None},
{'MSVC_TOOLSET_VERSION': version_def.msvc_verstr, 'MSVC_SCRIPT_ARGS': None},
]:
env = Environment(**kwargs)
with self.assertRaises(MSVCArgumentError):
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

else:
# VS2013 and earlier: no arguments

env = Environment(MSVC_SCRIPT_ARGS='undefinedsymbol')
with self.assertRaises(MSVCArgumentError):
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

for kwargs in [
{'MSVC_UWP_APP': True, 'MSVC_SCRIPT_ARGS': None},
Expand All @@ -563,7 +638,7 @@ def run_msvc_script_args(self) -> None:
]:
env = Environment(**kwargs)
with self.assertRaises(MSVCArgumentError):
_ = func(env, version_def.msvc_version, vc_dir, '')
_ = func(env, version_def.msvc_version, vc_dir)

def test_msvc_script_args_none(self) -> None:
force = ScriptArguments.msvc_force_default_arguments(force=False)
Expand Down
Loading
Loading