@@ -53,10 +53,16 @@ from swift_build_support.swift_build_support.toolchain import host_toolchain
53
53
# TODO: Remove this constant, it's really not helpful.
54
54
HOME = os .environ .get ("HOME" , "/" )
55
55
56
+ # These versions are community sourced. At any given time only the Xcode
57
+ # version used by Swift CI is officially supported. See ci.swift.org
58
+ _SUPPORTED_XCODE_BUILDS = [
59
+ ("12.2 beta 3" , "12B5035g" ),
60
+ ]
56
61
57
62
# -----------------------------------------------------------------------------
58
63
# Helpers
59
64
65
+
60
66
def print_note (message , stream = sys .stdout ):
61
67
"""Writes a diagnostic message to the given stream. By default this
62
68
function outputs to stdout.
@@ -148,6 +154,30 @@ def print_xcodebuild_versions(file=sys.stdout):
148
154
file .flush ()
149
155
150
156
157
+ def validate_xcode_compatibility ():
158
+ if sys .platform != 'darwin' :
159
+ return
160
+
161
+ if os .getenv ("SKIP_XCODE_VERSION_CHECK" ):
162
+ print ("note: skipping Xcode version check" )
163
+ return
164
+
165
+ version = shell .capture (
166
+ ['xcodebuild' , '-version' ], dry_run = False , echo = False ).strip ()
167
+
168
+ valid_build_numbers = tuple (x [1 ] for x in _SUPPORTED_XCODE_BUILDS )
169
+ if not version .endswith (valid_build_numbers ):
170
+ valid_versions_string = "\n " .join (
171
+ "{} ({})" .format (* x ) for x in _SUPPORTED_XCODE_BUILDS )
172
+ raise SystemExit (
173
+ "error: using unsupported Xcode version:\n \n {}\n \n "
174
+ "Install one of:\n {}\n \n "
175
+ "Or set 'SKIP_XCODE_VERSION_CHECK=1' in the environment" .format (
176
+ version , valid_versions_string
177
+ )
178
+ )
179
+
180
+
151
181
def tar (source , destination ):
152
182
"""
153
183
Create a gzip archive of the file at 'source' at the given
@@ -1335,6 +1365,8 @@ def main():
1335
1365
"\' does not exist " +
1336
1366
"(forgot to set $SWIFT_SOURCE_ROOT environment variable?)" )
1337
1367
1368
+ validate_xcode_compatibility ()
1369
+
1338
1370
# Determine if we are invoked in the preset mode and dispatch accordingly.
1339
1371
if any ([(opt .startswith ("--preset" ) or opt == "--show-presets" )
1340
1372
for opt in sys .argv [1 :]]):
0 commit comments