Skip to content

Commit 3ce7899

Browse files
committed
Add check for Xcode version compatibility
This adds a check validating the current Xcode version is supported for building the current sha. This makes us fail fast in the case that you've selected too new or too old of an Xcode version that might otherwise fail very late in the build process. You can also set SKIP_XCODE_VERSION_CHECK to anything to skip this.
1 parent d35cb3c commit 3ce7899

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

utils/build-script

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ from swift_build_support.swift_build_support.toolchain import host_toolchain
5353
# TODO: Remove this constant, it's really not helpful.
5454
HOME = os.environ.get("HOME", "/")
5555

56+
_SUPPORTED_XCODE_BUILDS = (
57+
"12A8169g", # 12.0b3
58+
"12A8179i", # 12.0b4
59+
"12A8189h", # 12.0b5
60+
"12A8189n", # 12.0b6
61+
"12A7208", # 12.0GM1
62+
"12A7209", # 12.0GM2
63+
"12A7300", # 12.0.1
64+
)
5665

5766
# -----------------------------------------------------------------------------
5867
# Helpers
@@ -147,6 +156,22 @@ def print_xcodebuild_versions(file=sys.stdout):
147156
print(fmt.format(version=version, sdks=sdks), file=file)
148157
file.flush()
149158

159+
def validate_xcode_compatibility():
160+
if sys.platform != 'darwin':
161+
return
162+
163+
if os.getenv("SKIP_XCODE_VERSION_CHECK"):
164+
print("note: skipping Xcode version check")
165+
return
166+
167+
version = shell.capture(
168+
['xcodebuild', '-version'], dry_run=False, echo=False).strip()
169+
if not version.endswith(_SUPPORTED_XCODE_BUILDS):
170+
raise SystemExit(
171+
"error: using unsupported Xcode version:\n\n{}\n\nInstall one of: {}".format(
172+
version, ", ".join(_SUPPORTED_XCODE_BUILDS)
173+
)
174+
)
150175

151176
def tar(source, destination):
152177
"""
@@ -1335,6 +1360,8 @@ def main():
13351360
"\' does not exist " +
13361361
"(forgot to set $SWIFT_SOURCE_ROOT environment variable?)")
13371362

1363+
validate_xcode_compatibility()
1364+
13381365
# Determine if we are invoked in the preset mode and dispatch accordingly.
13391366
if any([(opt.startswith("--preset") or opt == "--show-presets")
13401367
for opt in sys.argv[1:]]):

0 commit comments

Comments
 (0)