Skip to content

Commit 878e7fe

Browse files
authored
Merge pull request #13 from allevato/swift-4.2-remove-line-directives
[4.2] Merge pull request #7 from allevato/remove-line-directives
2 parents 7235ef2 + 5cb879b commit 878e7fe

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

build-script.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def check_rsync():
7676
fatal_error('Error: Could not find rsync.')
7777

7878

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

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

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+
105111
# Generate the new file
106112
check_call([GYB_EXEC] +
107113
[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,
109116
verbose=verbose)
110117

111118
# Copy the file if different from the file already present in
@@ -223,6 +230,10 @@ def main():
223230
basic_group.add_argument('-r', '--release', action='store_true', help='''
224231
Build as a release build.
225232
''')
233+
basic_group.add_argument('--add-source-locations', action='store_true',
234+
help='''
235+
Insert ###sourceLocation comments in generated code for line-directive.
236+
''')
226237

227238
testing_group = parser.add_argument_group('Testing')
228239
testing_group.add_argument('-t', '--test', action='store_true',
@@ -256,7 +267,8 @@ def main():
256267

257268

258269
try:
259-
generate_gyb_files(args.verbose)
270+
generate_gyb_files(verbose=args.verbose,
271+
add_source_locations=args.add_source_locations)
260272
except subprocess.CalledProcessError as e:
261273
printerr('Error: Generating .gyb files failed')
262274
printerr('Executing: %s' % ' '.join(e.cmd))

0 commit comments

Comments
 (0)