Skip to content

Commit ad1540f

Browse files
committed
[utils] Switch random scripts to shell.capture.
- This eliminates the last uses of `SwiftBuildSupport.check_output`.
1 parent e8b121b commit ad1540f

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

utils/SwiftBuildSupport.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import configparser as ConfigParser
1919

2020
import os
21-
import subprocess
2221
import sys
2322

2423
sys.path.append(os.path.join(os.path.dirname(__file__), 'swift_build_support'))
@@ -69,22 +68,6 @@ def _get_default_source_root():
6968
"SWIFT_BUILD_ROOT", os.path.join(SWIFT_SOURCE_ROOT, "build"))
7069

7170

72-
def check_output(args, print_command=False, verbose=False):
73-
if print_command:
74-
print(os.getcwd() + "$ " + shell.quote_command(args))
75-
sys.stdout.flush()
76-
try:
77-
return subprocess.check_output(args)
78-
except subprocess.CalledProcessError as e:
79-
diagnostics.fatal(
80-
"command terminated with a non-zero exit status " +
81-
str(e.returncode) + ", aborting")
82-
except OSError as e:
83-
diagnostics.fatal(
84-
"could not execute '" + shell.quote_command(args) +
85-
"': " + e.strerror)
86-
87-
8871
def _load_preset_files_impl(preset_file_names, substitutions={}):
8972
config = ConfigParser.SafeConfigParser(substitutions, allow_no_value=True)
9073
if config.read(preset_file_names) == []:

utils/profdata_merge/process.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@
1919
from multiprocessing import Process
2020

2121

22-
# hack to import SwiftBuildSupport and swift_build_support
23-
parent_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
24-
sys.path.append(parent_dir)
25-
support_dir = os.path.join(parent_dir, 'swift_build_support')
26-
sys.path.append(support_dir)
22+
# Allow importing swift_build_support.
23+
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
24+
'swift_build_support'))
2725
from swift_build_support import shell # noqa (E402)
2826
from swift_build_support.toolchain import host_toolchain # noqa (E402)
29-
from SwiftBuildSupport import check_output # noqa (E402)
3027

3128
toolchain = host_toolchain()
3229
LLVM_PROFDATA_PATH = toolchain.llvm_profdata
33-
_profdata_help = check_output([LLVM_PROFDATA_PATH, 'merge', '-help'])
30+
_profdata_help = shell.capture([LLVM_PROFDATA_PATH, 'merge', '-help'],
31+
print_command=False)
3432
LLVM_PROFDATA_SUPPORTS_SPARSE = 'sparse' in _profdata_help
3533

3634

utils/update-checkout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ sys.path.append(os.path.dirname(__file__))
1919

2020
from SwiftBuildSupport import (
2121
SWIFT_SOURCE_ROOT,
22-
check_output,
2322
) # noqa (E402 module level import not at top of file)
2423

2524
sys.path.append(os.path.join(os.path.dirname(__file__), 'swift_build_support'))
@@ -95,7 +94,8 @@ def update_working_copy(repo_path, branch):
9594
print("--- Updating '" + repo_path + "' ---")
9695
with shell.pushd(repo_path, dry_run=False, print_command=False):
9796
if branch:
98-
status = check_output(['git', 'status', '--porcelain'])
97+
status = shell.capture(['git', 'status', '--porcelain'],
98+
print_command=False)
9999
if status:
100100
print("Please, commit your changes.")
101101
print(status)

0 commit comments

Comments
 (0)