[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.
This commit is contained in:
Daniel Dunbar
2016-06-01 22:42:38 -07:00
parent 87a17001cc
commit 3d06deefe4
2 changed files with 17 additions and 27 deletions

View File

@@ -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))

View File

@@ -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 ---')