Skip to content

Commit 97da839

Browse files
committed
Add --add-source-locations option, off by default.
1 parent 13fcf24 commit 97da839

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

build-script.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def check_rsync():
7777
fatal_error('Error: Could not find rsync.')
7878

7979

80-
def generate_gyb_files(verbose):
80+
def generate_gyb_files(verbose, add_source_locations):
8181
print('** Generating gyb Files **')
8282

8383
check_gyb_exec()
@@ -103,11 +103,17 @@ def generate_gyb_files(verbose):
103103
# Slice off the '.gyb' to get the name for the output file
104104
output_file_name = gyb_file[:-4]
105105

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+
106112
# Generate the new file
107113
check_call([GYB_EXEC] +
108114
[swiftsyntax_sources_dir + '/' + gyb_file] +
109115
['-o', temp_files_dir + '/' + output_file_name] +
110-
['--line-directive='],
116+
line_directive_flags,
111117
verbose=verbose)
112118

113119
# Copy the file if different from the file already present in
@@ -312,6 +318,10 @@ def main():
312318
basic_group.add_argument('-r', '--release', action='store_true', help='''
313319
Build as a release build.
314320
''')
321+
basic_group.add_argument('--add-source-locations', action='store_true',
322+
help='''
323+
Insert ###sourceLocation comments in generated code for line-directive.
324+
''')
315325

316326
testing_group = parser.add_argument_group('Testing')
317327
testing_group.add_argument('-t', '--test', action='store_true',
@@ -345,7 +355,8 @@ def main():
345355

346356

347357
try:
348-
generate_gyb_files(args.verbose)
358+
generate_gyb_files(verbose=args.verbose,
359+
add_source_locations=args.add_source_locations)
349360
except subprocess.CalledProcessError as e:
350361
printerr('Error: Generating .gyb files failed')
351362
printerr('Executing: %s' % ' '.join(e.cmd))

0 commit comments

Comments
 (0)