Skip to content

[build-script] Introduce --dry-run mode #2241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions utils/SwiftBuildSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def _get_default_source_root():

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


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

if print_command:
print(os.getcwd() + "$ " + quote_shell_command(args))
sys.stdout.flush()
try:
return subprocess.check_call(args)
except subprocess.CalledProcessError as e:
Expand All @@ -101,6 +103,7 @@ def check_call(args, print_command=False, verbose=False, disable_sleep=False):
def check_output(args, print_command=False, verbose=False):
if print_command:
print(os.getcwd() + "$ " + quote_shell_command(args))
sys.stdout.flush()
try:
return subprocess.check_output(args)
except subprocess.CalledProcessError as e:
Expand Down
20 changes: 20 additions & 0 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def main_preset():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""Builds Swift using a preset.""")
parser.add_argument(
"-n", "--dry-run",
help="print the commands that would be executed, but do not execute "
"them",
action="store_true",
default=False)
parser.add_argument(
"--preset-file",
help="load presets from the specified file",
Expand Down Expand Up @@ -110,6 +116,8 @@ def main_preset():
args.preset_substitutions, args.preset_file_names, args.preset)

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

parser.add_argument(
"-n", "--dry-run",
help="print the commands that would be executed, but do not execute "
"them",
action="store_true",
default=False)

targets_group = parser.add_argument_group(
title="Host and cross-compilation targets")
targets_group.add_argument(
Expand Down Expand Up @@ -968,6 +983,8 @@ details of the setups of other systems or automated environments.""")
if '--check-args-only' in args.build_script_impl_args:
return 0

shell.dry_run = args.dry_run

# Prepare and validate toolchain
toolchain = host_toolchain(xcrun_toolchain=args.darwin_xcrun_toolchain)

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

build_script_impl_args += args.build_script_impl_args

if args.dry_run:
build_script_impl_args += ["--dry-run"]

check_call([build_script_impl] + build_script_impl_args,
disable_sleep=True)

Expand Down
Loading