Skip to content

Commit 741ec66

Browse files
authored
Merge pull request swiftlang#134 from apple/xcodebuild-flags
Add support for adding additional xcodebuild flags at runner invocation
2 parents 054945b + a4a5e57 commit 741ec66

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

project_future.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import json
2424
import time
2525
import argparse
26+
import shlex
2627

2728
import common
2829

@@ -68,13 +69,14 @@ def test(self, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr,
6869
class XcodeTarget(ProjectTarget):
6970
"""An Xcode workspace scheme."""
7071

71-
def __init__(self, project, target, destination, sdk, build_settings,
72-
is_workspace, has_scheme):
72+
def __init__(self, swiftc, project, target, destination, sdk,
73+
added_xcodebuild_flags, is_workspace, has_scheme):
74+
self._swiftc = swiftc
7375
self._project = project
7476
self._target = target
7577
self._destination = destination
7678
self._sdk = sdk
77-
self._build_settings = build_settings
79+
self._added_xcodebuild_flags = added_xcodebuild_flags
7880
self._is_workspace = is_workspace
7981
self._has_scheme = has_scheme
8082

@@ -116,11 +118,7 @@ def get_build_command(self, incremental=False):
116118
'INDEX_ENABLE_DATA_STORE=NO',
117119
'GCC_TREAT_WARNINGS_AS_ERRORS=NO',
118120
'SWIFT_TREAT_WARNINGS_AS_ERRORS=NO'])
119-
for setting, value in self._build_settings.iteritems():
120-
if setting == 'CONFIGURATION':
121-
command += ['-configuration', value]
122-
else:
123-
command += ['%s=%s' % (setting, value)]
121+
command += self._added_xcodebuild_flags
124122

125123
return command
126124

@@ -139,12 +137,11 @@ def get_test_command(self, incremental=False):
139137
# TODO: stdlib search code
140138
'SWIFT_LIBRARY_PATH=%s' %
141139
get_stdlib_platform_path(
142-
self._build_settings['SWIFT_EXEC'],
140+
self._swiftc,
143141
self._destination)]
144142
+ ['INDEX_ENABLE_DATA_STORE=NO',
145143
'GCC_TREAT_WARNINGS_AS_ERRORS=NO'])
146-
for setting, value in self._build_settings.iteritems():
147-
command += ['%s=%s' % (setting, value)]
144+
command += self._added_xcodebuild_flags
148145

149146
return command
150147

@@ -279,19 +276,25 @@ def strip_resource_phases(repo_path, stdout=sys.stdout, stderr=sys.stderr):
279276

280277
def dispatch(root_path, repo, action, swiftc, swift_version,
281278
sandbox_profile_xcodebuild, sandbox_profile_package,
282-
added_swift_flags, build_config, should_strip_resource_phases=False,
279+
added_swift_flags, added_xcodebuild_flags,
280+
build_config, should_strip_resource_phases=False,
283281
stdout=sys.stdout, stderr=sys.stderr,
284282
incremental=False):
285283
"""Call functions corresponding to actions."""
286284

285+
substitutions = action.copy()
286+
substitutions.update(repo)
287287
if added_swift_flags:
288288
# Support added swift flags specific to the current repository and
289289
# action by passing their fields as keyword arguments to format, e.g.
290290
# so that {path} in '-index-store-path /tmp/index/{path}' is replaced
291291
# with the value of repo's path field.
292-
substitutions = action.copy()
293-
substitutions.update(repo)
294292
added_swift_flags = added_swift_flags.format(**substitutions)
293+
if added_xcodebuild_flags:
294+
added_xcodebuild_flags = \
295+
shlex.split(added_xcodebuild_flags.format(**substitutions))
296+
else:
297+
added_xcodebuild_flags = []
295298

296299
if action['action'] == 'BuildSwiftPackage':
297300
if not build_config:
@@ -317,38 +320,38 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
317320
action['action']
318321
)
319322

320-
build_settings = {
321-
'SWIFT_EXEC': swiftc
322-
}
323+
initial_xcodebuild_flags = ['SWIFT_EXEC=%s' % swiftc]
323324

324325
if build_config == 'debug':
325-
build_settings['CONFIGURATION'] = 'Debug'
326+
initial_xcodebuild_flags += ['-configuration', 'Debug']
326327
elif build_config == 'release':
327-
build_settings['CONFIGURATION'] = 'Release'
328+
initial_xcodebuild_flags += ['-configuration', 'Release']
328329
elif 'configuration' in action:
329-
build_settings['CONFIGURATION'] = action['configuration']
330+
initial_xcodebuild_flags += ['-configuration',
331+
action['configuration']]
330332

