summaryrefslogtreecommitdiffstats
path: root/test/MSVC/MSVC_SDK_VERSION.py
blob: 4a3537b643393de38668e69446ca3cb263cd9857 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""
Test the MSVC_SDK_VERSION construction variable.
"""

import TestSCons

test = TestSCons.TestSCons()

test.skip_if_not_msvc()

import textwrap

from SCons.Tool.MSCommon.vc import get_installed_vcs_components
from SCons.Tool.MSCommon import msvc_sdk_versions
from SCons.Tool.MSCommon import msvc_toolset_versions

installed_versions = get_installed_vcs_components()

default_version = installed_versions[0]

GE_VS2015_versions = [v for v in installed_versions if v.msvc_vernum >= 14.0]
LT_VS2015_versions = [v for v in installed_versions if v.msvc_vernum < 14.0]

default_sdk_versions_uwp = msvc_sdk_versions(version=None, msvc_uwp_app=True)
default_sdk_versions_def = msvc_sdk_versions(version=None, msvc_uwp_app=False)

have_140 = any([v.msvc_verstr == '14.0' for v in GE_VS2015_versions])

def version_major(version):
    components = version.split('.')
    if len(components) >= 2:
        return components[0] + '.' + components[1][0]
    if len(components) == 1:
        return components[0] + '.0'
    return version

def version_major_list(version_list):
    versions = []
    seen_major = set()
    for version in version_list:
        major = version_major(version)
        if major in seen_major:
            continue
        versions.append(version)
        seen_major.add(major)
    return versions

if GE_VS2015_versions:

    for supported in GE_VS2015_versions:

        sdk_versions_uwp = msvc_sdk_versions(version=supported.msvc_version, msvc_uwp_app=True)
        sdk_versions_def = msvc_sdk_versions(version=supported.msvc_version, msvc_uwp_app=False)

        # find sdk version for each major SDK
        sdk_versions = version_major_list(sdk_versions_def)

        for sdk_version in sdk_versions:

            # sdk version construction variable
            test.write('SConstruct', textwrap.dedent(
                """
                DefaultEnvironment(tools=[])
                env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION={}, tools=['msvc'])
                """.format(repr(supported.msvc_version), repr(sdk_version))
            ))
            test.run(arguments='-Q -s', stdout='')

            # sdk version script argument
            test.write('SConstruct', textwrap.dedent(
                """
                DefaultEnvironment(tools=[])
                env = Environment(MSVC_VERSION={}, MSVC_SCRIPT_ARGS={}, tools=['msvc'])
                """.format(repr(supported.msvc_version), repr(sdk_version))
            ))
            test.run(arguments='-Q -s', stdout='')

            # sdk version construction variable and script argument
            test.write('SConstruct', textwrap.dedent(
                """
                DefaultEnvironment(tools=[])
                env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION={}, MSVC_SCRIPT_ARGS={}, tools=['msvc'])
                """.format(repr(supported.msvc_version), repr(sdk_version), repr(sdk_version))
            ))
            test.run(arguments='-Q -s', status=2, stderr=None)
            expect = "MSVCArgumentError: multiple sdk version declarations: MSVC_SDK_VERSION={} and MSVC_SCRIPT_ARGS={}:".format(
                repr(sdk_version), repr(sdk_version)
            )
            test.must_contain_all(test.stderr(), expect)

        # sdk version is not supported
        invalid_sdk_version = '9.1'
        test.write('SConstruct', textwrap.dedent(
            """
            DefaultEnvironment(tools=[])
            env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION={}, tools=['msvc'])
            """.format(repr(supported.msvc_version), repr(invalid_sdk_version))
        ))
        test.run(arguments='-Q -s', status=2, stderr=None)
        expect = "MSVCArgumentError: MSVC_SDK_VERSION ({}) is not supported:".format(
            repr(invalid_sdk_version)
        )
        test.must_contain_all(test.stderr(), expect)

        # sdk version not found
        missing_sdk_version = '10.0.12345.6'
        test.write('SConstruct', textwrap.dedent(
            """
            DefaultEnvironment(tools=[])
            env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION={}, tools=['msvc'])
            """.format(repr(supported.msvc_version), repr(missing_sdk_version))
        ))
        test.run(arguments='-Q -s', status=2, stderr=None)
        expect = "MSVCSDKVersionNotFound: MSVC_SDK_VERSION {} not found for platform type 'Desktop':".format(
            repr(missing_sdk_version)
        )
        test.must_contain_all(test.stderr(), expect)

        # platform contraints: 8.1 and UWP
        if '8.1' in sdk_versions:

            if supported.msvc_vernum > 14.0:

                toolset_full_versions = msvc_toolset_versions(supported.msvc_version, full=True, sxs=False)
                toolset_versions = version_major_list(toolset_full_versions)

                # toolset msvc_version != current msvc_version and toolset msvc_version != 14.0
                toolset_candidates = [v for v in toolset_versions if version_major(v) not in (supported.msvc_verstr, '14.0')]
                toolset_version = toolset_candidates[0] if toolset_candidates else None

                # sdk version 8.1, UWP, and msvc_verson > VS2015
                test.write('SConstruct', textwrap.dedent(
                    """
                    DefaultEnvironment(tools=[])
                    env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION='8.1', MSVC_UWP_APP=True, tools=['msvc'])
                    """.format(repr(supported.msvc_version))
                ))
                test.run(arguments='-Q -s', status=2, stderr=None)
                expect = "MSVCArgumentError: MSVC_SDK_VERSION ('8.1') and platform type ('UWP') constraint violation: MSVC_VERSION {} > '14.0' VS2015:".format(
                    repr(supported.msvc_version)
                )
                test.must_contain_all(test.stderr(), expect)

                if toolset_version:

                    # sdk version 8.1, UWP, and msvc_toolset_verson > VS2015
                    test.write('SConstruct', textwrap.dedent(
                        """
                        DefaultEnvironment(tools=[])
                        env = Environment(MSVC_VERSION={}, MSVC_TOOLSET_VERSION={}, MSVC_SDK_VERSION='8.1', MSVC_UWP_APP=True, tools=['msvc'])
                        """.format(repr(supported.msvc_version), repr(toolset_version))
                    ))
                    test.run(arguments='-Q -s', status=2, stderr=None)
                    expect = "MSVCArgumentError: MSVC_SDK_VERSION ('8.1') and platform type ('UWP') constraint violation: toolset version {} > '14.0' VS2015:".format(
                        repr(toolset_version)
                    )
                    test.must_contain_all(test.stderr(), expect)

                if have_140:

                    # sdk version 8.1, UWP, and msvc_toolset_version > VS2015
                    test.write('SConstruct', textwrap.dedent(
                        """
                        DefaultEnvironment(tools=[])
                        env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION='8.1', MSVC_TOOLSET_VERSION='14.0', MSVC_UWP_APP=True, tools=['msvc'])
                        """.format(repr(supported.msvc_version))
                    ))
                    test.run(arguments='-Q -s', stdout='')

            elif supported.msvc_vernum == 14.0:

                # sdk version 8.1, UWP, and msvc_verson == VS2015
                test.write('SConstruct', textwrap.dedent(
                    """
                    DefaultEnvironment(tools=[])
                    env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION='8.1', MSVC_UWP_APP=True, tools=['msvc'])
                    """.format(repr(supported.msvc_version))
                ))
                test.run(arguments='-Q -s', stdout='')

if LT_VS2015_versions:

    for unsupported in LT_VS2015_versions:
        # must be VS2015 or later

        sdk_version = default_sdk_versions_def[0] if default_sdk_versions_def else '8.1'

        test.write('SConstruct', textwrap.dedent(
            """
            DefaultEnvironment(tools=[])
            env = Environment(MSVC_VERSION={}, MSVC_SDK_VERSION={}, tools=['msvc'])
            """.format(repr(unsupported.msvc_version), repr(sdk_version))
        ))
        test.run(arguments='-Q -s', status=2, stderr=None)
        expect = "MSVCArgumentError: MSVC_SDK_VERSION ({}) constraint violation: MSVC_VERSION {} < '14.0' VS2015:".format(
            repr(sdk_version), repr(unsupported.msvc_version)
        )
        test.must_contain_all(test.stderr(), expect)

        test.write('SConstruct', textwrap.dedent(
            """
            DefaultEnvironment(tools=[])
            env = Environment(MSVC_VERSION={}, MSVC_SCRIPT_ARGS={}, tools=['msvc'])
            """.format(repr(unsupported.msvc_version), repr(sdk_version))
        ))
        test.run(arguments='-Q -s', status=2, stderr=None)
        expect = "MSVCArgumentError: MSVC_SCRIPT_ARGS ({}) constraint violation: MSVC_VERSION {} < '14.0' VS2015:".format(
            repr(sdk_version), repr(unsupported.msvc_version)
        )
        test.must_contain_all(test.stderr(), expect)

test.pass_test()