@@ -77,7 +77,7 @@ def check_rsync():
77
77
fatal_error ('Error: Could not find rsync.' )
78
78
79
79
80
- def generate_gyb_files (verbose ):
80
+ def generate_gyb_files (verbose , add_source_locations ):
81
81
print ('** Generating gyb Files **' )
82
82
83
83
check_gyb_exec ()
@@ -103,10 +103,17 @@ def generate_gyb_files(verbose):
103
103
# Slice off the '.gyb' to get the name for the output file
104
104
output_file_name = gyb_file [:- 4 ]
105
105
106
+ # Source locations are added by default by gyb, and cleared by passing
107
+ # `--line-directive=` (nothing following the `=`) to the generator. Our
108
+ # flag is the reverse; we don't want them by default, only if requested.
109
+ line_directive_flags = [] if add_source_locations \
110
+ else ['--line-directive=' ]
111
+
106
112
# Generate the new file
107
113
check_call ([GYB_EXEC ] +
108
114
[swiftsyntax_sources_dir + '/' + gyb_file ] +
109
- ['-o' , temp_files_dir + '/' + output_file_name ],
115
+ ['-o' , temp_files_dir + '/' + output_file_name ] +
116
+ line_directive_flags ,
110
117
verbose = verbose )
111
118
112
119
# Copy the file if different from the file already present in
@@ -311,6 +318,10 @@ def main():
311
318
basic_group .add_argument ('-r' , '--release' , action = 'store_true' , help = '''
312
319
Build as a release build.
313
320
''' )
321
+ basic_group .add_argument ('--add-source-locations' , action = 'store_true' ,
322
+ help = '''
323
+ Insert ###sourceLocation comments in generated code for line-directive.
324
+ ''' )
314
325
315
326
testing_group = parser .add_argument_group ('Testing' )
316
327
testing_group .add_argument ('-t' , '--test' , action = 'store_true' ,
@@ -344,7 +355,8 @@ def main():
344
355
345
356
346
357
try :
347
- generate_gyb_files (args .verbose )
358
+ generate_gyb_files (verbose = args .verbose ,
359
+ add_source_locations = args .add_source_locations )
348
360
except subprocess .CalledProcessError as e :
349
361
printerr ('Error: Generating .gyb files failed' )
350
362
printerr ('Executing: %s' % ' ' .join (e .cmd ))
0 commit comments