@@ -92,28 +92,30 @@ def check_rsync():
92
92
fatal_error ('Error: Could not find rsync.' )
93
93
94
94
95
- def generate_gyb_files (verbose , add_source_locations ):
95
+ def generate_gyb_files (verbose , add_source_locations , destination = None ):
96
96
print ('** Generating gyb Files **' )
97
97
98
98
check_gyb_exec ()
99
99
check_rsync ()
100
100
101
101
swiftsyntax_sources_dir = PACKAGE_DIR + '/Sources/SwiftSyntax'
102
102
temp_files_dir = tempfile .gettempdir ()
103
- generated_files_dir = swiftsyntax_sources_dir + '/gyb_generated'
103
+
104
+ if destination is None :
105
+ destination = swiftsyntax_sources_dir + '/gyb_generated'
104
106
105
107
if not os .path .exists (temp_files_dir ):
106
108
os .makedirs (temp_files_dir )
107
- if not os .path .exists (generated_files_dir ):
108
- os .makedirs (generated_files_dir )
109
+ if not os .path .exists (destination ):
110
+ os .makedirs (destination )
109
111
110
112
# Clear any *.swift files that are relics from the previous run.
111
- for previous_gyb_gen_file in os .listdir (generated_files_dir ):
113
+ for previous_gyb_gen_file in os .listdir (destination ):
112
114
if previous_gyb_gen_file .endswith ('.swift' ):
113
115
gyb_file = os .path .join (swiftsyntax_sources_dir ,
114
116
previous_gyb_gen_file + '.gyb' )
115
117
if not os .path .exists (gyb_file ):
116
- check_call (['rm' , previous_gyb_gen_file ], cwd = generated_files_dir ,
118
+ check_call (['rm' , previous_gyb_gen_file ], cwd = destination ,
117
119
verbose = verbose )
118
120
119
121
# Generate the new .swift files in a temporary directory and only copy them
@@ -145,7 +147,7 @@ def generate_gyb_files(verbose, add_source_locations):
145
147
check_call (['rsync' ] +
146
148
['--checksum' ] +
147
149
[temp_files_dir + '/' + output_file_name ] +
148
- [generated_files_dir + '/' + output_file_name ],
150
+ [destination + '/' + output_file_name ],
149
151
verbose = verbose )
150
152
151
153
print ('Done Generating gyb Files' )
@@ -221,6 +223,24 @@ def build(self, product_name, module_group_path=''):
221
223
222
224
223
225
## Testing
226
+ def verify_generated_files (verbose ):
227
+ user_generated_dir = os .path .join (PACKAGE_DIR , 'Sources' , 'SwiftSyntax' ,
228
+ 'gyb_generated' )
229
+ self_generated_dir = tempfile .mkdtemp ()
230
+ generate_gyb_files (verbose = verbose ,
231
+ add_source_locations = False ,
232
+ destination = self_generated_dir )
233
+
234
+ command = [
235
+ 'diff' , '-r' ,
236
+ '-x' , '.*' , # Exclude dot files like .DS_Store
237
+ '--context=0' ,
238
+ self_generated_dir ,
239
+ user_generated_dir ,
240
+ ]
241
+ check_call (command )
242
+
243
+
224
244
def run_tests (swift_test_exec , build_dir , parser_header_dir , parser_lib_dir ,
225
245
release , swift_build_exec , filecheck_exec , swiftc_exec , verbose ):
226
246
print ('** Running SwiftSyntax Tests **' )
@@ -501,6 +521,11 @@ def main():
501
521
Path to the FileCheck executable that was built as part of the LLVM
502
522
repository. If not specified, it will be looked up from PATH.
503
523
''' )
524
+ testing_group .add_argument ('--verify-generated-files' , action = 'store_true' ,
525
+ help = '''
526
+ Instead of generating files using gyb, verify that the files which
527
+ already exist match the ones that would be generated by this script.
528
+ ''' )
504
529
505
530
args = parser .parse_args (sys .argv [1 :])
506
531
@@ -521,20 +546,30 @@ def main():
521
546
sys .exit (0 )
522
547
523
548
try :
524
- generate_gyb_files (verbose = args .verbose ,
525
- add_source_locations = args .add_source_locations )
549
+ if not args .verify_generated_files :
550
+ generate_gyb_files (verbose = args .verbose ,
551
+ add_source_locations = args .add_source_locations )
526
552
# Skip the rest of the build if we should perform degyb only
527
553
if args .degyb_only :
528
554
sys .exit (0 )
529
555
except subprocess .CalledProcessError as e :
530
- printerr ('Error : Generating .gyb files failed' )
556
+ printerr ('FAIL : Generating .gyb files failed' )
531
557
printerr ('Executing: %s' % ' ' .join (e .cmd ))
532
558
printerr (e .output )
533
559
sys .exit (1 )
534
560
561
+ if args .verify_generated_files :
562
+ try :
563
+ success = verify_generated_files (verbose = args .verbose )
564
+ except subprocess .CalledProcessError as e :
565
+ printerr ('FAIL: Gyb-generated files committed to repository do '
566
+ 'not match generated ones. Please re-generate the '
567
+ 'gyb-files and recommit them.' )
568
+ sys .exit (1 )
569
+
535
570
if args .generate_xcodeproj :
536
- xcode_gen (config = args .xcconfig_path )
537
- sys .exit (0 )
571
+ xcode_gen (config = args .xcconfig_path )
572
+ sys .exit (0 )
538
573
539
574
try :
540
575
builder = Builder (swift_build_exec = args .swift_build_exec ,
@@ -551,7 +586,7 @@ def main():
551
586
if args .test :
552
587
builder .build ('lit-test-helper' )
553
588
except subprocess .CalledProcessError as e :
554
- printerr ('Error : Building SwiftSyntax failed' )
589
+ printerr ('FAIL : Building SwiftSyntax failed' )
555
590
printerr ('Executing: %s' % ' ' .join (e .cmd ))
556
591
printerr (e .output )
557
592
sys .exit (1 )
@@ -574,7 +609,7 @@ def main():
574
609
else :
575
610
print ('** All tests passed **' )
576
611
except subprocess .CalledProcessError as e :
577
- printerr ('Error : Running tests failed' )
612
+ printerr ('FAIL : Running tests failed' )
578
613
printerr ('Executing: %s' % ' ' .join (e .cmd ))
579
614
printerr (e .output )
580
615
sys .exit (1 )
0 commit comments