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.
27 Test SCONS_CACHE_MSVC_FORCE_DEFAULTS system environment variable.
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
,
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.")
48 # force SDK version and toolset version as msvc batch file arguments
49 test
.write('SConstruct', textwrap
.dedent(
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'])
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]
68 # key = (script, arguments)
69 print("SCRIPT_ARGS: {}".format(envcache_keys[0][-1]))
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_]+$'
82 # VS2015: target_arch msvc_sdk_version
83 expect
= r
'^SCRIPT_ARGS: [a-zA-Z0-9_]+ [0-9.]+$'
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
)
94 # indent-tabs-mode:nil
96 # vim: set expandtab tabstop=4 shiftwidth=4: