Skip to content

Commit 4ac751a

Browse files
authored
Merge pull request #627 from ahoppen/ahoppen/expliticly-override-swift-exec
Support using `sk-swiftc-wrapper` that is not installed in the toolchain
2 parents 89d65bf + 34dbeef commit 4ac751a

File tree

3 files changed

+65
-23
lines changed

3 files changed

+65
-23
lines changed

project_future.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,16 @@ def clean_swift_package(path, swiftc, sandbox_profile,
283283
def 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,
323324
def 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:

run_sk_stress_test

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def parse_args():
8484
parser.add_argument('--swiftc',
8585
metavar='PATH',
8686
help='swiftc executable')
87+
parser.add_argument('--sk-swiftc-wrapper',
88+
metavar='PATH',
89+
help='sk-swiftc-wrapper executable')
90+
parser.add_argument('--sk-stress-test',
91+
metavar='PATH',
92+
help='sk-stress-test executable')
8793
parser.add_argument('--skip-tools-build',
8894
action='store_true')
8995
parser.add_argument('--skip-ci-steps',
@@ -106,12 +112,27 @@ def parse_args():
106112
default='')
107113
return parser.parse_args()
108114

109-
def get_swiftc_path(workspace, swiftc):
110-
swiftc_path = (
111-
swiftc if swiftc else
112-
os.path.join(workspace, 'build/compat_macos/install/toolchain/usr/bin/swiftc')
113-
)
114-
return swiftc_path
115+
def get_swiftc_path(workspace, args):
116+
if args.swiftc:
117+
return args.swiftc
118+
else:
119+
return os.path.join(workspace, 'build/compat_macos/install/toolchain/usr/bin/swiftc')
120+
121+
def get_sk_swiftc_wrapper_path(workspace, args):
122+
if args.sk_swiftc_wrapper:
123+
return args.sk_swiftc_wrapper
124+
else:
125+
# If not explicitly specified, fall back to finding `sk-swiftc-wrapper` next to `swiftc`
126+
swiftc_path = get_swiftc_path(workspace, args)
127+
return os.path.join(os.path.dirname(swiftc_path), 'sk-swiftc-wrapper')
128+
129+
def get_sk_stress_test_path(workspace, args):
130+
if args.sk_stress_test:
131+
return args.sk_stress_test
132+
else:
133+
# If not explicitly specified, fall back to finding `sk-stress-test` next to `swiftc`
134+
swiftc_path = get_swiftc_path(workspace, args)
135+
return os.path.join(os.path.dirname(swiftc_path), 'sk-stress-test')
115136

116137
def get_sandbox_profile_flags():
117138
return [
@@ -139,9 +160,9 @@ def clone_swift_syntax(workspace, swift_branch):
139160

140161

141162
def execute_runner(workspace, args):
142-
swiftc_path = get_swiftc_path(workspace, args.swiftc)
143-
wrapper_path = os.path.join(os.path.dirname(swiftc_path), 'sk-swiftc-wrapper')
144-
stress_tester_path = os.path.join(os.path.dirname(swiftc_path), 'sk-stress-test')
163+
swiftc_path = get_swiftc_path(workspace, args)
164+
wrapper_path = get_sk_swiftc_wrapper_path(workspace, args)
165+
stress_tester_path = get_sk_stress_test_path(workspace, args)
145166

146167
extra_runner_args = []
147168
if args.sandbox:
@@ -256,7 +277,8 @@ class StressTesterRunner(object):
256277
run_cmd = ['./runner.py',
257278
'--projects', filtered_projects,
258279
'--verbose',
259-
'--swiftc', self.wrapper,
280+
'--swiftc', self.swiftc,
281+
'--override-swift-exec', self.wrapper,
260282
'--swift-branch', self.swift_branch,
261283
'--job-type', 'stress-tester',
262284
'--default-timeout', str(-1),

runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def main():
7979
args.strip_resource_phases,
8080
args.only_latest_versions,
8181
args.project_cache_path,
82-
time_reporter
82+
time_reporter,
83+
args.override_swift_exec
8384
),
8485
),
8586
),

0 commit comments

Comments
 (0)