Ryan Tseng | 85ec17e | 2018-09-06 17:10:05 -0700 | [diff] [blame] | 1 | # Copyright (c) 2018 The Chromium 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 | |
mark a. foltz | 8c11e26 | 2020-07-22 14:29:37 -0700 | [diff] [blame] | 5 | # Rather than pass this to all of the checks, we override the global excluded |
| 6 | # list with this one. |
mark a. foltz | 4410e8e | 2020-05-07 17:10:17 -0700 | [diff] [blame] | 7 | _EXCLUDED_PATHS = ( |
| 8 | # Exclude all of third_party/ except for BUILD.gns that we maintain. |
| 9 | r'third_party[\\\/].*(?<!BUILD.gn)$', |
| 10 | # Exclude everything under third_party/chromium_quic/{src|build} |
| 11 | r'third_party/chromium_quic/(src|build)/.*', |
| 12 | # Output directories (just in case) |
| 13 | r'.*\bDebug[\\\/].*', |
| 14 | r'.*\bRelease[\\\/].*', |
| 15 | r'.*\bxcodebuild[\\\/].*', |
| 16 | r'.*\bout[\\\/].*', |
| 17 | # There is no point in processing a patch file. |
| 18 | r'.+\.diff$', |
| 19 | r'.+\.patch$', |
| 20 | ) |
| 21 | |
Ryan Tseng | 85ec17e | 2018-09-06 17:10:05 -0700 | [diff] [blame] | 22 | |
btolsch | 9ba2371 | 2019-04-18 16:36:55 -0700 | [diff] [blame] | 23 | def _CheckDeps(input_api, output_api): |
| 24 | results = [] |
| 25 | import sys |
| 26 | original_sys_path = sys.path |
| 27 | try: |
| 28 | sys.path = sys.path + [input_api.os_path.join( |
| 29 | input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
| 30 | import checkdeps |
| 31 | from cpp_checker import CppChecker |
| 32 | from rules import Rule |
| 33 | finally: |
| 34 | sys.path = original_sys_path |
| 35 | |
btolsch | 9ba2371 | 2019-04-18 16:36:55 -0700 | [diff] [blame] | 36 | deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
mark a. foltz | 743b620 | 2019-08-29 14:43:43 -0700 | [diff] [blame] | 37 | deps_checker.CheckDirectory(input_api.PresubmitLocalPath()) |
| 38 | deps_results = deps_checker.results_formatter.GetResults() |
| 39 | for violation in deps_results: |
| 40 | results.append(output_api.PresubmitError(violation)) |
btolsch | 9ba2371 | 2019-04-18 16:36:55 -0700 | [diff] [blame] | 41 | return results |
| 42 | |
| 43 | |
btolsch | 333aecd | 2019-04-18 16:21:23 -0700 | [diff] [blame] | 44 | def _CommonChecks(input_api, output_api): |
| 45 | results = [] |
mark a. foltz | 4410e8e | 2020-05-07 17:10:17 -0700 | [diff] [blame] | 46 | # PanProjectChecks include: |
| 47 | # CheckLongLines (@ 80 cols) |
| 48 | # CheckChangeHasNoTabs |
| 49 | # CheckChangeHasNoStrayWhitespace |
| 50 | # CheckLicense |
| 51 | # CheckChangeWasUploaded (if committing) |
| 52 | # CheckChangeHasDescription |
| 53 | # CheckDoNotSubmitInDescription |
| 54 | # CheckDoNotSubmitInFiles |
| 55 | results.extend(input_api.canned_checks.PanProjectChecks( |
| 56 | input_api, output_api, owners_check=False)); |
| 57 | |
| 58 | # No carriage return characters, files end with one EOL (\n). |
| 59 | results.extend(input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol( |
| 60 | input_api, output_api)); |
| 61 | |
| 62 | # Gender inclusivity |
| 63 | results.extend(input_api.canned_checks.CheckGenderNeutral( |
| 64 | input_api, output_api)) |
| 65 | |
| 66 | # TODO(bug) format required |
| 67 | results.extend(input_api.canned_checks.CheckChangeTodoHasOwner( |
| 68 | input_api, output_api)) |
| 69 | |
mark a. foltz | b4e53be | 2020-05-28 11:42:36 -0700 | [diff] [blame] | 70 | # Linter. |
| 71 | # - We disable c++11 header checks since Open Screen allows them. |
| 72 | # - We disable whitespace/braces because of various false positives. |
| 73 | # - There are some false positives with 'explicit' checks, but it's useful |
| 74 | # enough to keep. |
mark a. foltz | 4410e8e | 2020-05-07 17:10:17 -0700 | [diff] [blame] | 75 | results.extend(input_api.canned_checks.CheckChangeLintsClean( |
mark a. foltz | b4e53be | 2020-05-28 11:42:36 -0700 | [diff] [blame] | 76 | input_api, output_api, |
| 77 | lint_filters = ['-build/c++11', '-whitespace/braces'], |
| 78 | verbose_level=4)) |
mark a. foltz | 4410e8e | 2020-05-07 17:10:17 -0700 | [diff] [blame] | 79 | |
| 80 | # clang-format |
| 81 | results.extend(input_api.canned_checks.CheckPatchFormatted( |
| 82 | input_api, output_api, bypass_warnings=False)) |
| 83 | |
| 84 | # GN formatting |
| 85 | results.extend(input_api.canned_checks.CheckGNFormatted( |
| 86 | input_api, output_api)) |
| 87 | |
| 88 | # buildtools/checkdeps |
btolsch | 9ba2371 | 2019-04-18 16:36:55 -0700 | [diff] [blame] | 89 | results.extend(_CheckDeps(input_api, output_api)) |
btolsch | 333aecd | 2019-04-18 16:21:23 -0700 | [diff] [blame] | 90 | return results |
| 91 | |
| 92 | |
Ryan Tseng | 85ec17e | 2018-09-06 17:10:05 -0700 | [diff] [blame] | 93 | def CheckChangeOnUpload(input_api, output_api): |
Josip Sokcevic | 3cc8363 | 2020-07-23 13:30:22 -0700 | [diff] [blame] | 94 | input_api.DEFAULT_FILES_TO_SKIP = _EXCLUDED_PATHS; |
btolsch | 333aecd | 2019-04-18 16:21:23 -0700 | [diff] [blame] | 95 | results = [] |
| 96 | results.extend(_CommonChecks(input_api, output_api)) |
| 97 | results.extend( |
| 98 | input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api)) |
| 99 | return results |
| 100 | |
| 101 | |
| 102 | def CheckChangeOnCommit(input_api, output_api): |
Josip Sokcevic | 3cc8363 | 2020-07-23 13:30:22 -0700 | [diff] [blame] | 103 | input_api.DEFAULT_FILES_TO_SKIP = _EXCLUDED_PATHS; |
btolsch | 333aecd | 2019-04-18 16:21:23 -0700 | [diff] [blame] | 104 | results = [] |
| 105 | results.extend(_CommonChecks(input_api, output_api)) |
| 106 | return results |