@@ -283,15 +283,16 @@ def clean_swift_package(path, swiftc, sandbox_profile,
283283def build_swift_package (path , swiftc , swift_version , configuration ,
284284 sandbox_profile , stdout = sys .stdout , stderr = sys .stderr ,
285285 added_swift_flags = None ,
286- incremental = False ):
286+ incremental = False ,
287+ override_swift_exec = None ):
287288 """Build a Swift package manager project."""
288289 swift = os .path .join (os .path .dirname (swiftc ), 'swift' )
289290 if not incremental :
290291 clean_swift_package (path , swiftc , sandbox_profile ,
291292 stdout = stdout , stderr = stderr )
292293 env = os .environ
293294 env ['DYLD_LIBRARY_PATH' ] = get_stdlib_platform_path (swiftc , 'macOS' )
294- env ['SWIFT_EXEC' ] = swiftc
295+ env ['SWIFT_EXEC' ] = override_swift_exec or swiftc
295296 command = [swift , 'build' , '-C' , path , '--verbose' ,
296297 '--configuration' , configuration ]
297298 if (swift_branch not in ['swift-3.0-branch' ,
@@ -323,13 +324,14 @@ def build_swift_package(path, swiftc, swift_version, configuration,
323324def test_swift_package (path , swiftc , sandbox_profile ,
324325 stdout = sys .stdout , stderr = sys .stderr ,
325326 added_swift_flags = None ,
326- incremental = False ):
327+ incremental = False ,
328+ override_swift_exec = None ):
327329 """Test a Swift package manager project."""
328330 swift = os .path .join (os .path .dirname (swiftc ), 'swift' )
329331 if not incremental :
330332 clean_swift_package (path , swiftc , sandbox_profile )
331333 env = os .environ
332- env ['SWIFT_EXEC' ] = swiftc
334+ env ['SWIFT_EXEC' ] = override_swift_exec or swiftc
333335 command = [swift , 'test' , '-C' , path , '--verbose' ]
334336 if added_swift_flags is not None :
335337 for flag in added_swift_flags .split ():
@@ -372,7 +374,7 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
372374 added_swift_flags , added_xcodebuild_flags ,
373375 build_config , should_strip_resource_phases = False ,
374376 stdout = sys .stdout , stderr = sys .stderr ,
375- incremental = False , time_reporter = None ):
377+ incremental = False , time_reporter = None , override_swift_exec = None ):
376378 """Call functions corresponding to actions."""
377379
378380 substitutions = action .copy ()
@@ -398,22 +400,24 @@ def dispatch(root_path, repo, action, swiftc, swift_version,
398400 sandbox_profile_package ,
399401 stdout = stdout , stderr = stderr ,
400402 added_swift_flags = added_swift_flags ,
401- incremental = incremental )
403+ incremental = incremental ,
404+ override_swift_exec = override_swift_exec )
402405 elif action ['action' ] == 'TestSwiftPackage' :
403406 return test_swift_package (os .path .join (root_path , repo ['path' ]),
404407 swiftc ,
405408 sandbox_profile_package ,
406409 stdout = stdout , stderr = stderr ,
407410 added_swift_flags = added_swift_flags ,
408- incremental = incremental )
411+ incremental = incremental ,
412+ override_swift_exec = override_swift_exec )
409413 elif re .match (r'^(Build|Test)Xcode(Workspace|Project)(Scheme|Target)$' ,
410414 action ['action' ]):
411415 match = re .match (
412416 r'^(Build|Test)Xcode(Workspace|Project)(Scheme|Target)$' ,
413417 action ['action' ]
414418 )
415419
416- initial_xcodebuild_flags = ['SWIFT_EXEC=%s' % swiftc ,
420+ initial_xcodebuild_flags = ['SWIFT_EXEC=%s' % ( override_swift_exec or swiftc ) ,
417421 '-IDEPackageSupportDisableManifestSandbox=YES' ]
418422
419423 if build_config == 'debug' :
@@ -543,11 +547,18 @@ def add_arguments(parser):
543547 help = 'swiftc executable' ,
544548 required = True ,
545549 type = os .path .abspath )
550+ parser .add_argument ('--override-swift-exec' ,
551+ metavar = 'PATH' ,
552+ help = 'override the SWIFT_EXEC that is used to build the projects' ,
553+ type = os .path .abspath )
546554 else :
547555 parser .add_argument ('--swiftc' ,
548556 metavar = 'PATH' ,
549557 help = 'swiftc executable' ,
550558 required = True )
559+ parser .add_argument ('--override-swift-exec' ,
560+ metavar = 'PATH' ,
561+ help = 'override the SWIFT_EXEC that is used to build the projects' )
551562 parser .add_argument ('--projects' ,
552563 metavar = 'PATH' ,
553564 required = True ,
@@ -1031,6 +1042,7 @@ def __init__(self, swiftc, swift_version, swift_branch, job_type,
10311042 strip_resource_phases ,
10321043 project_cache_path ,
10331044 time_reporter ,
1045+ override_swift_exec ,
10341046 action , project ):
10351047 self .swiftc = swiftc
10361048 self .swift_version = swift_version
@@ -1049,6 +1061,7 @@ def __init__(self, swiftc, swift_version, swift_branch, job_type,
10491061 self .strip_resource_phases = strip_resource_phases
10501062 self .time_reporter = time_reporter
10511063 self .job_type = job_type
1064+ self .override_swift_exec = override_swift_exec
10521065 self .init ()
10531066
10541067 def init (self ):
@@ -1107,7 +1120,8 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
11071120 self .build_config ,
11081121 incremental = self .skip_clean ,
11091122 time_reporter = self .time_reporter ,
1110- stdout = stdout , stderr = stderr )
1123+ stdout = stdout , stderr = stderr ,
1124+ override_swift_exec = self .override_swift_exec )
11111125 except common .ExecuteCommandFailure as error :
11121126 return self .failed (identifier , error )
11131127 else :
@@ -1146,6 +1160,7 @@ def __init__(self,
11461160 only_latest_versions ,
11471161 project_cache_path ,
11481162 time_reporter ,
1163+ override_swift_exec ,
11491164 action , version , project ):
11501165 super (CompatActionBuilder , self ).__init__ (
11511166 swiftc , swift_version , swift_branch , job_type ,
@@ -1157,6 +1172,7 @@ def __init__(self,
11571172 strip_resource_phases ,
11581173 project_cache_path ,
11591174 time_reporter ,
1175+ override_swift_exec ,
11601176 action , project
11611177 )
11621178 self .only_latest_versions = only_latest_versions
@@ -1184,7 +1200,8 @@ def dispatch(self, identifier, stdout=sys.stdout, stderr=sys.stderr):
11841200 incremental = self .skip_clean ,
11851201 should_strip_resource_phases = self .strip_resource_phases ,
11861202 time_reporter = self .time_reporter ,
1187- stdout = stdout , stderr = stderr )
1203+ stdout = stdout , stderr = stderr ,
1204+ override_swift_exec = self .override_swift_exec )
11881205 except common .ExecuteCommandFailure as error :
11891206 return self .failed (identifier , error )
11901207 else :
@@ -1331,7 +1348,7 @@ def __init__(self, swiftc, swift_version, swift_branch, job_type,
13311348 sandbox_profile_package ,
13321349 added_swift_flags , build_config ,
13331350 strip_resource_phases ,
1334- time_reporter ,
1351+ time_reporter , override_swift_exec ,
13351352 project , action ):
13361353 super (IncrementalActionBuilder ,
13371354 self ).__init__ (swiftc , swift_version , swift_branch , job_type ,
@@ -1342,6 +1359,7 @@ def __init__(self, swiftc, swift_version, swift_branch, job_type,
13421359 build_config = build_config ,
13431360 strip_resource_phases = strip_resource_phases ,
13441361 time_reporter = time_reporter ,
1362+ override_swift_exec = override_swift_exec ,
13451363 project = project ,
13461364 action = action )
13471365 self .proj_path = os .path .join (self .root_path , self .project ['path' ])
@@ -1449,7 +1467,8 @@ def dispatch(self, identifier, incremental, stdout=sys.stdout, stderr=sys.stderr
14491467 should_strip_resource_phases = False ,
14501468 time_reporter = self .time_reporter ,
14511469 stdout = stdout , stderr = stderr ,
1452- incremental = incremental )
1470+ incremental = incremental ,
1471+ override_swift_exec = self .override_swift_exec )
14531472 except common .ExecuteCommandFailure as error :
14541473 return self .failed (identifier , error )
14551474 else :
0 commit comments