Shahbaz Youssefi | 98a3550 | 2019-01-08 22:09:39 -0500 | [diff] [blame] | 1 | # Copyright 2019 The ANGLE Project Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Top-level presubmit script for code generation. |
| 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 | for more details on the presubmit API built into depot_tools. |
| 9 | """ |
| 10 | |
| 11 | from subprocess import call |
| 12 | |
Jamie Madill | 73397e8 | 2019-01-09 10:33:16 -0500 | [diff] [blame^] | 13 | |
| 14 | # Fragment of a regular expression that matches C++ and Objective-C++ implementation files. |
| 15 | _IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$' |
| 16 | |
| 17 | |
| 18 | # Fragment of a regular expression that matches C++ and Objective-C++ header files. |
| 19 | _HEADER_EXTENSIONS = r'\.(h|hpp|hxx)$' |
| 20 | |
| 21 | |
| 22 | def _CheckCodeGeneration(input_api, output_api): |
Shahbaz Youssefi | 98a3550 | 2019-01-08 22:09:39 -0500 | [diff] [blame] | 23 | code_gen_path = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 24 | 'scripts/run_code_generation.py') |
| 25 | cmd_name = 'run_code_generation' |
| 26 | cmd = [input_api.python_executable, code_gen_path, '--verify-no-dirty'] |
| 27 | test_cmd = input_api.Command( |
| 28 | name=cmd_name, |
| 29 | cmd=cmd, |
| 30 | kwargs={}, |
| 31 | message=output_api.PresubmitError) |
| 32 | if input_api.verbose: |
| 33 | print('Running ' + cmd_name) |
| 34 | return input_api.RunTests([test_cmd]) |
| 35 | |
Shahbaz Youssefi | 98a3550 | 2019-01-08 22:09:39 -0500 | [diff] [blame] | 36 | |
Jamie Madill | 73397e8 | 2019-01-09 10:33:16 -0500 | [diff] [blame^] | 37 | # Taken directly from Chromium's PRESUBMIT.py |
| 38 | def _CheckNewHeaderWithoutGnChange(input_api, output_api): |
| 39 | """Checks that newly added header files have corresponding GN changes. |
| 40 | Note that this is only a heuristic. To be precise, run script: |
| 41 | build/check_gn_headers.py. |
| 42 | """ |
| 43 | |
| 44 | def headers(f): |
| 45 | return input_api.FilterSourceFile( |
| 46 | f, white_list=(r'.+%s' % _HEADER_EXTENSIONS, )) |
| 47 | |
| 48 | new_headers = [] |
| 49 | for f in input_api.AffectedSourceFiles(headers): |
| 50 | if f.Action() != 'A': |
| 51 | continue |
| 52 | new_headers.append(f.LocalPath()) |
| 53 | |
| 54 | def gn_files(f): |
| 55 | return input_api.FilterSourceFile(f, white_list=(r'.+\.gn', )) |
| 56 | |
| 57 | all_gn_changed_contents = '' |
| 58 | for f in input_api.AffectedSourceFiles(gn_files): |
| 59 | for _, line in f.ChangedContents(): |
| 60 | all_gn_changed_contents += line |
| 61 | |
| 62 | problems = [] |
| 63 | for header in new_headers: |
| 64 | basename = input_api.os_path.basename(header) |
| 65 | if basename not in all_gn_changed_contents: |
| 66 | problems.append(header) |
| 67 | |
| 68 | if problems: |
| 69 | return [output_api.PresubmitPromptWarning( |
| 70 | 'Missing GN changes for new header files', items=sorted(problems), |
| 71 | long_text='Please double check whether newly added header files need ' |
| 72 | 'corresponding changes in gn or gni files.\nThis checking is only a ' |
| 73 | 'heuristic. Run build/check_gn_headers.py to be precise.\n' |
| 74 | 'Read https://crbug.com/661774 for more info.')] |
| 75 | return [] |
| 76 | |
| 77 | |
| 78 | def CheckChangeOnUpload(input_api, output_api): |
| 79 | results = [] |
| 80 | results.extend(_CheckCodeGeneration(input_api, output_api)) |
| 81 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 82 | input_api, output_api)) |
| 83 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 84 | input_api, output_api)) |
| 85 | results.extend(_CheckNewHeaderWithoutGnChange(input_api, output_api)) |
| 86 | results.extend( |
| 87 | input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) |
| 88 | return results |
| 89 | |
Shahbaz Youssefi | 98a3550 | 2019-01-08 22:09:39 -0500 | [diff] [blame] | 90 | |
| 91 | def CheckChangeOnCommit(input_api, output_api): |
Jamie Madill | 73397e8 | 2019-01-09 10:33:16 -0500 | [diff] [blame^] | 92 | results = [] |
| 93 | results.extend( |
| 94 | input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) |
| 95 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 96 | input_api, output_api)) |
| 97 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 98 | input_api, output_api)) |
| 99 | return results |