blob: c2a90ec11cacbcb96e66a5a670c20b93f30e9557 [file] [log] [blame]
Ryan Tseng85ec17e2018-09-06 17:10:05 -07001# 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. foltz4410e8e2020-05-07 17:10:17 -07005# Rather than pass this to all of the checks, we override the global blacklist
6# with this one.
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 Tseng85ec17e2018-09-06 17:10:05 -070022
btolsch9ba23712019-04-18 16:36:55 -070023def _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
btolsch9ba23712019-04-18 16:36:55 -070036 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
mark a. foltz743b6202019-08-29 14:43:43 -070037 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))
btolsch9ba23712019-04-18 16:36:55 -070041 return results
42
43
btolsch333aecd2019-04-18 16:21:23 -070044def _CommonChecks(input_api, output_api):
45 results = []
mark a. foltz4410e8e2020-05-07 17:10:17 -070046 # 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. foltzb4e53be2020-05-28 11:42:36 -070070 # 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. foltz4410e8e2020-05-07 17:10:17 -070075 results.extend(input_api.canned_checks.CheckChangeLintsClean(
mark a. foltzb4e53be2020-05-28 11:42:36 -070076 input_api, output_api,
77 lint_filters = ['-build/c++11', '-whitespace/braces'],
78 verbose_level=4))
mark a. foltz4410e8e2020-05-07 17:10:17 -070079
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
btolsch9ba23712019-04-18 16:36:55 -070089 results.extend(_CheckDeps(input_api, output_api))
btolsch333aecd2019-04-18 16:21:23 -070090 return results
91
92
Ryan Tseng85ec17e2018-09-06 17:10:05 -070093def CheckChangeOnUpload(input_api, output_api):
Jordan Bayles5a606b82020-06-25 18:57:22 -070094 input_api.DEFAULT_BLOCK_LIST = _EXCLUDED_PATHS;
btolsch333aecd2019-04-18 16:21:23 -070095 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
102def CheckChangeOnCommit(input_api, output_api):
Jordan Bayles5a606b82020-06-25 18:57:22 -0700103 input_api.DEFAULT_BLOCK_LIST = _EXCLUDED_PATHS;
btolsch333aecd2019-04-18 16:21:23 -0700104 results = []
105 results.extend(_CommonChecks(input_api, output_api))
106 return results