From 3d06deefe48cba5530bc98a35cf93b63bc3ef37a Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 1 Jun 2016 22:42:38 -0700 Subject: [PATCH] [utils] Inline `caffeinate` logic into sole client. - This eliminates the last client of `SwiftBuildSupport.check_call`, which is now replaced by `swift_build_support.shell.call`. - Part of SR-237. --- utils/SwiftBuildSupport.py | 23 ----------------------- utils/build-script | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/utils/SwiftBuildSupport.py b/utils/SwiftBuildSupport.py index b144b710e33..b9b54a56f83 100644 --- a/utils/SwiftBuildSupport.py +++ b/utils/SwiftBuildSupport.py @@ -18,7 +18,6 @@ except ImportError: import configparser as ConfigParser import os -import platform import subprocess import sys @@ -70,28 +69,6 @@ SWIFT_BUILD_ROOT = os.environ.get( "SWIFT_BUILD_ROOT", os.path.join(SWIFT_SOURCE_ROOT, "build")) -def check_call(args, print_command=False, verbose=False, disable_sleep=False): - if disable_sleep: - if platform.system() == 'Darwin': - # Don't mutate the caller's copy of the arguments. - args = list(args) - args.insert(0, "caffeinate") - - if print_command: - print(os.getcwd() + "$ " + shell.quote_command(args)) - sys.stdout.flush() - try: - return subprocess.check_call(args) - except subprocess.CalledProcessError as e: - diagnostics.fatal( - "command terminated with a non-zero exit status " + - str(e.returncode) + ", aborting") - except OSError as e: - diagnostics.fatal( - "could not execute '" + shell.quote_command(args) + - "': " + e.strerror) - - def check_output(args, print_command=False, verbose=False): if print_command: print(os.getcwd() + "$ " + shell.quote_command(args)) diff --git a/utils/build-script b/utils/build-script index c4a84a4210a..cdac3727640 100755 --- a/utils/build-script +++ b/utils/build-script @@ -28,7 +28,6 @@ from SwiftBuildSupport import ( HOME, SWIFT_BUILD_ROOT, SWIFT_SOURCE_ROOT, - check_call, get_all_preset_names, get_preset_options, ) # noqa (E402 module level import not at top of file) @@ -51,6 +50,21 @@ from swift_build_support.workspace import Workspace # noqa(E402) from swift_build_support.workspace import compute_build_subdir # noqa(E402) +def call_without_sleeping(command, dry_run=False): + """ + Execute a command during which system sleep is disabled. + + By default, this ignores the state of the `shell.dry_run` flag. + """ + + # Disable system sleep, if possible. + if platform.system() == 'Darwin': + # Don't mutate the caller's copy of the arguments. + command = ["caffeinate"] + list(command) + + shell.call(command, dry_run=dry_run, print_command=False) + + # Main entry point for the preset mode. def main_preset(): parser = argparse.ArgumentParser( @@ -124,7 +138,7 @@ def main_preset(): "using preset '" + args.preset + "', which expands to \n\n" + shell.quote_command(build_script_args) + "\n") - check_call(build_script_args, disable_sleep=True) + call_without_sleeping(build_script_args) return 0 @@ -1429,8 +1443,7 @@ details of the setups of other systems or automated environments.""") if args.dry_run: build_script_impl_args += ["--dry-run"] - check_call([build_script_impl] + build_script_impl_args, - disable_sleep=True) + call_without_sleeping([build_script_impl] + build_script_impl_args) if args.symbols_package: print('--- Creating symbols package ---')