Skip to content

Commit 01ad840

Browse files
committed
Merge pull request #2241 from rintaro/build-script-dryrun
[build-script] Introduce --dry-run mode
2 parents e3eb030 + 552590e commit 01ad840

File tree

6 files changed

+195
-164
lines changed

6 files changed

+195
-164
lines changed

utils/SwiftBuildSupport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def _get_default_source_root():
6767

6868
def print_with_argv0(message):
6969
print(sys.argv[0] + ": " + message)
70+
sys.stdout.flush()
7071

7172

7273
def quote_shell_command(args):
@@ -82,6 +83,7 @@ def check_call(args, print_command=False, verbose=False, disable_sleep=False):
8283

8384
if print_command:
8485
print(os.getcwd() + "$ " + quote_shell_command(args))
86+
sys.stdout.flush()
8587
try:
8688
return subprocess.check_call(args)
8789
except subprocess.CalledProcessError as e:
@@ -101,6 +103,7 @@ def check_call(args, print_command=False, verbose=False, disable_sleep=False):
101103
def check_output(args, print_command=False, verbose=False):
102104
if print_command:
103105
print(os.getcwd() + "$ " + quote_shell_command(args))
106+
sys.stdout.flush()
104107
try:
105108
return subprocess.check_output(args)
106109
except subprocess.CalledProcessError as e:

utils/build-script

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def main_preset():
5757
parser = argparse.ArgumentParser(
5858
formatter_class=argparse.RawDescriptionHelpFormatter,
5959
description="""Builds Swift using a preset.""")
60+
parser.add_argument(
61+
"-n", "--dry-run",
62+
help="print the commands that would be executed, but do not execute "
63+
"them",
64+
action="store_true",
65+
default=False)
6066
parser.add_argument(
6167
"--preset-file",
6268
help="load presets from the specified file",
@@ -110,6 +116,8 @@ def main_preset():
110116
args.preset_substitutions, args.preset_file_names, args.preset)
111117

112118
build_script_args = [sys.argv[0]]
119+
if args.dry_run:
120+
build_script_args += ["--dry-run"]
113121
build_script_args += preset_args
114122
if args.distcc:
115123
build_script_args += ["--distcc"]
@@ -306,6 +314,13 @@ It is a policy decision aimed at making the builds uniform across all
306314
environments and easily reproducible by engineers who are not familiar with the
307315
details of the setups of other systems or automated environments.""")
308316

317+
parser.add_argument(
318+
"-n", "--dry-run",
319+
help="print the commands that would be executed, but do not execute "
320+
"them",
321+
action="store_true",
322+
default=False)
323+
309324
targets_group = parser.add_argument_group(
310325
title="Host and cross-compilation targets")
311326
targets_group.add_argument(
@@ -968,6 +983,8 @@ details of the setups of other systems or automated environments.""")
968983
if '--check-args-only' in args.build_script_impl_args:
969984
return 0
970985

986+
shell.dry_run = args.dry_run
987+
971988
# Prepare and validate toolchain
972989
toolchain = host_toolchain(xcrun_toolchain=args.darwin_xcrun_toolchain)
973990

@@ -1419,6 +1436,9 @@ details of the setups of other systems or automated environments.""")
14191436

14201437
build_script_impl_args += args.build_script_impl_args
14211438

1439+
if args.dry_run:
1440+
build_script_impl_args += ["--dry-run"]
1441+
14221442
check_call([build_script_impl] + build_script_impl_args,
14231443
disable_sleep=True)
14241444

0 commit comments

Comments
 (0)