@@ -53,10 +53,16 @@ from swift_build_support.swift_build_support.toolchain import host_toolchain
5353# TODO: Remove this constant, it's really not helpful.
5454HOME = os .environ .get ("HOME" , "/" )
5555
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+ ]
5661
5762# -----------------------------------------------------------------------------
5863# Helpers
5964
65+
6066def print_note (message , stream = sys .stdout ):
6167 """Writes a diagnostic message to the given stream. By default this
6268 function outputs to stdout.
@@ -148,6 +154,30 @@ def print_xcodebuild_versions(file=sys.stdout):
148154 file .flush ()
149155
150156
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+
151181def tar (source , destination ):
152182 """
153183 Create a gzip archive of the file at 'source' at the given
@@ -1335,6 +1365,8 @@ def main():
13351365 "\' does not exist " +
13361366 "(forgot to set $SWIFT_SOURCE_ROOT environment variable?)" )
13371367
1368+ validate_xcode_compatibility ()
1369+
13381370 # Determine if we are invoked in the preset mode and dispatch accordingly.
13391371 if any ([(opt .startswith ("--preset" ) or opt == "--show-presets" )
13401372 for opt in sys .argv [1 :]]):
0 commit comments