Skip to content

Commit 3d06dee

Browse files
committed
[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.
1 parent 87a1700 commit 3d06dee

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

Diff for: utils/SwiftBuildSupport.py

-23
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import configparser as ConfigParser
1919

2020
import os
21-
import platform
2221
import subprocess
2322
import sys
2423

@@ -70,28 +69,6 @@ def _get_default_source_root():
7069
"SWIFT_BUILD_ROOT", os.path.join(SWIFT_SOURCE_ROOT, "build"))
7170

7271

73-
def check_call(args, print_command=False, verbose=False, disable_sleep=False):
74-
if disable_sleep:
75-
if platform.system() == 'Darwin':
76-
# Don't mutate the caller's copy of the arguments.
77-
args = list(args)
78-
args.insert(0, "caffeinate")
79-
80-
if print_command:
81-
print(os.getcwd() + "$ " + shell.quote_command(args))
82-
sys.stdout.flush()
83-
try:
84-
return subprocess.check_call(args)
85-
except subprocess.CalledProcessError as e:
86-
diagnostics.fatal(
87-
"command terminated with a non-zero exit status " +
88-
str(e.returncode) + ", aborting")
89-
except OSError as e:
90-
diagnostics.fatal(
91-
"could not execute '" + shell.quote_command(args) +
92-
"': " + e.strerror)
93-
94-
9572
def check_output(args, print_command=False, verbose=False):
9673
if print_command:
9774
print(os.getcwd() + "$ " + shell.quote_command(args))

Diff for: utils/build-script

+17-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ from SwiftBuildSupport import (
2828
HOME,
2929
SWIFT_BUILD_ROOT,
3030
SWIFT_SOURCE_ROOT,
31-
check_call,
3231
get_all_preset_names,
3332
get_preset_options,
3433
) # noqa (E402 module level import not at top of file)
@@ -51,6 +50,21 @@ from swift_build_support.workspace import Workspace # noqa(E402)
5150
from swift_build_support.workspace import compute_build_subdir # noqa(E402)
5251

5352

53+
def call_without_sleeping(command, dry_run=False):
54+
"""
55+
Execute a command during which system sleep is disabled.
56+
57+
By default, this ignores the state of the `shell.dry_run` flag.
58+
"""
59+
60+
# Disable system sleep, if possible.
61+
if platform.system() == 'Darwin':
62+
# Don't mutate the caller's copy of the arguments.
63+
command = ["caffeinate"] + list(command)
64+
65+
shell.call(command, dry_run=dry_run, print_command=False)
66+
67+
5468
# Main entry point for the preset mode.
5569
def main_preset():
5670
parser = argparse.ArgumentParser(
@@ -124,7 +138,7 @@ def main_preset():
124138
"using preset '" + args.preset + "', which expands to \n\n" +
125139
shell.quote_command(build_script_args) + "\n")
126140

127-
check_call(build_script_args, disable_sleep=True)
141+
call_without_sleeping(build_script_args)
128142

129143
return 0
130144

@@ -1429,8 +1443,7 @@ details of the setups of other systems or automated environments.""")
14291443
if args.dry_run:
14301444
build_script_impl_args += ["--dry-run"]
14311445

1432-
check_call([build_script_impl] + build_script_impl_args,
1433-
disable_sleep=True)
1446+
call_without_sleeping([build_script_impl] + build_script_impl_args)
14341447

14351448
if args.symbols_package:
14361449
print('--- Creating symbols package ---')

0 commit comments

Comments
 (0)