Skip to content

Add check for Xcode version compatibility #34227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ from swift_build_support.swift_build_support.toolchain import host_toolchain
# TODO: Remove this constant, it's really not helpful.
HOME = os.environ.get("HOME", "/")

# These versions are community sourced. At any given time only the Xcode
# version used by Swift CI is officially supported. See ci.swift.org
_SUPPORTED_XCODE_BUILDS = [
("12.2 beta 3", "12B5035g"),
]

# -----------------------------------------------------------------------------
# Helpers


def print_note(message, stream=sys.stdout):
"""Writes a diagnostic message to the given stream. By default this
function outputs to stdout.
Expand Down Expand Up @@ -148,6 +154,30 @@ def print_xcodebuild_versions(file=sys.stdout):
file.flush()


def validate_xcode_compatibility():
if sys.platform != 'darwin':
return

if os.getenv("SKIP_XCODE_VERSION_CHECK"):
print("note: skipping Xcode version check")
return

version = shell.capture(
['xcodebuild', '-version'], dry_run=False, echo=False).strip()

valid_build_numbers = tuple(x[1] for x in _SUPPORTED_XCODE_BUILDS)
if not version.endswith(valid_build_numbers):
valid_versions_string = "\n".join(
"{} ({})".format(*x) for x in _SUPPORTED_XCODE_BUILDS)
raise SystemExit(
"error: using unsupported Xcode version:\n\n{}\n\n"
"Install one of:\n{}\n\n"
"Or set 'SKIP_XCODE_VERSION_CHECK=1' in the environment".format(
version, valid_versions_string
)
)


def tar(source, destination):
"""
Create a gzip archive of the file at 'source' at the given
Expand Down Expand Up @@ -1335,6 +1365,8 @@ def main():
"\' does not exist " +
"(forgot to set $SWIFT_SOURCE_ROOT environment variable?)")

validate_xcode_compatibility()

# Determine if we are invoked in the preset mode and dispatch accordingly.
if any([(opt.startswith("--preset") or opt == "--show-presets")
for opt in sys.argv[1:]]):
Expand Down