@@ -161,15 +161,10 @@ def get_installed_name():
161
161
def get_installed_dylib_name ():
162
162
return 'lib' + get_installed_name () + '.dylib'
163
163
164
- def get_swiftpm_invocation (spm_exec , build_dir , parser_header_dir ,
165
- parser_lib_dir , release ):
166
- if spm_exec == 'swift build' :
167
- swiftpm_call = ['swift' , 'build' ]
168
- elif spm_exec == 'swift test' :
169
- swiftpm_call = ['swift' , 'test' ]
170
- else :
171
- swiftpm_call = [spm_exec ]
164
+ def get_swiftpm_invocation (toolchain , action , build_dir , release ):
165
+ swift_exec = os .path .join (toolchain , 'usr' , 'bin' , 'swift' )
172
166
167
+ swiftpm_call = [swift_exec , action ]
173
168
swiftpm_call .extend (['--package-path' , PACKAGE_DIR ])
174
169
if release :
175
170
swiftpm_call .extend (['--configuration' , 'release' ])
@@ -179,34 +174,23 @@ def get_swiftpm_invocation(spm_exec, build_dir, parser_header_dir,
179
174
# Swift compiler needs to know the module link name.
180
175
swiftpm_call .extend (['-Xswiftc' , '-module-link-name' , '-Xswiftc' , get_installed_name ()])
181
176
182
- # To find the syntax parser library.
183
- if parser_header_dir :
184
- swiftpm_call .extend (['-Xswiftc' , '-I' , '-Xswiftc' , parser_header_dir ])
185
- if parser_lib_dir :
186
- swiftpm_call .extend (['-Xswiftc' , '-L' , '-Xswiftc' , parser_lib_dir ])
187
- if platform .system () == 'Darwin' :
188
- swiftpm_call .extend (['-Xlinker' , '-rpath' , '-Xlinker' , parser_lib_dir ])
189
-
190
177
# To speed up compilation.
191
178
swiftpm_call .extend (['-Xswiftc' , '-enforce-exclusivity=unchecked' ])
192
179
return swiftpm_call
193
180
194
181
class Builder (object ):
195
- def __init__ (self , swift_build_exec , swiftc_exec , build_dir ,
196
- parser_header_dir , parser_lib_dir ,
197
- release , verbose , disable_sandbox = False ):
198
- self . swiftpm_call = get_swiftpm_invocation ( spm_exec = swift_build_exec ,
182
+ def __init__ (self , toolchain , build_dir , release , verbose ,
183
+ disable_sandbox = False ):
184
+ self . swiftpm_call = get_swiftpm_invocation ( toolchain = toolchain ,
185
+ action = 'build' ,
199
186
build_dir = build_dir ,
200
- parser_header_dir = parser_header_dir ,
201
- parser_lib_dir = parser_lib_dir ,
202
187
release = release )
203
188
if disable_sandbox :
204
189
self .swiftpm_call .append ('--disable-sandbox' )
205
190
if verbose :
206
191
self .swiftpm_call .extend (['--verbose' ])
207
192
self .verbose = verbose
208
193
self ._environ = dict (os .environ )
209
- self ._environ ['SWIFT_EXEC' ] = swiftc_exec
210
194
self ._environ ['SWIFT_SYNTAX_BUILD_SCRIPT' ] = ''
211
195
212
196
def build (self , product_name , module_group_path = '' ):
@@ -241,31 +225,20 @@ def verify_generated_files(verbose):
241
225
check_call (command )
242
226
243
227
244
- def run_tests (swift_test_exec , build_dir , parser_header_dir , parser_lib_dir ,
245
- release , swift_build_exec , filecheck_exec , swiftc_exec , verbose ):
228
+ def run_tests (toolchain , build_dir , release , filecheck_exec , verbose ):
246
229
print ('** Running SwiftSyntax Tests **' )
247
230
248
- optional_swiftc_exec = swiftc_exec
249
- if optional_swiftc_exec == 'swift' :
250
- optional_swiftc_exec = None
251
-
252
- lit_success = run_lit_tests (swift_build_exec = swift_build_exec ,
231
+ lit_success = run_lit_tests (toolchain = toolchain ,
253
232
build_dir = build_dir ,
254
- parser_header_dir = parser_header_dir ,
255
- parser_lib_dir = parser_lib_dir ,
256
233
release = release ,
257
- swiftc_exec = optional_swiftc_exec ,
258
234
filecheck_exec = filecheck_exec ,
259
235
verbose = verbose )
260
236
if not lit_success :
261
237
return False
262
238
263
- xctest_success = run_xctests (swift_test_exec = swift_test_exec ,
239
+ xctest_success = run_xctests (toolchain = toolchain ,
264
240
build_dir = build_dir ,
265
- parser_header_dir = parser_header_dir ,
266
- parser_lib_dir = parser_lib_dir ,
267
241
release = release ,
268
- swiftc_exec = swiftc_exec ,
269
242
verbose = verbose )
270
243
if not xctest_success :
271
244
return False
@@ -295,12 +268,10 @@ def check_incr_transfer_roundtrip_exec():
295
268
''' )
296
269
297
270
298
- def find_lit_test_helper_exec (swift_build_exec , parser_header_dir , parser_lib_dir ,
299
- build_dir , release ):
300
- swiftpm_call = get_swiftpm_invocation ( spm_exec = swift_build_exec ,
271
+ def find_lit_test_helper_exec (toolchain , build_dir , release ):
272
+ swiftpm_call = get_swiftpm_invocation ( toolchain = toolchain ,
273
+ action = 'build' ,
301
274
build_dir = build_dir ,
302
- parser_header_dir = parser_header_dir ,
303
- parser_lib_dir = parser_lib_dir ,
304
275
release = release )
305
276
swiftpm_call .extend (['--product' , 'lit-test-helper' ])
306
277
swiftpm_call .extend (['--show-bin-path' ])
@@ -309,25 +280,20 @@ def find_lit_test_helper_exec(swift_build_exec, parser_header_dir, parser_lib_di
309
280
return bin_dir .strip () + '/lit-test-helper'
310
281
311
282
312
- def run_lit_tests (swift_build_exec , build_dir , parser_header_dir , parser_lib_dir ,
313
- release , swiftc_exec , filecheck_exec , verbose ):
283
+ def run_lit_tests (toolchain , build_dir , release , filecheck_exec , verbose ):
314
284
print ('** Running lit-based tests **' )
315
285
316
286
check_lit_exec ()
317
287
check_incr_transfer_roundtrip_exec ()
318
288
319
289
lit_test_helper_exec = \
320
- find_lit_test_helper_exec (swift_build_exec = swift_build_exec ,
290
+ find_lit_test_helper_exec (toolchain = toolchain ,
321
291
build_dir = build_dir ,
322
- parser_header_dir = parser_header_dir ,
323
- parser_lib_dir = parser_lib_dir ,
324
292
release = release )
325
293
326
294
lit_call = [LIT_EXEC ]
327
295
lit_call .extend ([PACKAGE_DIR + '/lit_tests' ])
328
296
329
- if swiftc_exec :
330
- lit_call .extend (['--param' , 'SWIFTC=' + realpath (swiftc_exec )])
331
297
if filecheck_exec :
332
298
lit_call .extend (['--param' , 'FILECHECK=' + filecheck_exec ])
333
299
if lit_test_helper_exec :
@@ -345,24 +311,17 @@ def run_lit_tests(swift_build_exec, build_dir, parser_header_dir, parser_lib_dir
345
311
346
312
## XCTest based tests
347
313
348
- def run_xctests (swift_test_exec , build_dir , parser_header_dir , parser_lib_dir ,
349
- release , swiftc_exec , verbose ):
314
+ def run_xctests (toolchain , build_dir , release , verbose ):
350
315
print ('** Running XCTests **' )
351
- swiftpm_call = get_swiftpm_invocation (spm_exec = swift_test_exec ,
316
+ swiftpm_call = get_swiftpm_invocation (toolchain = toolchain ,
317
+ action = 'test' ,
352
318
build_dir = build_dir ,
353
- parser_header_dir = parser_header_dir ,
354
- parser_lib_dir = parser_lib_dir ,
355
319
release = release )
356
320
357
321
if verbose :
358
322
swiftpm_call .extend (['--verbose' ])
359
323
360
- subenv = dict (os .environ )
361
- if swiftc_exec :
362
- # Add the swiftc exec to PATH so that SwiftSyntax finds it
363
- subenv ['PATH' ] = realpath (swiftc_exec + '/..' ) + ':' + subenv ['PATH' ]
364
- subenv ['SWIFT_EXEC' ] = swiftc_exec
365
- return call (swiftpm_call , env = subenv , verbose = verbose ) == 0
324
+ return call (swiftpm_call , verbose = verbose ) == 0
366
325
367
326
def delete_rpath (rpath , binary ):
368
327
if platform .system () == 'Darwin' :
@@ -470,6 +429,9 @@ def main():
470
429
/path/to/SwiftSyntax.swiftmodule/x86_64.swiftmodule and
471
430
/path/to/SwiftSyntax.swiftmodule/x86_64.swiftdoc
472
431
''' )
432
+ basic_group .add_argument ('--toolchain' , help = '''
433
+ The path to the toolchain that shall be used to build SwiftSyntax.
434
+ ''' )
473
435
474
436
build_group = parser .add_argument_group ('Build' )
475
437
build_group .add_argument ('--disable-sandbox' ,
@@ -486,37 +448,6 @@ def main():
486
448
testing_group .add_argument ('-t' , '--test' , action = 'store_true' ,
487
449
help = 'Run tests' )
488
450
489
- testing_group .add_argument ('--swift-build-exec' , default = 'swift build' ,
490
- help = '''
491
- Path to the swift-build executable that is used to build SwiftPM projects
492
- If not specified the the 'swift build' command will be used.
493
- ''' )
494
- testing_group .add_argument ('--swift-test-exec' , default = 'swift test' ,
495
- help = '''
496
- Path to the swift-test executable that is used to test SwiftPM projects
497
- If not specified the the 'swift test' command will be used.
498
- ''' )
499
- testing_group .add_argument ('--swiftc-exec' , default = 'swiftc' , help = '''
500
- Path to the swift executable. If not specified the swiftc exeuctable
501
- will be inferred from PATH.
502
- ''' )
503
- testing_group .add_argument ('--syntax-parser-header-dir' , default = None ,
504
- help = '''
505
- Path to the header and modulemap for the syntax parser library.
506
- If not specified no extra search path will be provided, it will be assumed
507
- that the library is in swift's default search paths.
508
- ''' )
509
- testing_group .add_argument ('--syntax-parser-lib-dir' , default = None ,
510
- help = '''
511
- Path to the syntax parser shared library. If not specified no extra search
512
- path will be provided, it will be assumed that the library is in swift's
513
- default search paths.
514
- ''' )
515
- testing_group .add_argument ('--swift-syntax-test-exec' , default = None ,
516
- help = '''
517
- Path to the swift-syntax-test executable that was built from the main
518
- Swift repo. If not specified, it will be looked up from PATH.
519
- ''' )
520
451
testing_group .add_argument ('--filecheck-exec' , default = None , help = '''
521
452
Path to the FileCheck executable that was built as part of the LLVM
522
453
repository. If not specified, it will be looked up from PATH.
@@ -539,7 +470,7 @@ def main():
539
470
else :
540
471
# will this ever happen?
541
472
build_dir = args .build_dir + '/debug'
542
- stdlib_rpath = realpath ( os .path .dirname (args .swiftc_exec ) + '/../ lib/ swift/ macosx/ ' )
473
+ stdlib_rpath = os .path .join (args .toolchain , 'usr' , ' lib' , ' swift' , ' macosx' )
543
474
install (build_dir = build_dir , dylib_dir = args .dylib_dir ,
544
475
swiftmodule_base_name = args .swiftmodule_base_name ,
545
476
stdlib_rpath = stdlib_rpath )
@@ -572,14 +503,13 @@ def main():
572
503
sys .exit (0 )
573
504
574
505
try :
575
- builder = Builder (swift_build_exec = args .swift_build_exec ,
576
- swiftc_exec = args .swiftc_exec ,
506
+ builder = Builder (toolchain = args .toolchain ,
577
507
build_dir = args .build_dir ,
578
- parser_header_dir = args .syntax_parser_header_dir ,
579
- parser_lib_dir = args .syntax_parser_lib_dir ,
580
508
release = args .release ,
581
509
verbose = args .verbose ,
582
510
disable_sandbox = args .disable_sandbox )
511
+ # TODO: Building with group info does not allow us to reuse the build
512
+ # for running the tests.
583
513
builder .build ('SwiftSyntax' , module_group_path = GROUP_INFO_PATH )
584
514
585
515
# Only build lit-test-helper if we are planning to run tests
@@ -593,14 +523,10 @@ def main():
593
523
594
524
if args .test :
595
525
try :
596
- success = run_tests (swift_test_exec = args .swift_test_exec ,
526
+ success = run_tests (toolchain = args .toolchain ,
597
527
build_dir = realpath (args .build_dir ),
598
- parser_header_dir = args .syntax_parser_header_dir ,
599
- parser_lib_dir = args .syntax_parser_lib_dir ,
600
528
release = args .release ,
601
- swift_build_exec = args .swift_build_exec ,
602
529
filecheck_exec = realpath (args .filecheck_exec ),
603
- swiftc_exec = args .swiftc_exec ,
604
530
verbose = args .verbose )
605
531
if not success :
606
532
# An error message has already been printed by the failing test
0 commit comments