@@ -190,43 +190,40 @@ def get_swiftpm_invocation(spm_exec, build_dir, parser_header_dir,
190
190
191
191
# To speed up compilation.
192
192
swiftpm_call .extend (['-Xswiftc' , '-enforce-exclusivity=unchecked' ])
193
-
194
- # To build the group information into the module documentation file
195
- # swiftpm_call.extend(['-Xswiftc', '-Xfrontend', '-Xswiftc', '-group-info-path'])
196
- # swiftpm_call.extend(['-Xswiftc', '-Xfrontend', '-Xswiftc', GROUP_INFO_PATH])
197
-
198
193
return swiftpm_call
199
194
200
- def build_swiftsyntax (swift_build_exec , swiftc_exec , build_dir ,
201
- parser_header_dir , parser_lib_dir ,
202
- build_test_util , release ,
203
- verbose , disable_sandbox = False ):
204
- print ('** Building SwiftSyntax **' )
205
-
206
- swiftpm_call = get_swiftpm_invocation (spm_exec = swift_build_exec ,
207
- build_dir = build_dir ,
208
- parser_header_dir = parser_header_dir ,
209
- parser_lib_dir = parser_lib_dir ,
210
- release = release )
211
- swiftpm_call .extend (['--product' , 'SwiftSyntax' ])
212
-
213
- if disable_sandbox :
214
- swiftpm_call .append ('--disable-sandbox' )
215
-
216
- # Only build lit-test-helper if we are planning to run tests
217
- if build_test_util :
218
- swiftpm_call .extend (['--product' , 'lit-test-helper' ])
219
-
220
- if verbose :
221
- swiftpm_call .extend (['--verbose' ])
222
- _environ = dict (os .environ )
223
- _environ ['SWIFT_EXEC' ] = swiftc_exec
224
- _environ ['SWIFT_SYNTAX_BUILD_SCRIPT' ] = ''
225
- check_call (swiftpm_call , env = _environ , verbose = verbose )
195
+ class Builder (object ):
196
+ def __init__ (self , swift_build_exec , swiftc_exec , build_dir ,
197
+ parser_header_dir , parser_lib_dir ,
198
+ release , verbose , disable_sandbox = False ):
199
+ self .swiftpm_call = get_swiftpm_invocation (spm_exec = swift_build_exec ,
200
+ build_dir = build_dir ,
201
+ parser_header_dir = parser_header_dir ,
202
+ parser_lib_dir = parser_lib_dir ,
203
+ release = release )
204
+ if disable_sandbox :
205
+ self .swiftpm_call .append ('--disable-sandbox' )
206
+ if verbose :
207
+ self .swiftpm_call .extend (['--verbose' ])
208
+ self .verbose = verbose
209
+ self ._environ = dict (os .environ )
210
+ self ._environ ['SWIFT_EXEC' ] = swiftc_exec
211
+ self ._environ ['SWIFT_SYNTAX_BUILD_SCRIPT' ] = ''
212
+
213
+ def build (self , product_name , module_group_path = '' ):
214
+ print ('** Building ' + product_name + ' **' )
215
+ command = list (self .swiftpm_call )
216
+ command .extend (['--product' , product_name ])
217
+
218
+ # To build the group information into the module documentation file
219
+ if module_group_path :
220
+ command .extend (['-Xswiftc' , '-Xfrontend' , '-Xswiftc' , '-group-info-path' ])
221
+ command .extend (['-Xswiftc' , '-Xfrontend' , '-Xswiftc' , module_group_path ])
222
+
223
+ check_call (command , env = self ._environ , verbose = self .verbose )
226
224
227
225
228
226
## Testing
229
-
230
227
def run_tests (swift_test_exec , build_dir , parser_header_dir , parser_lib_dir ,
231
228
release , swift_build_exec , filecheck_exec , swiftc_exec , verbose ):
232
229
print ('** Running SwiftSyntax Tests **' )
@@ -541,15 +538,19 @@ def main():
541
538
sys .exit (0 )
542
539
543
540
try :
544
- build_swiftsyntax (swift_build_exec = args .swift_build_exec ,
541
+ builder = Builder (swift_build_exec = args .swift_build_exec ,
545
542
swiftc_exec = args .swiftc_exec ,
546
543
build_dir = args .build_dir ,
547
544
parser_header_dir = args .syntax_parser_header_dir ,
548
545
parser_lib_dir = args .syntax_parser_lib_dir ,
549
- build_test_util = args .test ,
550
546
release = args .release ,
551
547
verbose = args .verbose ,
552
548
disable_sandbox = args .disable_sandbox )
549
+ builder .build ('SwiftSyntax' , module_group_path = GROUP_INFO_PATH )
550
+
551
+ # Only build lit-test-helper if we are planning to run tests
552
+ if args .test :
553
+ builder .build ('lit-test-helper' )
553
554
except subprocess .CalledProcessError as e :
554
555
printerr ('Error: Building SwiftSyntax failed' )
555
556
printerr ('Executing: %s' % ' ' .join (e .cmd ))
0 commit comments