15
15
16
16
INCR_TRANSFER_ROUNDTRIP_EXEC = \
17
17
WORKSPACE_DIR + '/swift/utils/incrparse/incr_transfer_round_trip.py'
18
- GYB_EXEC = WORKSPACE_DIR + '/swift/utils/gyb'
19
18
LIT_EXEC = WORKSPACE_DIR + '/llvm-project/llvm/utils/lit/lit.py'
20
19
GROUP_INFO_PATH = PACKAGE_DIR + '/utils/group.json'
21
20
@@ -84,16 +83,16 @@ def realpath(path):
84
83
85
84
## Generating gyb files
86
85
87
- def check_gyb_exec ():
88
- if not os .path .exists (GYB_EXEC ):
86
+ def check_gyb_exec (gyb_exec ):
87
+ if not os .path .exists (gyb_exec ):
89
88
fatal_error ('''
90
89
Error: Could not find gyb.
91
90
Looking at '%s'.
92
91
93
92
Make sure you have the main swift repo checked out next to the swift-syntax
94
93
repository.
95
94
Refer to README.md for more information.
96
- ''' % GYB_EXEC )
95
+ ''' % gyb_exec )
97
96
98
97
99
98
def check_rsync ():
@@ -102,7 +101,7 @@ def check_rsync():
102
101
fatal_error ('Error: Could not find rsync.' )
103
102
104
103
105
- def generate_single_gyb_file (gyb_file , output_file_name , destination ,
104
+ def generate_single_gyb_file (gyb_exec , gyb_file , output_file_name , destination ,
106
105
temp_files_dir , add_source_locations ,
107
106
additional_gyb_flags , verbose ):
108
107
# Source locations are added by default by gyb, and cleared by passing
@@ -112,7 +111,7 @@ def generate_single_gyb_file(gyb_file, output_file_name, destination,
112
111
else ['--line-directive=' ]
113
112
114
113
# Generate the new file
115
- check_call ([GYB_EXEC ] +
114
+ check_call ([gyb_exec ] +
116
115
[gyb_file ] +
117
116
['-o' , temp_files_dir + '/' + output_file_name ] +
118
117
line_directive_flags +
@@ -127,10 +126,10 @@ def generate_single_gyb_file(gyb_file, output_file_name, destination,
127
126
[destination + '/' + output_file_name ],
128
127
verbose = verbose )
129
128
130
- def generate_gyb_files (verbose , add_source_locations , destination = None ):
129
+ def generate_gyb_files (gyb_exec , verbose , add_source_locations , destination = None ):
131
130
print ('** Generating gyb Files **' )
132
131
133
- check_gyb_exec ()
132
+ check_gyb_exec (gyb_exec )
134
133
check_rsync ()
135
134
136
135
swiftsyntax_sources_dir = os .path .join (PACKAGE_DIR , 'Sources' ,
@@ -175,7 +174,8 @@ def generate_gyb_files(verbose, add_source_locations, destination=None):
175
174
# Slice off the '.gyb' to get the name for the output file
176
175
output_file_name = gyb_file [:- 4 ]
177
176
178
- generate_single_gyb_file (swiftsyntax_sources_dir + '/' + gyb_file ,
177
+ generate_single_gyb_file (gyb_exec ,
178
+ swiftsyntax_sources_dir + '/' + gyb_file ,
179
179
output_file_name , destination ,
180
180
temp_files_dir , add_source_locations ,
181
181
additional_gyb_flags = [],
@@ -186,7 +186,7 @@ def generate_gyb_files(verbose, add_source_locations, destination=None):
186
186
187
187
gyb_file = swiftsyntax_sources_dir + '/SyntaxNodes.swift.gyb.template'
188
188
189
- generate_single_gyb_file (gyb_file , output_file_name ,
189
+ generate_single_gyb_file (gyb_exec , gyb_file , output_file_name ,
190
190
template_destination , temp_files_dir ,
191
191
add_source_locations ,
192
192
additional_gyb_flags = [
@@ -246,11 +246,11 @@ def build(self, product_name, module_group_path=''):
246
246
247
247
248
248
## Testing
249
- def verify_generated_files (verbose ):
249
+ def verify_generated_files (gyb_exec , verbose ):
250
250
user_generated_dir = os .path .join (PACKAGE_DIR , 'Sources' , 'SwiftSyntax' ,
251
251
'gyb_generated' )
252
252
self_generated_dir = tempfile .mkdtemp ()
253
- generate_gyb_files (verbose = verbose ,
253
+ generate_gyb_files (gyb_exec , verbose = verbose ,
254
254
add_source_locations = False ,
255
255
destination = self_generated_dir )
256
256
@@ -438,6 +438,8 @@ def main():
438
438
section for arguments that need to be specified for this.
439
439
''' )
440
440
441
+ default_gyb_exec = WORKSPACE_DIR + '/swift/utils/gyb'
442
+
441
443
basic_group = parser .add_argument_group ('Basic' )
442
444
443
445
basic_group .add_argument ('--build-dir' , default = None , help = '''
@@ -507,6 +509,9 @@ def main():
507
509
Path to the FileCheck executable that was built as part of the LLVM
508
510
repository. If not specified, it will be looked up from PATH.
509
511
''' )
512
+ testing_group .add_argument ('--gyb-exec' , default = default_gyb_exec , help = '''
513
+ Path to the gyb tool. (default: '%s').
514
+ ''' % (default_gyb_exec ) )
510
515
testing_group .add_argument ('--verify-generated-files' , action = 'store_true' ,
511
516
help = '''
512
517
Instead of generating files using gyb, verify that the files which
@@ -533,7 +538,7 @@ def main():
533
538
534
539
try :
535
540
if not args .verify_generated_files :
536
- generate_gyb_files (verbose = args .verbose ,
541
+ generate_gyb_files (args . gyb_exec , verbose = args .verbose ,
537
542
add_source_locations = args .add_source_locations )
538
543
# Skip the rest of the build if we should perform degyb only
539
544
if args .degyb_only :
@@ -546,7 +551,7 @@ def main():
546
551
547
552
if args .verify_generated_files :
548
553
try :
549
- success = verify_generated_files (verbose = args .verbose )
554
+ success = verify_generated_files (args . gyb_exec , verbose = args .verbose )
550
555
except subprocess .CalledProcessError as e :
551
556
printerr ('FAIL: Gyb-generated files committed to repository do '
552
557
'not match generated ones. Please re-generate the '
0 commit comments