23
23
import json
24
24
import time
25
25
import argparse
26
+ import shlex
26
27
27
28
import common
28
29
@@ -68,13 +69,14 @@ def test(self, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr,
68
69
class XcodeTarget (ProjectTarget ):
69
70
"""An Xcode workspace scheme."""
70
71
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
73
75
self ._project = project
74
76
self ._target = target
75
77
self ._destination = destination
76
78
self ._sdk = sdk
77
- self ._build_settings = build_settings
79
+ self ._added_xcodebuild_flags = added_xcodebuild_flags
78
80
self ._is_workspace = is_workspace
79
81
self ._has_scheme = has_scheme
80
82
@@ -116,11 +118,7 @@ def get_build_command(self, incremental=False):
116
118
'INDEX_ENABLE_DATA_STORE=NO' ,
117
119
'GCC_TREAT_WARNINGS_AS_ERRORS=NO' ,
118
120
'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
124
122
125
123
return command
126
124
@@ -139,12 +137,11 @@ def get_test_command(self, incremental=False):
139
137
# TODO: stdlib search code
140
138
'SWIFT_LIBRARY_PATH=%s' %
141
139
get_stdlib_platform_path (
142
- self ._build_settings [ 'SWIFT_EXEC' ] ,
140
+ self ._swiftc ,
143
141
self ._destination )]
144
142
+ ['INDEX_ENABLE_DATA_STORE=NO' ,
145
143
'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
148
145
149
146
return command
150
147
@@ -279,19 +276,25 @@ def strip_resource_phases(repo_path, stdout=sys.stdout, stderr=sys.stderr):
279
276
280
277
def dispatch (root_path , repo , action , swiftc , swift_version ,
281
278
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 ,
283
281
stdout = sys .stdout , stderr = sys .stderr ,
284
282
incremental = False ):
285
283
"""Call functions corresponding to actions."""
286
284
285
+ substitutions = action .copy ()
286
+ substitutions .update (repo )
287
287
if added_swift_flags :
288
288
# Support added swift flags specific to the current repository and
289
289
# action by passing their fields as keyword arguments to format, e.g.
290
290
# so that {path} in '-index-store-path /tmp/index/{path}' is replaced
291
291
# with the value of repo's path field.
292
- substitutions = action .copy ()
293
- substitutions .update (repo )
294
292
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 = []
295
298
296
299
if action ['action' ] == 'BuildSwiftPackage' :
297
300
if not build_config :
@@ -317,38 +320,38 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
317
320
action ['action' ]
318
321
)
319
322
320
- build_settings = {
321
- 'SWIFT_EXEC' : swiftc
322
- }
323
+ initial_xcodebuild_flags = ['SWIFT_EXEC=%s' % swiftc ]
323
324
324
325
if build_config == 'debug' :
325
- build_settings [ 'CONFIGURATION' ] = 'Debug'
326
+ initial_xcodebuild_flags += [ '-configuration' , 'Debug' ]
326
327
elif build_config == 'release' :
327
- build_settings [ 'CONFIGURATION' ] = 'Release'
328
+ initial_xcodebuild_flags += [ '-configuration' , 'Release' ]
328
329
elif 'configuration' in action :
329
- build_settings ['CONFIGURATION' ] = action ['configuration' ]
330
+ initial_xcodebuild_flags += ['-configuration' ,
331
+ action ['configuration' ]]
330
332
331
333
other_swift_flags = []
332
334
if swift_version :
333
335
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 ] ]
335
337
if added_swift_flags :
336
338
other_swift_flags .append (added_swift_flags )
337
339
if other_swift_flags :
338
340
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 )]
340
342
341
343
is_workspace = match .group (2 ).lower () == 'workspace'
342
344
project_path = os .path .join (root_path , repo ['path' ],
343
345
action [match .group (2 ).lower ()])
344
346
has_scheme = match .group (3 ).lower () == 'scheme'
345
347
xcode_target = \
346
- XcodeTarget (project_path ,
348
+ XcodeTarget (swiftc ,
349
+ project_path ,
347
350
action [match .group (3 ).lower ()],
348
351
action ['destination' ],
349
352
get_sdk_platform_path (action ['destination' ],
350
353
stdout = stdout , stderr = stderr ),
351
- build_settings ,
354
+ initial_xcodebuild_flags + added_xcodebuild_flags ,
352
355
is_workspace ,
353
356
has_scheme )
354
357
if should_strip_resource_phases :
@@ -486,6 +489,12 @@ def add_arguments(parser):
486
489
'names from projects.json enclosed in {} will be '
487
490
'replaced with their value)' ,
488
491
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 = '' )
489
498
parser .add_argument ("--skip-clean" ,
490
499
help = 'skip all git and build clean steps before '
491
500
'building projects' ,
@@ -851,6 +860,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
851
860
sandbox_profile_xcodebuild ,
852
861
sandbox_profile_package ,
853
862
added_swift_flags ,
863
+ added_xcodebuild_flags ,
854
864
skip_clean , build_config ,
855
865
strip_resource_phases ,
856
866
action , version , project ):
@@ -866,6 +876,7 @@ def __init__(self, swiftc, swift_version, swift_branch,
866
876
self .root_path = common .private_workspace ('project_cache' )
867
877
self .current_platform = platform .system ()
868
878
self .added_swift_flags = added_swift_flags
879
+ self .added_xcodebuild_flags = added_xcodebuild_flags
869
880
self .skip_clean = skip_clean
870
881
self .build_config = build_config
871
882
self .strip_resource_phases = strip_resource_phases
@@ -923,6 +934,7 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
923
934
self .sandbox_profile_xcodebuild ,
924
935
self .sandbox_profile_package ,
925
936
self .added_swift_flags ,
937
+ self .added_xcodebuild_flags ,
926
938
self .build_config ,
927
939
incremental = self .skip_clean ,
928
940
stdout = stdout , stderr = stderr )
@@ -964,6 +976,7 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
964
976
self .sandbox_profile_xcodebuild ,
965
977
self .sandbox_profile_package ,
966
978
self .added_swift_flags ,
979
+ self .added_xcodebuild_flags ,
967
980
self .build_config ,
968
981
incremental = self .skip_clean ,
969
982
should_strip_resource_phases = self .strip_resource_phases ,
@@ -1220,6 +1233,7 @@ def dispatch(self, identifier, incremental, stdout=sys.stdout, stderr=sys.stderr
1220
1233
self .sandbox_profile_xcodebuild ,
1221
1234
self .sandbox_profile_package ,
1222
1235
self .added_swift_flags ,
1236
+ self .added_xcodebuild_flags ,
1223
1237
self .build_config ,
1224
1238
should_strip_resource_phases = False ,
1225
1239
stdout = stdout , stderr = stderr ,
0 commit comments