Merge branch 'master' into jbrill-msvc-detect
[scons.git] / test / MSVC / MSVC_SPECTRE_LIBS.py
blob4747e4ba42beaa5e582a1e99268cc7893a8cae57
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 the MSVC_SPECTRE_LIBS construction variable.
28 """
30 import TestSCons
31 import textwrap
33 from SCons.Tool.MSCommon.vc import get_installed_vcs_components
34 from SCons.Tool.MSCommon import msvc_toolset_versions_spectre
36 test = TestSCons.TestSCons()
37 test.skip_if_not_msvc()
39 installed_versions = get_installed_vcs_components()
40 GE_VS2017_versions = [v for v in installed_versions if v.msvc_vernum >= 14.1]
41 LT_VS2017_versions = [v for v in installed_versions if v.msvc_vernum < 14.1]
43 if GE_VS2017_versions:
44 # VS2017 and later for toolset argument
46 for supported in GE_VS2017_versions:
48 spectre_toolset_versions = msvc_toolset_versions_spectre(supported.msvc_version)
49 spectre_toolset_version = spectre_toolset_versions[0] if spectre_toolset_versions else None
51 if spectre_toolset_version:
53 # spectre libs using construction variable
54 test.write('SConstruct', textwrap.dedent(
55 """
56 DefaultEnvironment(tools=[])
57 env = Environment(MSVC_VERSION={}, MSVC_SPECTRE_LIBS=True, tools=['msvc'])
58 lib_path = env['ENV']['LIB']
59 if '\\\\lib\\\\spectre\\\\' not in lib_path.lower():
60 raise RuntimeError("'spectre' not found in lib path " + lib_path)
61 """.format(repr(supported.msvc_version))
63 test.run(arguments='-Q -s', stdout='')
65 # spectre libs using script argument
66 test.write('SConstruct', textwrap.dedent(
67 """
68 DefaultEnvironment(tools=[])
69 env = Environment(MSVC_VERSION={}, MSVC_SCRIPT_ARGS='-vcvars_spectre_libs=spectre', tools=['msvc'])
70 lib_path = env['ENV']['LIB']
71 if '\\\\lib\\\\spectre\\\\' not in lib_path.lower():
72 raise RuntimeError("'spectre' not found in lib path " + lib_path)
73 """.format(repr(supported.msvc_version))
75 test.run(arguments='-Q -s', stdout='')
77 # error construction variable and script argument
78 test.write('SConstruct', textwrap.dedent(
79 """
80 DefaultEnvironment(tools=[])
81 env = Environment(MSVC_VERSION={}, MSVC_SPECTRE_LIBS=True, MSVC_SCRIPT_ARGS='-vcvars_spectre_libs=spectre', tools=['msvc'])
82 """.format(repr(supported.msvc_version))
84 test.run(arguments='-Q -s', status=2, stderr=None)
85 expect = "MSVCArgumentError: multiple spectre declarations: MSVC_SPECTRE_LIBS=True and MSVC_SCRIPT_ARGS='-vcvars_spectre_libs=spectre':"
86 test.must_contain_all(test.stderr(), expect)
88 else:
90 # spectre libs using construction variable
91 test.write('SConstruct', textwrap.dedent(
92 """
93 DefaultEnvironment(tools=[])
94 env = Environment(MSVC_VERSION={}, MSVC_SPECTRE_LIBS=True, tools=['msvc'])
95 """.format(repr(supported.msvc_version))
97 test.run(arguments='-Q -s', status=2, stderr=None)
98 if not test.stderr().strip().startswith('MSVCSpectreLibsNotFound: Spectre libraries not found'):
99 test.fail_test()
101 # spectre libs using script argument
102 test.write('SConstruct', textwrap.dedent(
104 DefaultEnvironment(tools=[])
105 env = Environment(MSVC_VERSION={}, MSVC_SCRIPT_ARGS='-vcvars_spectre_libs=spectre', MSVC_SCRIPTERROR_POLICY='error', tools=['msvc'])
106 """.format(repr(supported.msvc_version))
108 test.run(arguments='-Q -s', status=2, stderr=None)
109 if not test.stderr().strip().startswith('MSVCScriptExecutionError: vc script errors detected:'):
110 test.fail_test()
112 # spectre libs using construction variable
113 test.write('SConstruct', textwrap.dedent(
115 DefaultEnvironment(tools=[])
116 env = Environment(MSVC_VERSION={}, MSVC_SPECTRE_LIBS=False, tools=['msvc'])
117 lib_path = env['ENV']['LIB']
118 if '\\\\lib\\\\spectre\\\\' in lib_path.lower():
119 raise RuntimeError("'spectre' found in lib path " + lib_path)
120 """.format(repr(supported.msvc_version))
122 test.run(arguments='-Q -s', stdout='')
124 if LT_VS2017_versions:
125 # VS2015 and earlier for toolset argument error
127 for unsupported in LT_VS2017_versions:
129 # must be VS2017 or later
130 test.write('SConstruct', textwrap.dedent(
132 DefaultEnvironment(tools=[])
133 env = Environment(MSVC_VERSION={}, MSVC_SPECTRE_LIBS=True, tools=['msvc'])
134 """.format(repr(unsupported.msvc_version))
136 test.run(arguments='-Q -s', status=2, stderr=None)
137 if not test.stderr().strip().startswith('MSVCArgumentError: MSVC_SPECTRE_LIBS (True) constraint violation:'):
138 test.fail_test()
140 for disabled in (False, None):
142 # ignore
143 test.write('SConstruct', textwrap.dedent(
145 DefaultEnvironment(tools=[])
146 env = Environment(MSVC_VERSION={}, MSVC_SPECTRE_LIBS={}, tools=['msvc'])
147 """.format(repr(unsupported.msvc_version), disabled)
149 test.run(arguments='-Q -s', stdout='')
151 test.pass_test()
153 # Local Variables:
154 # tab-width:4
155 # indent-tabs-mode:nil
156 # End:
157 # vim: set expandtab tabstop=4 shiftwidth=4: