Skip to content

Commit 07d0a62

Browse files
committed
Merge pull request #2877 from apple/build-script-allow-non-zero-xcodebuild-sdk-version
build-script: allow non-zero exit codes from 'xcodebuild -version -sdk'
2 parents 8f3031d + c55e89f commit 07d0a62

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

utils/swift_build_support/swift_build_support/debug.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ def print_xcodebuild_versions(file=sys.stdout):
2929
"""
3030
version = shell.capture(
3131
['xcodebuild', '-version'], dry_run=False, echo=False).rstrip()
32+
# Allow non-zero exit codes. Under certain obscure circumstances
33+
# xcodebuild can exit with an non-zero exit code even when the SDK is
34+
# usable.
3235
sdks = shell.capture(
33-
['xcodebuild', '-version', '-sdk'], dry_run=False, echo=False).rstrip()
36+
['xcodebuild', '-version', '-sdk'], dry_run=False, echo=False,
37+
allow_non_zero_exit=True).rstrip()
3438
fmt = """\
3539
{version}
3640

utils/swift_build_support/swift_build_support/shell.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def call(command, stderr=None, env=None, dry_run=None, echo=True):
9292

9393

9494
def capture(command, stderr=None, env=None, dry_run=None, echo=True,
95-
optional=False):
95+
optional=False, allow_non_zero_exit=False):
9696
"""
9797
capture(command, ...) -> str
9898
@@ -114,6 +114,8 @@ def capture(command, stderr=None, env=None, dry_run=None, echo=True,
114114
# Coerce to `str` hack. not py3 `byte`, not py2 `unicode`.
115115
return str(out.decode())
116116
except subprocess.CalledProcessError as e:
117+
if allow_non_zero_exit:
118+
return e.output
117119
if optional:
118120
return None
119121
diagnostics.fatal(

utils/swift_build_support/tests/test_shell.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def test_capture(self):
7171

7272
self.assertIsNone(shell.capture(["false"], optional=True))
7373

74+
self.assertEqual(
75+
shell.capture(["sh", "-c", "echo foo && false"],
76+
allow_non_zero_exit=True), "foo\n")
77+
7478
with self.assertRaises(SystemExit):
7579
shell.capture(["**not-a-command**"], optional=True)
7680

0 commit comments

Comments
 (0)