@@ -76,7 +76,7 @@ def check_rsync():
76
76
fatal_error ('Error: Could not find rsync.' )
77
77
78
78
79
- def generate_gyb_files (verbose ):
79
+ def generate_gyb_files (verbose , add_source_locations ):
80
80
print ('** Generating gyb Files **' )
81
81
82
82
check_gyb_exec ()
@@ -102,10 +102,17 @@ def generate_gyb_files(verbose):
102
102
# Slice off the '.gyb' to get the name for the output file
103
103
output_file_name = gyb_file [:- 4 ]
104
104
105
+ # Source locations are added by default by gyb, and cleared by passing
106
+ # `--line-directive=` (nothing following the `=`) to the generator. Our
107
+ # flag is the reverse; we don't want them by default, only if requested.
108
+ line_directive_flags = [] if add_source_locations \
109
+ else ['--line-directive=' ]
110
+
105
111
# Generate the new file
106
112
check_call ([GYB_EXEC ] +
107
113
[swiftsyntax_sources_dir + '/' + gyb_file ] +
108
- ['-o' , temp_files_dir + '/' + output_file_name ],
114
+ ['-o' , temp_files_dir + '/' + output_file_name ] +
115
+ line_directive_flags ,
109
116
verbose = verbose )
110
117
111
118
# Copy the file if different from the file already present in
@@ -223,6 +230,10 @@ def main():
223
230
basic_group .add_argument ('-r' , '--release' , action = 'store_true' , help = '''
224
231
Build as a release build.
225
232
''' )
233
+ basic_group .add_argument ('--add-source-locations' , action = 'store_true' ,
234
+ help = '''
235
+ Insert ###sourceLocation comments in generated code for line-directive.
236
+ ''' )
226
237
227
238
testing_group = parser .add_argument_group ('Testing' )
228
239
testing_group .add_argument ('-t' , '--test' , action = 'store_true' ,
@@ -256,7 +267,8 @@ def main():
256
267
257
268
258
269
try :
259
- generate_gyb_files (args .verbose )
270
+ generate_gyb_files (verbose = args .verbose ,
271
+ add_source_locations = args .add_source_locations )
260
272
except subprocess .CalledProcessError as e :
261
273
printerr ('Error: Generating .gyb files failed' )
262
274
printerr ('Executing: %s' % ' ' .join (e .cmd ))
0 commit comments