331333
other_swift_flags = []
332334
if swift_version:
333335
other_swift_flags += ['-swift-version', swift_version.split('.')[0]]
334-
build_settings['SWIFT_VERSION'] = swift_version.split('.')[0]
336+
initial_xcodebuild_flags += ['SWIFT_VERSION=%s' % swift_version.split('.')[0]]
335337
if added_swift_flags:
336338
other_swift_flags.append(added_swift_flags)
337339
if other_swift_flags:
338340
other_swift_flags = ['$(OTHER_SWIFT_FLAGS)'] + other_swift_flags
339-
build_settings['OTHER_SWIFT_FLAGS'] = ' '.join(other_swift_flags)
341+
initial_xcodebuild_flags += ['OTHER_SWIFT_FLAGS=%s' % ' '.join(other_swift_flags)]
340342

341343
is_workspace = match.group(2).lower() == 'workspace'
342344
project_path = os.path.join(root_path, repo['path'],
343345
action[match.group(2).lower()])
344346
has_scheme = match.group(3).lower() == 'scheme'
345347
xcode_target = \
346-
XcodeTarget(project_path,
348+
XcodeTarget(swiftc,
349+
project_path,
347350
action[match.group(3).lower()],
348351
action['destination'],
349352
get_sdk_platform_path(action['destination'],
350353
stdout=stdout, stderr=stderr),
351-
build_settings,
354+
initial_xcodebuild_flags + added_xcodebuild_flags,
352355
is_workspace,
353356
has_scheme)
354357
if should_strip_resource_phases:
@@ -486,6 +489,12 @@ def add_arguments(parser):
486489
'names from projects.json enclosed in {} will be '
487490
'replaced with their value)',
488491
default='')
492+
parser.add_argument("--add-xcodebuild-flags",
493+
metavar="FLAGS",
494+
help='add flags to each xcodebuild invocation (note: field '
495+
'names from projects.json enclosed in {} will be '
496+
'replaced with their value)',
497+
default='')
489498
parser.add_argument("--skip-clean",
490499
help='skip all git and build clean steps before '
491500
'building projects',
@@ -851,6 +860,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
851860
sandbox_profile_xcodebuild,
852861
sandbox_profile_package,
853862
added_swift_flags,
863+
added_xcodebuild_flags,
854864
skip_clean, build_config,
855865
strip_resource_phases,
856866
action, version, project):
@@ -866,6 +876,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
866876
self.root_path = common.private_workspace('project_cache')
867877
self.current_platform = platform.system()
868878
self.added_swift_flags = added_swift_flags
879+
self.added_xcodebuild_flags = added_xcodebuild_flags
869880
self.skip_clean = skip_clean
870881
self.build_config = build_config
871882
self.strip_resource_phases = strip_resource_phases
@@ -923,6 +934,7 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
923934
self.sandbox_profile_xcodebuild,
924935
self.sandbox_profile_package,
925936
self.added_swift_flags,
937+
self.added_xcodebuild_flags,
926938
self.build_config,
927939
incremental=self.skip_clean,
928940
stdout=stdout, stderr=stderr)
@@ -964,6 +976,7 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
964976
self.sandbox_profile_xcodebuild,
965977
self.sandbox_profile_package,
966978
self.added_swift_flags,
979+
self.added_xcodebuild_flags,
967980
self.build_config,
968981
incremental=self.skip_clean,
969982
should_strip_resource_phases=self.strip_resource_phases,
@@ -1220,6 +1233,7 @@ def dispatch(self, identifier, incremental, stdout=sys.stdout, stderr=sys.stderr
12201233
self.sandbox_profile_xcodebuild,
12211234
self.sandbox_profile_package,
12221235
self.added_swift_flags,
1236+
self.added_xcodebuild_flags,
12231237
self.build_config,
12241238
should_strip_resource_phases=False,
12251239
stdout=stdout, stderr=stderr,

runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def main():
5151
args.sandbox_profile_xcodebuild,
5252
args.sandbox_profile_package,
5353
args.add_swift_flags,
54+
args.add_xcodebuild_flags,
5455
args.skip_clean,
5556
args.build_config,
5657
args.strip_resource_phases

0 commit comments

Comments
 (0)