Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion utils/swift_build_support/swift_build_support/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ def print_xcodebuild_versions(file=sys.stdout):
"""
version = shell.capture(
['xcodebuild', '-version'], dry_run=False, echo=False).rstrip()
# Allow non-zero exit codes. Under certain obscure circumstances
# xcodebuild can exit with an non-zero exit code even when the SDK is
# usable.
sdks = shell.capture(
['xcodebuild', '-version', '-sdk'], dry_run=False, echo=False).rstrip()
['xcodebuild', '-version', '-sdk'], dry_run=False, echo=False,
allow_non_zero_exit=True).rstrip()
fmt = """\
{version}

Expand Down
4 changes: 3 additions & 1 deletion utils/swift_build_support/swift_build_support/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def call(command, stderr=None, env=None, dry_run=None, echo=True):


def capture(command, stderr=None, env=None, dry_run=None, echo=True,
optional=False):
optional=False, allow_non_zero_exit=False):
"""
capture(command, ...) -> str

Expand All @@ -114,6 +114,8 @@ def capture(command, stderr=None, env=None, dry_run=None, echo=True,
# Coerce to `str` hack. not py3 `byte`, not py2 `unicode`.
return str(out.decode())
except subprocess.CalledProcessError as e:
if allow_non_zero_exit:
return e.output
if optional:
return None
diagnostics.fatal(
Expand Down
4 changes: 4 additions & 0 deletions utils/swift_build_support/tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def test_capture(self):

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

self.assertEqual(
shell.capture(["sh", "-c", "echo foo && false"],
allow_non_zero_exit=True), "foo\n")

with self.assertRaises(SystemExit):
shell.capture(["**not-a-command**"], optional=True)

Expand Down