From 13fcf249def70bb3cb3bdd846766ef81e9fdd55e Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Fri, 7 Sep 2018 01:11:19 -0700 Subject: [PATCH 1/2] Remove line directives from generated files. These just add noise in the generated files and contain absolute file paths on whosever filesystem the files were generated, so they aren't terribly useful. --- build-script.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-script.py b/build-script.py index dfa524041b8..a46e550b6e2 100755 --- a/build-script.py +++ b/build-script.py @@ -106,7 +106,8 @@ def generate_gyb_files(verbose): # Generate the new file check_call([GYB_EXEC] + [swiftsyntax_sources_dir + '/' + gyb_file] + - ['-o', temp_files_dir + '/' + output_file_name], + ['-o', temp_files_dir + '/' + output_file_name] + + ['--line-directive='], verbose=verbose) # Copy the file if different from the file already present in From 97da83934a9cfd05c8bea82218a0f9a66d1f9868 Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Fri, 7 Sep 2018 15:38:36 -0700 Subject: [PATCH 2/2] Add --add-source-locations option, off by default. --- build-script.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/build-script.py b/build-script.py index a46e550b6e2..7f13028cc90 100755 --- a/build-script.py +++ b/build-script.py @@ -77,7 +77,7 @@ def check_rsync(): fatal_error('Error: Could not find rsync.') -def generate_gyb_files(verbose): +def generate_gyb_files(verbose, add_source_locations): print('** Generating gyb Files **') check_gyb_exec() @@ -103,11 +103,17 @@ def generate_gyb_files(verbose): # Slice off the '.gyb' to get the name for the output file output_file_name = gyb_file[:-4] + # Source locations are added by default by gyb, and cleared by passing + # `--line-directive=` (nothing following the `=`) to the generator. Our + # flag is the reverse; we don't want them by default, only if requested. + line_directive_flags = [] if add_source_locations \ + else ['--line-directive='] + # Generate the new file check_call([GYB_EXEC] + [swiftsyntax_sources_dir + '/' + gyb_file] + ['-o', temp_files_dir + '/' + output_file_name] + - ['--line-directive='], + line_directive_flags, verbose=verbose) # Copy the file if different from the file already present in @@ -312,6 +318,10 @@ def main(): basic_group.add_argument('-r', '--release', action='store_true', help=''' Build as a release build. ''') + basic_group.add_argument('--add-source-locations', action='store_true', + help=''' + Insert ###sourceLocation comments in generated code for line-directive. + ''') testing_group = parser.add_argument_group('Testing') testing_group.add_argument('-t', '--test', action='store_true', @@ -345,7 +355,8 @@ def main(): try: - generate_gyb_files(args.verbose) + generate_gyb_files(verbose=args.verbose, + add_source_locations=args.add_source_locations) except subprocess.CalledProcessError as e: printerr('Error: Generating .gyb files failed') printerr('Executing: %s' % ' '.join(e.cmd))