@@ -161,15 +161,10 @@ def get_installed_name():
161161def get_installed_dylib_name ():
162162 return 'lib' + get_installed_name () + '.dylib'
163163
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' )
172166
167+ swiftpm_call = [swift_exec , action ]
173168 swiftpm_call .extend (['--package-path' , PACKAGE_DIR ])
174169 if release :
175170 swiftpm_call .extend (['--configuration' , 'release' ])
@@ -179,34 +174,23 @@ def get_swiftpm_invocation(spm_exec, build_dir, parser_header_dir,
179174 # Swift compiler needs to know the module link name.
180175 swiftpm_call .extend (['-Xswiftc' , '-module-link-name' , '-Xswiftc' , get_installed_name ()])
181176
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-
190177 # To speed up compilation.
191178 swiftpm_call .extend (['-Xswiftc' , '-enforce-exclusivity=unchecked' ])
192179 return swiftpm_call
193180
194181class 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' ,
199186 build_dir = build_dir ,
200- parser_header_dir = parser_header_dir ,
201- parser_lib_dir = parser_lib_dir ,
202187 release = release )
203188 if disable_sandbox :
204189 self .swiftpm_call .append ('--disable-sandbox' )
205190 if verbose :
206191 self .swiftpm_call .extend (['--verbose' ])
207192 self .verbose = verbose
208193 self ._environ = dict (os .environ )
209- self ._environ ['SWIFT_EXEC' ] = swiftc_exec
210194 self ._environ ['SWIFT_SYNTAX_BUILD_SCRIPT' ] = ''
211195
212196 def build (self , product_name , module_group_path = '' ):
@@ -241,31 +225,20 @@ def verify_generated_files(verbose):
241225 check_call (command )
242226
243227
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 ):
246229 print ('** Running SwiftSyntax Tests **' )
247230
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 ,
253232 build_dir = build_dir ,
254- parser_header_dir = parser_header_dir ,
255- parser_lib_dir = parser_lib_dir ,
256233 release = release ,
257- swiftc_exec = optional_swiftc_exec ,
258234 filecheck_exec = filecheck_exec ,
259235 verbose = verbose )
260236 if not lit_success :
261237 return False
262238
263- xctest_success = run_xctests (swift_test_exec = swift_test_exec ,
239+ xctest_success = run_xctests (toolchain = toolchain ,
264240 build_dir = build_dir ,
265- parser_header_dir = parser_header_dir ,
266- parser_lib_dir = parser_lib_dir ,
267241 release = release ,
268- swiftc_exec = swiftc_exec ,
269242 verbose = verbose )
270243 if not xctest_success :
271244 return False
@@ -295,12 +268,10 @@ def check_incr_transfer_roundtrip_exec():
295268''' )
296269
297270
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' ,
301274 build_dir = build_dir ,
302- parser_header_dir = parser_header_dir ,
303- parser_lib_dir = parser_lib_dir ,
304275 release = release )
305276 swiftpm_call .extend (['--product' , 'lit-test-helper' ])
306277 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
309280 return bin_dir .strip () + '/lit-test-helper'
310281
311282
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 ):
314284 print ('** Running lit-based tests **' )
315285
316286 check_lit_exec ()
317287 check_incr_transfer_roundtrip_exec ()
318288
319289 lit_test_helper_exec = \
320- find_lit_test_helper_exec (swift_build_exec = swift_build_exec ,
290+ find_lit_test_helper_exec (toolchain = toolchain ,
321291 build_dir = build_dir ,
322- parser_header_dir = parser_header_dir ,
323- parser_lib_dir = parser_lib_dir ,
324292 release = release )
325293
326294 lit_call = [LIT_EXEC ]
327295 lit_call .extend ([PACKAGE_DIR + '/lit_tests' ])
328296
329- if swiftc_exec :
330- lit_call .extend (['--param' , 'SWIFTC=' + realpath (swiftc_exec )])
331297 if filecheck_exec :
332298 lit_call .extend (['--param' , 'FILECHECK=' + filecheck_exec ])
333299 if lit_test_helper_exec :
@@ -345,24 +311,17 @@ def run_lit_tests(swift_build_exec, build_dir, parser_header_dir, parser_lib_dir
345311
346312## XCTest based tests
347313
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 ):
350315 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' ,
352318 build_dir = build_dir ,
353- parser_header_dir = parser_header_dir ,
354- parser_lib_dir = parser_lib_dir ,
355319 release = release )
356320
357321 if verbose :
358322 swiftpm_call .extend (['--verbose' ])
359323
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
366325
367326def delete_rpath (rpath , binary ):
368327 if platform .system () == 'Darwin' :
@@ -470,6 +429,9 @@ def main():
470429 /path/to/SwiftSyntax.swiftmodule/x86_64.swiftmodule and
471430 /path/to/SwiftSyntax.swiftmodule/x86_64.swiftdoc
472431 ''' )
432+ basic_group .add_argument ('--toolchain' , help = '''
433+ The path to the toolchain that shall be used to build SwiftSyntax.
434+ ''' )
473435
474436 build_group = parser .add_argument_group ('Build' )
475437 build_group .add_argument ('--disable-sandbox' ,
@@ -486,37 +448,6 @@ def main():
486448 testing_group .add_argument ('-t' , '--test' , action = 'store_true' ,
487449 help = 'Run tests' )
488450
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- ''' )
520451 testing_group .add_argument ('--filecheck-exec' , default = None , help = '''
521452 Path to the FileCheck executable that was built as part of the LLVM
522453 repository. If not specified, it will be looked up from PATH.
@@ -539,7 +470,7 @@ def main():
539470 else :
540471 # will this ever happen?
541472 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' )
543474 install (build_dir = build_dir , dylib_dir = args .dylib_dir ,
544475 swiftmodule_base_name = args .swiftmodule_base_name ,
545476 stdlib_rpath = stdlib_rpath )
@@ -572,14 +503,13 @@ def main():
572503 sys .exit (0 )
573504
574505 try :
575- builder = Builder (swift_build_exec = args .swift_build_exec ,
576- swiftc_exec = args .swiftc_exec ,
506+ builder = Builder (toolchain = args .toolchain ,
577507 build_dir = args .build_dir ,
578- parser_header_dir = args .syntax_parser_header_dir ,
579- parser_lib_dir = args .syntax_parser_lib_dir ,
580508 release = args .release ,
581509 verbose = args .verbose ,
582510 disable_sandbox = args .disable_sandbox )
511+ # TODO: Building with group info does not allow us to reuse the build
512+ # for running the tests.
583513 builder .build ('SwiftSyntax' , module_group_path = GROUP_INFO_PATH )
584514
585515 # Only build lit-test-helper if we are planning to run tests
@@ -593,14 +523,10 @@ def main():
593523
594524 if args .test :
595525 try :
596- success = run_tests (swift_test_exec = args .swift_test_exec ,
526+ success = run_tests (toolchain = args .toolchain ,
597527 build_dir = realpath (args .build_dir ),
598- parser_header_dir = args .syntax_parser_header_dir ,
599- parser_lib_dir = args .syntax_parser_lib_dir ,
600528 release = args .release ,
601- swift_build_exec = args .swift_build_exec ,
602529 filecheck_exec = realpath (args .filecheck_exec ),
603- swiftc_exec = args .swiftc_exec ,
604530 verbose = args .verbose )
605531 if not success :
606532 # An error message has already been printed by the failing test
0 commit comments