@@ -49,7 +49,7 @@ def escapeCmdArg(arg):
49
49
return arg
50
50
51
51
52
- def call (cmd , env = os .environ , stdout = None , stderr = subprocess .STDOUT ,
52
+ def call (cmd , env = os .environ , stdout = None , stderr = subprocess .STDOUT ,
53
53
verbose = False ):
54
54
if verbose :
55
55
print (' ' .join ([escapeCmdArg (arg ) for arg in cmd ]))
@@ -78,9 +78,9 @@ def realpath(path):
78
78
def check_gyb_exec ():
79
79
if not os .path .exists (GYB_EXEC ):
80
80
fatal_error ('''
81
- Error: Could not find gyb.
81
+ Error: Could not find gyb.
82
82
83
- Make sure you have the main swift repo checked out next to the swift-syntax
83
+ Make sure you have the main swift repo checked out next to the swift-syntax
84
84
repository.
85
85
Refer to README.md for more information.
86
86
''' )
@@ -110,10 +110,10 @@ def generate_gyb_files(verbose, add_source_locations, tar_path):
110
110
# Clear any *.swift files that are relics from the previous run.
111
111
for previous_gyb_gen_file in os .listdir (generated_files_dir ):
112
112
if previous_gyb_gen_file .endswith ('.swift' ):
113
- gyb_file = os .path .join (swiftsyntax_sources_dir ,
113
+ gyb_file = os .path .join (swiftsyntax_sources_dir ,
114
114
previous_gyb_gen_file + '.gyb' )
115
115
if not os .path .exists (gyb_file ):
116
- check_call (['rm' , previous_gyb_gen_file ], cwd = generated_files_dir ,
116
+ check_call (['rm' , previous_gyb_gen_file ], cwd = generated_files_dir ,
117
117
verbose = verbose )
118
118
119
119
# Generate the new .swift files in a temporary directory and only copy them
@@ -140,7 +140,7 @@ def generate_gyb_files(verbose, add_source_locations, tar_path):
140
140
line_directive_flags ,
141
141
verbose = verbose )
142
142
143
- # Copy the file if different from the file already present in
143
+ # Copy the file if different from the file already present in
144
144
# gyb_generated
145
145
check_call (['rsync' ] +
146
146
['--checksum' ] +
@@ -166,15 +166,10 @@ def get_installed_name():
166
166
def get_installed_dylib_name ():
167
167
return 'lib' + get_installed_name () + '.dylib'
168
168
169
- def get_swiftpm_invocation (spm_exec , build_dir , parser_header_dir ,
170
- parser_lib_dir , release ):
171
- if spm_exec == 'swift build' :
172
- swiftpm_call = ['swift' , 'build' ]
173
- elif spm_exec == 'swift test' :
174
- swiftpm_call = ['swift' , 'test' ]
175
- else :
176
- swiftpm_call = [spm_exec ]
169
+ def get_swiftpm_invocation (toolchain , action , build_dir , release ):
170
+ swift_exec = os .path .join (toolchain , 'usr' , 'bin' , 'swift' )
177
171
172
+ swiftpm_call = [swift_exec , action ]
178
173
swiftpm_call .extend (['--package-path' , PACKAGE_DIR ])
179
174
if release :
180
175
swiftpm_call .extend (['--configuration' , 'release' ])
@@ -184,34 +179,23 @@ def get_swiftpm_invocation(spm_exec, build_dir, parser_header_dir,
184
179
# Swift compiler needs to know the module link name.
185
180
swiftpm_call .extend (['-Xswiftc' , '-module-link-name' , '-Xswiftc' , get_installed_name ()])
186
181
187
- # To find the syntax parser library.
188
- if parser_header_dir :
189
- swiftpm_call .extend (['-Xswiftc' , '-I' , '-Xswiftc' , parser_header_dir ])
190
- if parser_lib_dir :
191
- swiftpm_call .extend (['-Xswiftc' , '-L' , '-Xswiftc' , parser_lib_dir ])
192
- if platform .system () == 'Darwin' :
193
- swiftpm_call .extend (['-Xlinker' , '-rpath' , '-Xlinker' , parser_lib_dir ])
194
-
195
182
# To speed up compilation.
196
183
swiftpm_call .extend (['-Xswiftc' , '-enforce-exclusivity=unchecked' ])
197
184
return swiftpm_call
198
185
199
186
class Builder (object ):
200
- def __init__ (self , swift_build_exec , swiftc_exec , build_dir ,
201
- parser_header_dir , parser_lib_dir ,
202
- release , verbose , disable_sandbox = False ):
203
- self . swiftpm_call = get_swiftpm_invocation ( spm_exec = swift_build_exec ,
187
+ def __init__ (self , toolchain , build_dir , release , verbose ,
188
+ disable_sandbox = False ):
189
+ self . swiftpm_call = get_swiftpm_invocation ( toolchain = toolchain ,
190
+ action = 'build' ,
204
191
build_dir = build_dir ,
205
- parser_header_dir = parser_header_dir ,
206
- parser_lib_dir = parser_lib_dir ,
207
192
release = release )
208
193
if disable_sandbox :
209
194
self .swiftpm_call .append ('--disable-sandbox' )
210
195
if verbose :
211
196
self .swiftpm_call .extend (['--verbose' ])
212
197
self .verbose = verbose
213
198
self ._environ = dict (os .environ )
214
- self ._environ ['SWIFT_EXEC' ] = swiftc_exec
215
199
self ._environ ['SWIFT_SYNTAX_BUILD_SCRIPT' ] = ''
216
200
217
201
def build (self , product_name , module_group_path = '' ):
@@ -228,31 +212,20 @@ def build(self, product_name, module_group_path=''):
228
212
229
213
230
214
## Testing
231
- def run_tests (swift_test_exec , build_dir , parser_header_dir , parser_lib_dir ,
232
- release , swift_build_exec , filecheck_exec , swiftc_exec , verbose ):
215
+ def run_tests (toolchain , build_dir , release , filecheck_exec , verbose ):
233
216
print ('** Running SwiftSyntax Tests **' )
234
217
235
- optional_swiftc_exec = swiftc_exec
236
- if optional_swiftc_exec == 'swift' :
237
- optional_swiftc_exec = None
238
-
239
- lit_success = run_lit_tests (swift_build_exec = swift_build_exec ,
218
+ lit_success = run_lit_tests (toolchain = toolchain ,
240
219
build_dir = build_dir ,
241
- parser_header_dir = parser_header_dir ,
242
- parser_lib_dir = parser_lib_dir ,
243
220
release = release ,
244
- swiftc_exec = optional_swiftc_exec ,
245
221
filecheck_exec = filecheck_exec ,
246
222
verbose = verbose )
247
223
if not lit_success :
248
224
return False
249
225
250
- xctest_success = run_xctests (swift_test_exec = swift_test_exec ,
226
+ xctest_success = run_xctests (toolchain = toolchain ,
251
227
build_dir = build_dir ,
252
- parser_header_dir = parser_header_dir ,
253
- parser_lib_dir = parser_lib_dir ,
254
228
release = release ,
255
- swiftc_exec = swiftc_exec ,
256
229
verbose = verbose )
257
230
if not xctest_success :
258
231
return False
@@ -264,30 +237,28 @@ def run_tests(swift_test_exec, build_dir, parser_header_dir, parser_lib_dir,
264
237
def check_lit_exec ():
265
238
if not os .path .exists (LIT_EXEC ):
266
239
fatal_error ('''
267
- Error: Could not find lit.py.
240
+ Error: Could not find lit.py.
268
241
269
- Make sure you have the llvm repo checked out next to the swift-syntax repo.
242
+ Make sure you have the llvm repo checked out next to the swift-syntax repo.
270
243
Refer to README.md for more information.
271
244
''' )
272
245
273
246
274
247
def check_incr_transfer_roundtrip_exec ():
275
248
if not os .path .exists (INCR_TRANSFER_ROUNDTRIP_EXEC ):
276
249
fatal_error ('''
277
- Error: Could not find incr_transfer_round_trip.py.
250
+ Error: Could not find incr_transfer_round_trip.py.
278
251
279
- Make sure you have the main swift repo checked out next to the swift-syntax
280
- repo.
252
+ Make sure you have the main swift repo checked out next to the swift-syntax
253
+ repo.
281
254
Refer to README.md for more information.
282
255
''' )
283
256
284
257
285
- def find_lit_test_helper_exec (swift_build_exec , parser_header_dir , parser_lib_dir ,
286
- build_dir , release ):
287
- swiftpm_call = get_swiftpm_invocation ( spm_exec = swift_build_exec ,
258
+ def find_lit_test_helper_exec (toolchain , build_dir , release ):
259
+ swiftpm_call = get_swiftpm_invocation ( toolchain = toolchain ,
260
+ action = 'build' ,
288
261
build_dir = build_dir ,
289
- parser_header_dir = parser_header_dir ,
290
- parser_lib_dir = parser_lib_dir ,
291
262
release = release )
292
263
swiftpm_call .extend (['--product' , 'lit-test-helper' ])
293
264
swiftpm_call .extend (['--show-bin-path' ])
@@ -296,25 +267,20 @@ def find_lit_test_helper_exec(swift_build_exec, parser_header_dir, parser_lib_di
296
267
return bin_dir .strip () + '/lit-test-helper'
297
268
298
269
299
- def run_lit_tests (swift_build_exec , build_dir , parser_header_dir , parser_lib_dir ,
300
- release , swiftc_exec , filecheck_exec , verbose ):
270
+ def run_lit_tests (toolchain , build_dir , release , filecheck_exec , verbose ):
301
271
print ('** Running lit-based tests **' )
302
272
303
273
check_lit_exec ()
304
274
check_incr_transfer_roundtrip_exec ()
305
275
306
276
lit_test_helper_exec = \
307
- find_lit_test_helper_exec (swift_build_exec = swift_build_exec ,
277
+ find_lit_test_helper_exec (toolchain = toolchain ,
308
278
build_dir = build_dir ,
309
- parser_header_dir = parser_header_dir ,
310
- parser_lib_dir = parser_lib_dir ,
311
279
release = release )
312
280
313
281
lit_call = [LIT_EXEC ]
314
282
lit_call .extend ([PACKAGE_DIR + '/lit_tests' ])
315
-
316
- if swiftc_exec :
317
- lit_call .extend (['--param' , 'SWIFTC=' + realpath (swiftc_exec )])
283
+
318
284
if filecheck_exec :
319
285
lit_call .extend (['--param' , 'FILECHECK=' + filecheck_exec ])
320
286
if lit_test_helper_exec :
@@ -332,24 +298,17 @@ def run_lit_tests(swift_build_exec, build_dir, parser_header_dir, parser_lib_dir
332
298
333
299
## XCTest based tests
334
300
335
- def run_xctests (swift_test_exec , build_dir , parser_header_dir , parser_lib_dir ,
336
- release , swiftc_exec , verbose ):
301
+ def run_xctests (toolchain , build_dir , release , verbose ):
337
302
print ('** Running XCTests **' )
338
- swiftpm_call = get_swiftpm_invocation (spm_exec = swift_test_exec ,
303
+ swiftpm_call = get_swiftpm_invocation (toolchain = toolchain ,
304
+ action = 'test' ,
339
305
build_dir = build_dir ,
340
- parser_header_dir = parser_header_dir ,
341
- parser_lib_dir = parser_lib_dir ,
342
306
release = release )
343
307
344
308
if verbose :
345
309
swiftpm_call .extend (['--verbose' ])
346
310
347
- subenv = dict (os .environ )
348
- if swiftc_exec :
349
- # Add the swiftc exec to PATH so that SwiftSyntax finds it
350
- subenv ['PATH' ] = realpath (swiftc_exec + '/..' ) + ':' + subenv ['PATH' ]
351
- subenv ['SWIFT_EXEC' ] = swiftc_exec
352
- return call (swiftpm_call , env = subenv , verbose = verbose ) == 0
311
+ return call (swiftpm_call , verbose = verbose ) == 0
353
312
354
313
def delete_rpath (rpath , binary ):
355
314
if platform .system () == 'Darwin' :
@@ -451,12 +410,15 @@ def main():
451
410
basic_group .add_argument ('--swiftmodule-base-name' ,
452
411
help = '''
453
412
The name under which the Swift module should be installed. A .swiftdoc and
454
- .swiftmodule file extension will be added to this path and the
455
- corresponding files will be copied there.
413
+ .swiftmodule file extension will be added to this path and the
414
+ corresponding files will be copied there.
456
415
Example /path/to/SwiftSyntax.swiftmodule/x86_64 copies files to
457
416
/path/to/SwiftSyntax.swiftmodule/x86_64.swiftmodule and
458
417
/path/to/SwiftSyntax.swiftmodule/x86_64.swiftdoc
459
418
''' )
419
+ basic_group .add_argument ('--toolchain' , help = '''
420
+ The path to the toolchain that shall be used to build SwiftSyntax.
421
+ ''' )
460
422
461
423
build_group = parser .add_argument_group ('Build' )
462
424
build_group .add_argument ('--disable-sandbox' ,
@@ -476,38 +438,7 @@ def main():
476
438
testing_group = parser .add_argument_group ('Testing' )
477
439
testing_group .add_argument ('-t' , '--test' , action = 'store_true' ,
478
440
help = 'Run tests' )
479
-
480
- testing_group .add_argument ('--swift-build-exec' , default = 'swift build' ,
481
- help = '''
482
- Path to the swift-build executable that is used to build SwiftPM projects
483
- If not specified the the 'swift build' command will be used.
484
- ''' )
485
- testing_group .add_argument ('--swift-test-exec' , default = 'swift test' ,
486
- help = '''
487
- Path to the swift-test executable that is used to test SwiftPM projects
488
- If not specified the the 'swift test' command will be used.
489
- ''' )
490
- testing_group .add_argument ('--swiftc-exec' , default = 'swiftc' , help = '''
491
- Path to the swift executable. If not specified the swiftc exeuctable
492
- will be inferred from PATH.
493
- ''' )
494
- testing_group .add_argument ('--syntax-parser-header-dir' , default = None ,
495
- help = '''
496
- Path to the header and modulemap for the syntax parser library.
497
- If not specified no extra search path will be provided, it will be assumed
498
- that the library is in swift's default search paths.
499
- ''' )
500
- testing_group .add_argument ('--syntax-parser-lib-dir' , default = None ,
501
- help = '''
502
- Path to the syntax parser shared library. If not specified no extra search
503
- path will be provided, it will be assumed that the library is in swift's
504
- default search paths.
505
- ''' )
506
- testing_group .add_argument ('--swift-syntax-test-exec' , default = None ,
507
- help = '''
508
- Path to the swift-syntax-test executable that was built from the main
509
- Swift repo. If not specified, it will be looked up from PATH.
510
- ''' )
441
+
511
442
testing_group .add_argument ('--filecheck-exec' , default = None , help = '''
512
443
Path to the FileCheck executable that was built as part of the LLVM
513
444
repository. If not specified, it will be looked up from PATH.
@@ -525,7 +456,7 @@ def main():
525
456
else :
526
457
# will this ever happen?
527
458
build_dir = args .build_dir + '/debug'
528
- stdlib_rpath = realpath ( os .path .dirname (args .swiftc_exec ) + '/../ lib/ swift/ macosx/ ' )
459
+ stdlib_rpath = os .path .join (args .toolchain , 'usr' , ' lib' , ' swift' , ' macosx' )
529
460
install (build_dir = build_dir , dylib_dir = args .dylib_dir ,
530
461
swiftmodule_base_name = args .swiftmodule_base_name ,
531
462
stdlib_rpath = stdlib_rpath )
@@ -549,14 +480,13 @@ def main():
549
480
sys .exit (0 )
550
481
551
482
try :
552
- builder = Builder (swift_build_exec = args .swift_build_exec ,
553
- swiftc_exec = args .swiftc_exec ,
483
+ builder = Builder (toolchain = args .toolchain ,
554
484
build_dir = args .build_dir ,
555
- parser_header_dir = args .syntax_parser_header_dir ,
556
- parser_lib_dir = args .syntax_parser_lib_dir ,
557
485
release = args .release ,
558
486
verbose = args .verbose ,
559
487
disable_sandbox = args .disable_sandbox )
488
+ # TODO: Building with group info does not allow us to reuse the build
489
+ # for running the tests.
560
490
builder .build ('SwiftSyntax' , module_group_path = GROUP_INFO_PATH )
561
491
562
492
# Only build lit-test-helper if we are planning to run tests
@@ -570,14 +500,10 @@ def main():
570
500
571
501
if args .test :
572
502
try :
573
- success = run_tests (swift_test_exec = args .swift_test_exec ,
503
+ success = run_tests (toolchain = args .toolchain ,
574
504
build_dir = realpath (args .build_dir ),
575
- parser_header_dir = args .syntax_parser_header_dir ,
576
- parser_lib_dir = args .syntax_parser_lib_dir ,
577
505
release = args .release ,
578
- swift_build_exec = args .swift_build_exec ,
579
506
filecheck_exec = realpath (args .filecheck_exec ),
580
- swiftc_exec = args .swiftc_exec ,
581
507
verbose = args .verbose )
582
508
if not success :
583
509
# An error message has already been printed by the failing test
0 commit comments