Merge pull request #4655 from bdbaddog/fix_new_ninja_package
[scons.git] / test / MSVC / msvc_cache_force_defaults.py
blobad67304d560f1a9d23e706660766d23b25693b8e
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Test SCONS_CACHE_MSVC_FORCE_DEFAULTS system environment variable.
28 """
30 import textwrap
32 from SCons.Tool.MSCommon.vc import get_installed_vcs_components
33 from SCons.Tool.MSCommon.MSVC.Kind import (
34 msvc_version_is_express,
35 msvc_version_is_btdispatch,
37 import TestSCons
39 test = TestSCons.TestSCons()
40 test.skip_if_not_msvc()
42 installed_versions = get_installed_vcs_components()
43 default_version = installed_versions[0]
44 if default_version.msvc_vernum < 14.0:
45 test.skip_test("MSVC version earlier than 14.0, skipping.")
47 # VS2015 and later
48 # force SDK version and toolset version as msvc batch file arguments
49 test.write('SConstruct', textwrap.dedent(
50 """
51 import os
52 import json
54 cache_file = 'MSCACHE.json'
56 os.environ['SCONS_CACHE_MSVC_CONFIG']=cache_file
57 os.environ['SCONS_CACHE_MSVC_FORCE_DEFAULTS']='1'
59 DefaultEnvironment(tools=[])
60 env = Environment(tools=['msvc'])
62 envcache_keys = []
63 with open(cache_file, 'r') as file:
64 envcache_list = json.load(file)
65 envcache_keys = [tuple(d['key']) for d in envcache_list]
67 if envcache_keys:
68 # key = (script, arguments)
69 print("SCRIPT_ARGS: {}".format(envcache_keys[0][-1]))
70 """
72 test.run(arguments="-Q -s", status=0, stdout=None)
73 cache_arg = test.stdout().strip()
74 if default_version.msvc_verstr == '14.0':
75 if msvc_version_is_express(default_version.msvc_version):
76 # VS2015 Express: target_arch
77 expect = r'^SCRIPT_ARGS: [a-zA-Z0-9_]+$'
78 elif msvc_version_is_btdispatch(default_version.msvc_version):
79 # VS2015 BTDispatch: target_arch
80 expect = r'^SCRIPT_ARGS: [a-zA-Z0-9_]+$'
81 else:
82 # VS2015: target_arch msvc_sdk_version
83 expect = r'^SCRIPT_ARGS: [a-zA-Z0-9_]+ [0-9.]+$'
84 else:
85 # VS2017+ msvc_sdk_version msvc_toolset_version
86 expect = r'^SCRIPT_ARGS: [0-9.]+ -vcvars_ver=[0-9.]+$'
88 test.must_contain_all(cache_arg, expect, find=TestSCons.match_re)
90 test.pass_test()
92 # Local Variables:
93 # tab-width:4
94 # indent-tabs-mode:nil
95 # End:
96 # vim: set expandtab tabstop=4 shiftwidth=4: