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 the MSVC_SDK_VERSION construction variable.
31 from SCons
.Tool
.MSCommon
.vc
import get_installed_vcs_components
32 from SCons
.Tool
.MSCommon
import msvc_sdk_versions
33 from SCons
.Tool
.MSCommon
import msvc_toolset_versions
36 test
= TestSCons
.TestSCons()
37 test
.skip_if_not_msvc()
39 installed_versions
= get_installed_vcs_components()
40 default_version
= installed_versions
[0]
41 GE_VS2015_versions
= [v
for v
in installed_versions
if v
.msvc_vernum
>= 14.0]
42 LT_VS2015_versions
= [v
for v
in installed_versions
if v
.msvc_vernum
< 14.0]
43 default_sdk_versions_uwp
= msvc_sdk_versions(version
=None, msvc_uwp_app
=True)
44 default_sdk_versions_def
= msvc_sdk_versions(version
=None, msvc_uwp_app
=False)
46 have_140
= any(v
.msvc_verstr
== '14.0' for v
in GE_VS2015_versions
)
48 def version_major(version
):
49 components
= version
.split('.')
50 if len(components
) >= 2:
51 return components
[0] + '.' + components
[1][0]
52 if len(components
) == 1:
53 return components
[0] + '.0'
56 def version_major_list(version_list
):
59 for version
in version_list
:
60 major
= version_major(version
)
61 if major
in seen_major
:
63 versions
.append(version
)
67 if GE_VS2015_versions
:
69 for supported
in GE_VS2015_versions
:
71 sdk_versions_uwp
= msvc_sdk_versions(version
=supported
.msvc_version
, msvc_uwp_app
=True)
72 sdk_versions_def
= msvc_sdk_versions(version
=supported
.msvc_version
, msvc_uwp_app
=False)
74 # find sdk version for each major SDK
75 sdk_versions
= version_major_list(sdk_versions_def
)
77 for sdk_version
in sdk_versions
:
79 # sdk version construction variable
80 test
.write('SConstruct', textwrap
.dedent(
82 DefaultEnvironment(tools=[])
83 env = Environment(MSVC_VERSION={0}, MSVC_SDK_VERSION={1}, tools=['msvc'])
84 lib_path = env['ENV']['LIB']
85 if '\\\\{2}\\\\' not in lib_path:
86 raise RuntimeError("{1} not found in lib path " + lib_path)
87 """.format(repr(supported
.msvc_version
), repr(sdk_version
), sdk_version
)
89 test
.run(arguments
='-Q -s', stdout
='')
91 # sdk version script argument
92 test
.write('SConstruct', textwrap
.dedent(
94 DefaultEnvironment(tools=[])
95 env = Environment(MSVC_VERSION={0}, MSVC_SCRIPT_ARGS={1}, tools=['msvc'])
96 lib_path = env['ENV']['LIB']
97 if '\\\\{2}\\\\' not in lib_path:
98 raise RuntimeError("{1} not found in lib path " + lib_path)
99 """.format(repr(supported
.msvc_version
), repr(sdk_version
), sdk_version
)
101 test
.run(arguments
='-Q -s', stdout
='')
103 # sdk version construction variable and script argument
104 test
.write('SConstruct', textwrap
.dedent(
106 DefaultEnvironment(tools=[])
107 env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION={}, MSVC_SCRIPT_ARGS={}, tools=['msvc'])
108 """.format(repr(supported
.msvc_version
), repr(sdk_version
), repr(sdk_version
))
110 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
111 expect
= "MSVCArgumentError: multiple sdk version declarations: MSVC_SDK_VERSION={} and MSVC_SCRIPT_ARGS={}:".format(
112 repr(sdk_version
), repr(sdk_version
)
114 test
.must_contain_all(test
.stderr(), expect
)
116 # sdk version is not supported
117 invalid_sdk_version
= '9.1'
118 test
.write('SConstruct', textwrap
.dedent(
120 DefaultEnvironment(tools=[])
121 env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION={}, tools=['msvc'])
122 """.format(repr(supported
.msvc_version
), repr(invalid_sdk_version
))
124 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
125 expect
= "MSVCArgumentError: MSVC_SDK_VERSION ({}) is not supported:".format(
126 repr(invalid_sdk_version
)
128 test
.must_contain_all(test
.stderr(), expect
)
130 # sdk version not found
131 missing_sdk_version
= '10.0.12345.6'
132 test
.write('SConstruct', textwrap
.dedent(
134 DefaultEnvironment(tools=[])
135 env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION={}, tools=['msvc'])
136 """.format(repr(supported
.msvc_version
), repr(missing_sdk_version
))
138 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
139 expect
= "MSVCSDKVersionNotFound: MSVC_SDK_VERSION {} not found for platform type 'Desktop':".format(
140 repr(missing_sdk_version
)
142 test
.must_contain_all(test
.stderr(), expect
)
144 # platform contraints: 8.1 and UWP
145 if '8.1' in sdk_versions
:
147 if supported
.msvc_vernum
> 14.0:
149 toolset_full_versions
= msvc_toolset_versions(supported
.msvc_version
, full
=True, sxs
=False)
150 toolset_versions
= version_major_list(toolset_full_versions
)
152 # toolset msvc_version != current msvc_version and toolset msvc_version != 14.0
153 toolset_candidates
= [v
for v
in toolset_versions
if version_major(v
) not in (supported
.msvc_verstr
, '14.0')]
154 toolset_version
= toolset_candidates
[0] if toolset_candidates
else None
156 # sdk version 8.1, UWP, and msvc_verson > VS2015
157 test
.write('SConstruct', textwrap
.dedent(
159 DefaultEnvironment(tools=[])
160 env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION='8.1', MSVC_UWP_APP=True, tools=['msvc'])
161 """.format(repr(supported
.msvc_version
))
163 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
164 expect
= "MSVCArgumentError: MSVC_SDK_VERSION ('8.1') and platform type ('UWP') constraint violation: MSVC_VERSION {} > '14.0' VS2015:".format(
165 repr(supported
.msvc_version
)
167 test
.must_contain_all(test
.stderr(), expect
)
171 # sdk version 8.1, UWP, and msvc_toolset_verson > VS2015
172 test
.write('SConstruct', textwrap
.dedent(
174 DefaultEnvironment(tools=[])
175 env = Environment(MSVC_VERSION={}, MSVC_TOOLSET_VERSION={}, MSVC_SDK_VERSION='8.1', MSVC_UWP_APP=True, tools=['msvc'])
176 """.format(repr(supported
.msvc_version
), repr(toolset_version
))
178 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
179 expect
= "MSVCArgumentError: MSVC_SDK_VERSION ('8.1') and platform type ('UWP') constraint violation: toolset version {} > '14.0' VS2015:".format(
180 repr(toolset_version
)
182 test
.must_contain_all(test
.stderr(), expect
)
186 # sdk version 8.1, UWP, and msvc_toolset_version > VS2015
187 test
.write('SConstruct', textwrap
.dedent(
189 DefaultEnvironment(tools=[])
190 env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION='8.1', MSVC_TOOLSET_VERSION='14.0', MSVC_UWP_APP=True, tools=['msvc'])
191 """.format(repr(supported
.msvc_version
))
193 test
.run(arguments
='-Q -s', stdout
='')
195 elif supported
.msvc_vernum
== 14.0:
197 # sdk version 8.1, UWP, and msvc_verson == VS2015
198 test
.write('SConstruct', textwrap
.dedent(
200 DefaultEnvironment(tools=[])
201 env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION='8.1', MSVC_UWP_APP=True, tools=['msvc'])
202 """.format(repr(supported
.msvc_version
))
204 test
.run(arguments
='-Q -s', stdout
='')
206 if LT_VS2015_versions
:
208 for unsupported
in LT_VS2015_versions
:
209 # must be VS2015 or later
211 sdk_version
= default_sdk_versions_def
[0] if default_sdk_versions_def
else '8.1'
213 test
.write('SConstruct', textwrap
.dedent(
215 DefaultEnvironment(tools=[])
216 env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION={}, tools=['msvc'])
217 """.format(repr(unsupported
.msvc_version
), repr(sdk_version
))
219 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
220 expect
= "MSVCArgumentError: MSVC_SDK_VERSION ({}) constraint violation: MSVC_VERSION {} < '14.0' VS2015:".format(
221 repr(sdk_version
), repr(unsupported
.msvc_version
)
223 test
.must_contain_all(test
.stderr(), expect
)
225 test
.write('SConstruct', textwrap
.dedent(
227 DefaultEnvironment(tools=[])
228 env = Environment(MSVC_VERSION={}, MSVC_SCRIPT_ARGS={}, tools=['msvc'])
229 """.format(repr(unsupported
.msvc_version
), repr(sdk_version
))
231 test
.run(arguments
='-Q -s', status
=2, stderr
=None)
232 expect
= "MSVCArgumentError: MSVC_SCRIPT_ARGS ({}) constraint violation: MSVC_VERSION {} < '14.0' VS2015:".format(
233 repr(sdk_version
), repr(unsupported
.msvc_version
)
235 test
.must_contain_all(test
.stderr(), expect
)
241 # indent-tabs-mode:nil
243 # vim: set expandtab tabstop=4 shiftwidth=4: