3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Test batch file argument functions for Microsoft Visual C/C++.
30 import SCons
.Environment
32 from SCons
.Tool
.MSCommon
import vc
33 from SCons
.Tool
.MSCommon
import vcTests
35 from SCons
.Tool
.MSCommon
.MSVC
import Config
36 from SCons
.Tool
.MSCommon
.MSVC
import Util
37 from SCons
.Tool
.MSCommon
.MSVC
import WinSDK
38 from SCons
.Tool
.MSCommon
.MSVC
import ScriptArguments
39 from SCons
.Tool
.MSCommon
.MSVC
.Kind
import (
40 msvc_version_is_express
,
41 msvc_version_is_btdispatch
,
44 from SCons
.Tool
.MSCommon
.MSVC
.Exceptions
import (
47 MSVCToolsetVersionNotFound
,
48 MSVCSDKVersionNotFound
,
49 MSVCSpectreLibsNotFound
,
52 def Environment(**kwargs
):
54 if tools_key
not in kwargs
:
57 tools
= kwargs
[tools_key
]
59 return SCons
.Environment
.Base(tools
=tools
, **kwargs
)
61 def _sdk_versions_comps_dict_seen(installed_version_pairs
):
63 sdk_versions_comps_dict
= {}
64 sdk_versions_seen
= set()
66 _sdk_version_list_seen
= {}
67 for version_def
, _
in installed_version_pairs
:
68 sdk_versions_comps_dict
[version_def
.msvc_version
] = {}
69 for msvc_uwp_app
in (True, False):
70 sdk_version_list
= WinSDK
.get_msvc_sdk_version_list(version_def
.msvc_version
, msvc_uwp_app
=msvc_uwp_app
)
71 key
= tuple(sdk_version_list
)
72 if key
in _sdk_version_list_seen
:
73 sdk_comps_list
= _sdk_version_list_seen
[key
]
75 sdk_versions_seen
.update(sdk_version_list
)
76 sdk_comps_list
= [Util
.msvc_sdk_version_components(sdk_version
) for sdk_version
in sdk_version_list
]
77 _sdk_version_list_seen
[key
] = sdk_comps_list
78 sdk_versions_comps_dict
[version_def
.msvc_version
][msvc_uwp_app
] = sdk_comps_list
80 return sdk_versions_comps_dict
, sdk_versions_seen
82 def _sdk_versions_notfound(installed_version_pairs
, sdk_versions_comps_dict
, sdk_versions_seen
):
84 sdk_versions_notfound_dict
= {}
85 sdk_notfound_seen
= {}
87 def _make_notfound_version(sdk_seen
, sdk_def
):
88 if len(sdk_def
.sdk_comps
) == 4:
91 ival
= int(sdk_def
.sdk_comps
[-2])
95 version
= '{}.{}.{:05d}.{}'.format(
96 sdk_def
.sdk_comps
[0], sdk_def
.sdk_comps
[1], ival
, sdk_def
.sdk_comps
[-1]
98 if version
not in sdk_seen
:
103 for version_def
, _
in installed_version_pairs
:
104 sdk_versions_notfound_dict
[version_def
.msvc_version
] = {}
105 for msvc_uwp_app
in (True, False):
106 sdk_notfound_list
= []
107 sdk_versions_notfound_dict
[version_def
.msvc_version
][msvc_uwp_app
] = sdk_notfound_list
108 sdk_comps_list
= sdk_versions_comps_dict
[version_def
.msvc_version
][msvc_uwp_app
]
109 for sdk_def
in sdk_comps_list
:
110 if sdk_def
.sdk_version
in sdk_notfound_seen
:
111 sdk_notfound_version
= sdk_notfound_seen
[sdk_def
.sdk_version
]
113 sdk_notfound_version
= _make_notfound_version(sdk_versions_seen
, sdk_def
)
114 sdk_notfound_seen
[sdk_def
.sdk_version
] = sdk_notfound_version
115 if not sdk_notfound_version
:
117 sdk_notfound_list
.append(sdk_notfound_version
)
119 return sdk_versions_notfound_dict
124 ALL_VERSIONS_PAIRS
= []
127 INSTALLED_VERSIONS_PAIRS
= []
130 HAVE140_TOOLSET
= ScriptArguments
._msvc
_have
140_toolset
()
132 for vcver
in Config
.MSVC_VERSION_SUFFIX
.keys():
133 version_def
= Util
.msvc_version_components(vcver
)
134 vc_dir
= vc
.find_vc_pdir(vcver
)
135 t
= (version_def
, vc_dir
)
136 ALL_VERSIONS_PAIRS
.append(t
)
138 INSTALLED_VERSIONS_PAIRS
.append(t
)
140 HAVE_MSVC
= True if len(INSTALLED_VERSIONS_PAIRS
) else False
142 SPECTRE_TOOLSET_VERSIONS
= {
143 version_def
.msvc_version
: vc
.msvc_toolset_versions_spectre(version_def
.msvc_version
)
144 for version_def
, _
in INSTALLED_VERSIONS_PAIRS
147 SDK_VERSIONS_COMPS_DICT
, SDK_VERSIONS_SEEN
= _sdk_versions_comps_dict_seen(INSTALLED_VERSIONS_PAIRS
)
149 SDK_VERSIONS_NOTFOUND_DICT
= _sdk_versions_notfound(
150 INSTALLED_VERSIONS_PAIRS
, SDK_VERSIONS_COMPS_DICT
, SDK_VERSIONS_SEEN
154 def msvc_sdk_version_list_components(cls
, msvc_version
, msvc_uwp_app
: bool=False):
155 comps_dict
= cls
.SDK_VERSIONS_COMPS_DICT
.get(msvc_version
, {})
156 comps_list
= comps_dict
.get(msvc_uwp_app
, [])
160 def msvc_sdk_version(cls
, msvc_version
, msvc_uwp_app
: bool=False):
161 comps_dict
= cls
.SDK_VERSIONS_COMPS_DICT
.get(msvc_version
, {})
162 comps_list
= comps_dict
.get(msvc_uwp_app
, [])
164 sdk_version
= '10.0.20348.0'
166 sdk_version
= comps_list
[0].sdk_version
170 def msvc_sdk_notfound_version(cls
, msvc_version
, msvc_uwp_app
: bool=False):
171 notfound_dict
= cls
.SDK_VERSIONS_NOTFOUND_DICT
.get(msvc_version
, {})
172 notfound_list
= notfound_dict
.get(msvc_uwp_app
, [])
173 if not notfound_list
:
174 notfound_version
= '10.0.00000.1'
176 notfound_version
= notfound_list
[0]
177 return notfound_version
180 def msvc_toolset_notfound_dict(cls
):
181 return vcTests
.Data
.msvc_toolset_notfound_dict()
184 def msvc_toolset_notfound_version(cls
, msvc_version
):
185 d
= cls
.msvc_toolset_notfound_dict()
186 notfound_versions
= d
.get(msvc_version
,[])
187 if not notfound_versions
:
188 notfound_version
= msvc_version
+ '0.00001'
190 notfound_version
= notfound_versions
[0]
191 return notfound_version
197 class MSVC_SDK_VERSIONS
:
199 MSVC_SDK_VERSIONS
= Config
.MSVC_SDK_VERSIONS
202 def enable_copy(cls
):
203 hook
= set(cls
.MSVC_SDK_VERSIONS
)
204 Config
.MSVC_SDK_VERSIONS
= hook
208 def restore(cls
) -> None:
209 Config
.MSVC_SDK_VERSIONS
= cls
.MSVC_SDK_VERSIONS
211 class ScriptArgumentsTests(unittest
.TestCase
):
213 def test_verify(self
) -> None:
214 MSVC_SDK_VERSIONS
= Patch
.Config
.MSVC_SDK_VERSIONS
.enable_copy()
215 MSVC_SDK_VERSIONS
.add('99.0')
216 with self
.assertRaises(MSVCInternalError
):
217 ScriptArguments
.verify()
218 Patch
.Config
.MSVC_SDK_VERSIONS
.restore()
220 def test_msvc_script_arguments_defaults(self
) -> None:
221 func
= ScriptArguments
.msvc_script_arguments
223 # disable forcing sdk and toolset versions as arguments
224 force
= ScriptArguments
.msvc_force_default_arguments(force
=False)
225 for version_def
, vc_dir
in Data
.INSTALLED_VERSIONS_PAIRS
:
226 for arg
in ('', 'arch'):
227 scriptargs
= func(env
, version_def
.msvc_version
, vc_dir
, arg
)
228 self
.assertTrue(scriptargs
== arg
, "{}({},{}) != {} [force=False]".format(
229 func
.__name
__, repr(version_def
.msvc_version
), repr(arg
), repr(scriptargs
)
231 # enable forcing sdk and toolset versions as arguments
232 ScriptArguments
.msvc_force_default_arguments(force
=True)
233 for version_def
, vc_dir
in Data
.INSTALLED_VERSIONS_PAIRS
:
234 for arg
in ('', 'arch'):
235 scriptargs
= func(env
, version_def
.msvc_version
, vc_dir
, arg
)
237 if version_def
.msvc_verstr
== '14.0':
238 if msvc_version_is_express(version_def
.msvc_version
):
239 sdk_supported
= False
240 elif msvc_version_is_btdispatch(version_def
.msvc_version
):
241 sdk_supported
= False
242 if version_def
.msvc_vernum
>= 14.0 and sdk_supported
:
243 if arg
and scriptargs
.startswith(arg
):
244 testargs
= scriptargs
[len(arg
):].lstrip()
246 testargs
= scriptargs
247 self
.assertTrue(testargs
, "{}({},{}) is empty [force=True]".format(
248 func
.__name
__, repr(version_def
.msvc_version
), repr(arg
)
251 self
.assertTrue(scriptargs
== arg
, "{}({},{}) != {} [force=True]".format(
252 func
.__name
__, repr(version_def
.msvc_version
), repr(arg
), repr(scriptargs
)
254 # restore forcing sdk and toolset versions as arguments
255 ScriptArguments
.msvc_force_default_arguments(force
=force
)
257 def test_msvc_toolset_versions_internal(self
) -> None:
258 func
= ScriptArguments
._msvc
_toolset
_versions
_internal
259 for version_def
, vc_dir
in Data
.INSTALLED_VERSIONS_PAIRS
:
260 for full
in (True, False):
261 for sxs
in (True, False):
262 toolset_versions
= func(version_def
.msvc_version
, vc_dir
, full
=full
, sxs
=sxs
)
263 if version_def
.msvc_vernum
< 14.1:
264 self
.assertTrue(toolset_versions
is None, "{}({},{},full={},sxs={}) is not None ({})".format(
265 func
.__name
__, repr(version_def
.msvc_version
), repr(vc_dir
), repr(full
), repr(sxs
),
266 repr(toolset_versions
)
269 self
.assertTrue(len(toolset_versions
), "{}({},{},full={},sxs={}) is empty".format(
270 func
.__name
__, repr(version_def
.msvc_version
), repr(vc_dir
), repr(full
), repr(sxs
)
273 # sxs list can be empty
276 self
.assertFalse(len(toolset_versions
), "{}({},{},full={},sxs={}) is not empty".format(
277 func
.__name
__, repr(version_def
.msvc_version
), repr(vc_dir
), repr(full
), repr(sxs
)
280 def test_msvc_toolset_internal(self
) -> None:
281 if not Data
.HAVE_MSVC
:
283 func
= ScriptArguments
._msvc
_toolset
_internal
284 for version_def
, vc_dir
in Data
.INSTALLED_VERSIONS_PAIRS
:
285 toolset_versions
= ScriptArguments
._msvc
_toolset
_versions
_internal
(version_def
.msvc_version
, vc_dir
, full
=True, sxs
=True)
286 if not toolset_versions
:
288 for toolset_version
in toolset_versions
:
289 _
= func(version_def
.msvc_version
, toolset_version
, vc_dir
)
291 def run_msvc_script_args_none(self
) -> None:
292 func
= ScriptArguments
.msvc_script_arguments
293 for version_def
, vc_dir
in Data
.INSTALLED_VERSIONS_PAIRS
:
295 {'MSVC_SCRIPT_ARGS': None},
296 {'MSVC_SCRIPT_ARGS': None, 'MSVC_UWP_APP': None},
297 {'MSVC_SCRIPT_ARGS': None, 'MSVC_TOOLSET_VERSION': None},
298 {'MSVC_SCRIPT_ARGS': None, 'MSVC_SDK_VERSION': None},
299 {'MSVC_SCRIPT_ARGS': None, 'MSVC_SPECTRE_LIBS': None},
301 env
= Environment(**kwargs
)
302 _
= func(env
, version_def
.msvc_version
, vc_dir
)
304 def run_msvc_script_args(self
) -> None:
305 func
= ScriptArguments
.msvc_script_arguments
306 for version_def
, vc_dir
in Data
.INSTALLED_VERSIONS_PAIRS
:
307 if version_def
.msvc_vernum
>= 14.1:
311 Util
.msvc_extended_version_components(toolset_version
)
312 for toolset_version
in
313 ScriptArguments
._msvc
_toolset
_versions
_internal
(
314 version_def
.msvc_version
, vc_dir
, full
=True, sxs
=False
318 toolset_def
= toolset_versions
[0] if toolset_versions
else Util
.msvc_extended_version_components(version_def
.msvc_verstr
)
320 earlier_toolset_versions
= [earlier_toolset_def
for earlier_toolset_def
in toolset_versions
if earlier_toolset_def
.msvc_vernum
!= version_def
.msvc_vernum
]
321 earlier_toolset_def
= earlier_toolset_versions
[0] if earlier_toolset_versions
else None
323 vc_buildtools_def
= Config
.MSVC_BUILDTOOLS_EXTERNAL
[toolset_def
.msvc_buildtools
]
324 vc_buildseries_def
= vc_buildtools_def
.vc_buildseries_list
[0]
326 latest_buildseries_major
, latest_buildseries_minor
= [int(comp
) for comp
in vc_buildseries_def
.vc_version
.split('.')]
328 # should not raise exception (argument not validated)
329 env
= Environment(MSVC_SCRIPT_ARGS
='undefinedsymbol')
330 _
= func(env
, version_def
.msvc_version
, vc_dir
)
333 {'MSVC_UWP_APP': False, 'MSVC_SCRIPT_ARGS': None},
334 {'MSVC_UWP_APP': '0', 'MSVC_SCRIPT_ARGS': None},
335 {'MSVC_UWP_APP': False, 'MSVC_SCRIPT_ARGS': 'store'},
336 {'MSVC_UWP_APP': '0', 'MSVC_SCRIPT_ARGS': 'store'},
337 {'MSVC_SPECTRE_LIBS': False, 'MSVC_SCRIPT_ARGS': '-vcvars_spectre_libs=spectre'},
338 {'MSVC_SPECTRE_LIBS': 'True', 'MSVC_SCRIPT_ARGS': '-vcvars_spectre_libs=spectre'}, # not boolean ignored
340 env
= Environment(**kwargs
)
341 _
= func(env
, version_def
.msvc_version
, vc_dir
)
343 for msvc_uwp_app
in (True, False):
345 sdk_list
= Data
.msvc_sdk_version_list_components(version_def
.msvc_version
, msvc_uwp_app
=msvc_uwp_app
)
346 for sdk_def
in sdk_list
:
348 if sdk_def
.sdk_verstr
== '8.1' and msvc_uwp_app
:
352 if earlier_toolset_def
:
353 # SDK 8.1 and UWP: toolset must be 14.0
354 expect
= True if earlier_toolset_def
.msvc_vernum
> 14.0 else False
357 'MSVC_SDK_VERSION': sdk_def
.sdk_version
,
358 'MSVC_UWP_APP': msvc_uwp_app
,
359 'MSVC_TOOLSET_VERSION': earlier_toolset_def
.msvc_toolset_version
363 expect
= True if version_def
.msvc_vernum
> 14.0 else False
366 # script args not validated
368 'MSVC_SCRIPT_ARGS': sdk_def
.sdk_version
,
369 'MSVC_UWP_APP': msvc_uwp_app
371 # SDK 8.1 and UWP: msvc_version > 14.0
373 'MSVC_SDK_VERSION': sdk_def
.sdk_version
,
374 'MSVC_UWP_APP': msvc_uwp_app
376 # SDK 8.1 and UWP: toolset must be 14.0
378 'MSVC_SDK_VERSION': sdk_def
.sdk_version
,
379 'MSVC_UWP_APP': msvc_uwp_app
,
380 'MSVC_TOOLSET_VERSION': toolset_def
.msvc_toolset_version
383 env
= Environment(**kwargs
)
385 with self
.assertRaises(MSVCArgumentError
):
386 _
= func(env
, version_def
.msvc_version
, vc_dir
)
388 _
= func(env
, version_def
.msvc_version
, vc_dir
)
393 {'MSVC_SCRIPT_ARGS': sdk_def
.sdk_version
, 'MSVC_UWP_APP': msvc_uwp_app
},
394 {'MSVC_SDK_VERSION': sdk_def
.sdk_version
, 'MSVC_UWP_APP': msvc_uwp_app
},
396 env
= Environment(**kwargs
)
397 _
= func(env
, version_def
.msvc_version
, vc_dir
)
400 {'MSVC_SCRIPT_ARGS': '-vcvars_ver={}'.format(toolset_def
.msvc_toolset_version
)},
401 {'MSVC_TOOLSET_VERSION': toolset_def
.msvc_toolset_version
},
403 env
= Environment(**kwargs
)
404 _
= func(env
, version_def
.msvc_version
, vc_dir
)
406 msvc_toolset_notfound_version
= Data
.msvc_toolset_notfound_version(version_def
.msvc_version
)
409 {'MSVC_TOOLSET_VERSION': msvc_toolset_notfound_version
},
410 {'MSVC_TOOLSET_VERSION': "{}.{}.00.0".format(
411 toolset_def
.msvc_toolset_comps
[0], toolset_def
.msvc_toolset_comps
[1]
414 env
= Environment(**kwargs
)
415 with self
.assertRaises(MSVCToolsetVersionNotFound
):
416 _
= func(env
, version_def
.msvc_version
, vc_dir
)
418 msvc_sdk_notfound_version
= Data
.msvc_sdk_notfound_version(version_def
.msvc_version
)
421 {'MSVC_SDK_VERSION': msvc_sdk_notfound_version
},
423 env
= Environment(**kwargs
)
424 with self
.assertRaises(MSVCSDKVersionNotFound
):
425 _
= func(env
, version_def
.msvc_version
, vc_dir
)
427 have_spectre
= toolset_def
.msvc_toolset_version
in Data
.SPECTRE_TOOLSET_VERSIONS
.get(version_def
.msvc_version
,[])
428 env
= Environment(MSVC_SPECTRE_LIBS
=True, MSVC_TOOLSET_VERSION
=toolset_def
.msvc_toolset_version
)
430 with self
.assertRaises(MSVCSpectreLibsNotFound
):
431 _
= func(env
, version_def
.msvc_version
, vc_dir
)
433 _
= func(env
, version_def
.msvc_version
, vc_dir
)
435 msvc_sdk_version
= Data
.msvc_sdk_version(version_def
.msvc_version
)
439 if Data
.HAVE140_TOOLSET
:
443 ({'MSVC_TOOLSET_VERSION': '14.00.00001',
445 (MSVCArgumentError
, ),
449 for kwargs
, exc_t
in [
450 # multiple definitions
451 ({'MSVC_UWP_APP': True,
452 'MSVC_SCRIPT_ARGS': 'uwp'
453 }, (MSVCArgumentError
, ),
455 # multiple definitions (args)
456 ({'MSVC_UWP_APP': True,
457 'MSVC_SCRIPT_ARGS': 'uwp undefined store'
458 }, (MSVCArgumentError
, ),
460 # multiple definitions
461 ({'MSVC_TOOLSET_VERSION': toolset_def
.msvc_toolset_version
,
462 'MSVC_SCRIPT_ARGS': "-vcvars_ver={}".format(toolset_def
.msvc_toolset_version
)
464 (MSVCArgumentError
, ),
466 # multiple definitions (args)
467 ({'MSVC_TOOLSET_VERSION': toolset_def
.msvc_toolset_version
,
468 'MSVC_SCRIPT_ARGS': "-vcvars_ver={0} undefined -vcvars_ver={0}".format(toolset_def
.msvc_toolset_version
)
470 (MSVCArgumentError
, ),
472 # multiple definitions
473 ({'MSVC_SDK_VERSION': msvc_sdk_version
,
474 'MSVC_SCRIPT_ARGS': msvc_sdk_version
476 (MSVCArgumentError
, ),
478 # multiple definitions (args)
479 ({'MSVC_SDK_VERSION': msvc_sdk_version
,
480 'MSVC_SCRIPT_ARGS': '{0} undefined {0}'.format(msvc_sdk_version
)
482 (MSVCArgumentError
, ),
484 # multiple definitions
485 ({'MSVC_SPECTRE_LIBS': True,
486 'MSVC_SCRIPT_ARGS': '-vcvars_spectre_libs=spectre'
488 (MSVCArgumentError
, MSVCSpectreLibsNotFound
),
490 # multiple definitions (args)
491 ({'MSVC_SPECTRE_LIBS': True,
492 'MSVC_SCRIPT_ARGS': '-vcvars_spectre_libs=spectre undefined -vcvars_spectre_libs=spectre'
494 (MSVCArgumentError
, MSVCSpectreLibsNotFound
),
497 ({'MSVC_TOOLSET_VERSION': '12.0',
499 (MSVCArgumentError
, ),
501 # toolset > msvc_version
502 ({'MSVC_TOOLSET_VERSION': '{}.{}'.format(latest_buildseries_major
, latest_buildseries_minor
+1),
504 (MSVCArgumentError
, ),
506 # version not supported
507 ({'MSVC_TOOLSET_VERSION': "{}".format(version_def
.msvc_major
),
509 (MSVCArgumentError
, ),
511 # version not supported
512 ({'MSVC_TOOLSET_VERSION': "{}.{}.00000.0".format(
513 toolset_def
.msvc_toolset_comps
[0], toolset_def
.msvc_toolset_comps
[1]
515 (MSVCArgumentError
, ),
517 # version not supported
518 ({'MSVC_SDK_VERSION': '9.1',
520 (MSVCArgumentError
, ),
522 # spectre not available for UWP
523 ({'MSVC_SPECTRE_LIBS': True,
524 'MSVC_UWP_APP': True,
526 (MSVCArgumentError
, MSVCSpectreLibsNotFound
),
528 # spectre not available in VS2015
529 ({'MSVC_SPECTRE_LIBS': True,
530 'MSVC_TOOLSET_VERSION': '14.00.00000',
532 (MSVCArgumentError
, MSVCSpectreLibsNotFound
, MSVCToolsetVersionNotFound
),
535 env
= Environment(**kwargs
)
536 with self
.assertRaises(exc_t
):
537 _
= func(env
, version_def
.msvc_version
, vc_dir
)
539 elif version_def
.msvc_verstr
== '14.0':
541 if msvc_version_is_express(version_def
.msvc_version
):
542 sdk_supported
= False
543 uwp_supported
= True # based on target arch
544 elif msvc_version_is_btdispatch(version_def
.msvc_version
):
545 sdk_supported
= False
546 uwp_supported
= False
551 env
= Environment(MSVC_SCRIPT_ARGS
='undefinedsymbol')
552 _
= func(env
, version_def
.msvc_version
, vc_dir
)
555 # VS2015: MSVC_SDK_VERSION
558 # VS2015: MSVC_UWP_APP
560 for msvc_uwp_app
in (True, False):
562 sdk_list
= WinSDK
.get_msvc_sdk_version_list(version_def
.msvc_version
, msvc_uwp_app
=msvc_uwp_app
)
563 for sdk_version
in sdk_list
:
566 {'MSVC_SCRIPT_ARGS': sdk_version
, 'MSVC_UWP_APP': msvc_uwp_app
},
567 {'MSVC_SDK_VERSION': sdk_version
, 'MSVC_UWP_APP': msvc_uwp_app
},
569 env
= Environment(**kwargs
)
570 _
= func(env
, version_def
.msvc_version
, vc_dir
)
573 # VS2015: MSVC_UWP_APP error
575 for msvc_uwp_app
in (True,):
577 sdk_list
= WinSDK
.get_msvc_sdk_version_list(version_def
.msvc_version
, msvc_uwp_app
=msvc_uwp_app
)
578 for sdk_version
in sdk_list
:
581 {'MSVC_SCRIPT_ARGS': sdk_version
, 'MSVC_UWP_APP': msvc_uwp_app
},
582 {'MSVC_SDK_VERSION': sdk_version
, 'MSVC_UWP_APP': msvc_uwp_app
},
584 env
= Environment(**kwargs
)
585 with self
.assertRaises(MSVCArgumentError
):
586 _
= func(env
, version_def
.msvc_version
, vc_dir
)
589 # VS2015: MSVC_SDK_VERSION error
591 sdk_list
= WinSDK
.get_msvc_sdk_version_list(version_def
.msvc_version
, msvc_uwp_app
=msvc_uwp_app
)
592 for sdk_version
in sdk_list
:
594 env
= Environment(MSVC_SDK_VERSION
=sdk_version
)
595 with self
.assertRaises(MSVCArgumentError
):
596 _
= func(env
, version_def
.msvc_version
, vc_dir
)
598 # MSVC_SCRIPT_ARGS sdk_version not validated
599 env
= Environment(MSVC_SCRIPT_ARGS
=sdk_version
)
600 _
= func(env
, version_def
.msvc_version
, vc_dir
)
603 # VS2015: MSVC_UWP_APP
605 for msvc_uwp_app
in (True, False):
606 env
= Environment(MSVC_UWP_APP
=msvc_uwp_app
)
607 _
= func(env
, version_def
.msvc_version
, vc_dir
)
610 # VS2015: MSVC_UWP_APP error
612 for msvc_uwp_app
in (True,):
614 env
= Environment(MSVC_UWP_APP
=msvc_uwp_app
)
615 with self
.assertRaises(MSVCArgumentError
):
616 _
= func(env
, version_def
.msvc_version
, vc_dir
)
618 # MSVC_SCRIPT_ARGS store not validated
619 env
= Environment(MSVC_SCRIPT_ARGS
='store')
620 _
= func(env
, version_def
.msvc_version
, vc_dir
)
623 {'MSVC_SPECTRE_LIBS': True, 'MSVC_SCRIPT_ARGS': None},
624 {'MSVC_TOOLSET_VERSION': version_def
.msvc_verstr
, 'MSVC_SCRIPT_ARGS': None},
626 env
= Environment(**kwargs
)
627 with self
.assertRaises(MSVCArgumentError
):
628 _
= func(env
, version_def
.msvc_version
, vc_dir
)
631 # VS2013 and earlier: no arguments
633 env
= Environment(MSVC_SCRIPT_ARGS
='undefinedsymbol')
634 with self
.assertRaises(MSVCArgumentError
):
635 _
= func(env
, version_def
.msvc_version
, vc_dir
)
638 {'MSVC_UWP_APP': True, 'MSVC_SCRIPT_ARGS': None},
639 {'MSVC_UWP_APP': '1', 'MSVC_SCRIPT_ARGS': None},
640 {'MSVC_SPECTRE_LIBS': True, 'MSVC_SCRIPT_ARGS': None},
641 {'MSVC_TOOLSET_VERSION': version_def
.msvc_verstr
, 'MSVC_SCRIPT_ARGS': None},
642 {'MSVC_SDK_VERSION': '10.0.00000.0', 'MSVC_SCRIPT_ARGS': None},
644 env
= Environment(**kwargs
)
645 with self
.assertRaises(MSVCArgumentError
):
646 _
= func(env
, version_def
.msvc_version
, vc_dir
)
648 def test_msvc_script_args_none(self
) -> None:
649 force
= ScriptArguments
.msvc_force_default_arguments(force
=False)
650 self
.run_msvc_script_args_none()
652 ScriptArguments
.msvc_force_default_arguments(force
=True)
653 self
.run_msvc_script_args_none()
654 ScriptArguments
.msvc_force_default_arguments(force
=force
)
656 def test_msvc_script_args(self
) -> None:
657 force
= ScriptArguments
.msvc_force_default_arguments(force
=False)
658 self
.run_msvc_script_args()
659 ScriptArguments
.msvc_force_default_arguments(force
=True)
660 self
.run_msvc_script_args()
661 ScriptArguments
.msvc_force_default_arguments(force
=force
)
663 def test_reset(self
) -> None:
664 ScriptArguments
.reset()
665 self
.assertTrue(ScriptArguments
._toolset
_have
140_cache
is None, "ScriptArguments._toolset_have140_cache was not reset")
666 self
.assertFalse(ScriptArguments
._toolset
_version
_cache
, "ScriptArguments._toolset_version_cache was not reset")
667 self
.assertFalse(ScriptArguments
._toolset
_default
_cache
, "ScriptArguments._toolset_default_cache was not reset")
669 if __name__
== "__main__":