Skip to content

Commit af7e2da

Browse files
committed
Replace —print-build-dir with --dump-config
The --dump-config option prints a recursive JSON dump of the BuildScriptInvocation object’s properties, which gives access to essentially all of the knowledge build-script has about the build before it starts performing it. This makes the output more flexible and extensible without severely convoluting the implementation, but doesn’t really give us a stable representation of that data.
1 parent b388346 commit af7e2da

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

utils/build-script

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from __future__ import print_function
1313

1414
import argparse
15+
import json
1516
import os
1617
import pipes
1718
import platform
@@ -56,6 +57,15 @@ def exit_rejecting_arguments(message, parser=None):
5657
sys.exit(2) # 2 is the same as `argparse` error exit code.
5758

5859

60+
class JSONDumper(json.JSONEncoder):
61+
def __init__(self, *args, **kwargs):
62+
json.JSONEncoder.__init__(self, indent=2, separators=(',', ': '),
63+
*args, **kwargs)
64+
65+
def default(self, o):
66+
return vars(o)
67+
68+
5969
class HostSpecificConfiguration(object):
6070

6171
"""Configuration information for an individual host."""
@@ -1093,8 +1103,9 @@ def main_preset():
10931103
"--build-dir",
10941104
help="specify the directory where build artifact should be stored")
10951105
parser.add_argument(
1096-
"--print-build-dir",
1097-
help="Print the build directory and exit without building",
1106+
"--dump-config",
1107+
help="instead of building, write JSON to stdout containing "
1108+
"various values used to build in this configuration",
10981109
action="store_true",
10991110
default=False)
11001111
args = parser.parse_args()
@@ -1146,8 +1157,8 @@ def main_preset():
11461157
build_script_args = [sys.argv[0]]
11471158
if args.dry_run:
11481159
build_script_args += ["--dry-run"]
1149-
if args.print_build_dir:
1150-
build_script_args += ["--print-build-dir"]
1160+
if args.dump_config:
1161+
build_script_args += ["--dump-config"]
11511162

11521163
build_script_args += preset_args
11531164
if args.distcc:
@@ -1233,8 +1244,8 @@ def main_normal():
12331244
if args.show_sdks:
12341245
debug.print_xcodebuild_versions()
12351246

1236-
if args.print_build_dir:
1237-
print(invocation.workspace.build_root)
1247+
if args.dump_config:
1248+
print(JSONDumper().encode(invocation))
12381249
return 0
12391250

12401251
# Clean build directory if requested.

utils/build_swift/driver_arguments.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ def create_argument_parser():
287287
option(['-n', '--dry-run'], store_true,
288288
help='print the commands that would be executed, but do not '
289289
'execute them')
290+
option('--dump-config', toggle_true,
291+
help='instead of building, write JSON to stdout containing '
292+
'various values used to build in this configuration')
293+
290294
option('--legacy-impl', store_true('legacy_impl'),
291295
help='use legacy implementation')
292296

@@ -333,8 +337,6 @@ def create_argument_parser():
333337
metavar='PATH',
334338
help='name of the directory under $SWIFT_BUILD_ROOT where the '
335339
'build products will be placed')
336-
option('--print-build-dir', toggle_true,
337-
help='print the build directory and exit without building')
338340
option('--install-prefix', store_path,
339341
default=targets.install_prefix(),
340342
help='The installation prefix. This is where built Swift products '

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
'tsan_libdispatch_test': False,
162162
'long_test': False,
163163
'lto_type': None,
164-
'print_build_dir': False,
164+
'dump_config': False,
165165
'show_sdks': False,
166166
'skip_build': False,
167167
'stdlib_deployment_targets': None,
@@ -403,7 +403,7 @@ class IgnoreOption(_BaseOption):
403403
SetTrueOption('--benchmark'),
404404
SetTrueOption('--clean'),
405405
SetTrueOption('--dry-run'),
406-
SetTrueOption('--print-build-dir'),
406+
SetTrueOption('--dump-config'),
407407
SetTrueOption('--disable-guaranteed-normal-arguments'),
408408
SetTrueOption('--enable-stdlibcore-exclusivity-checking'),
409409
SetTrueOption('--force-optimized-typechecker'),

0 commit comments

Comments
 (0)