Skip to content

Commit 7eca798

Browse files
authored
Merge pull request swiftlang#7 from allevato/remove-line-directives
Remove line directives from generated files.
2 parents 0693b54 + 97da839 commit 7eca798

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

build-script.py

+15-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,10 +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] +
109-
['-o', temp_files_dir + '/' + output_file_name],
115+
['-o', temp_files_dir + '/' + output_file_name] +
116+
line_directive_flags,
110117
verbose=verbose)
111118

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

315326
testing_group = parser.add_argument_group('Testing')
316327
testing_group.add_argument('-t', '--test', action='store_true',
@@ -344,7 +355,8 @@ def main():
344355

345356

346357
try:
347-
generate_gyb_files(args.verbose)
358+
generate_gyb_files(verbose=args.verbose,
359+
add_source_locations=args.add_source_locations)
348360
except subprocess.CalledProcessError as e:
349361
printerr('Error: Generating .gyb files failed')
350362
printerr('Executing: %s' % ' '.join(e.cmd))

0 commit comments

Comments
 (0)