[email protected] | a18130a | 2012-01-03 17:52:08 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 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 Chromium. |
| 6 | |
[email protected] | f129379 | 2009-07-31 18:09:56 | [diff] [blame] | 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
tfarina | 78bb92f4 | 2015-01-31 00:20:48 | [diff] [blame] | 8 | for more details about the presubmit API built into depot_tools. |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 9 | """ |
| 10 | |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 11 | |
[email protected] | 379e7dd | 2010-01-28 17:39:21 | [diff] [blame] | 12 | _EXCLUDED_PATHS = ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 13 | r"^native_client_sdk[\\/]src[\\/]build_tools[\\/]make_rules.py", |
| 14 | r"^native_client_sdk[\\/]src[\\/]build_tools[\\/]make_simple.py", |
| 15 | r"^native_client_sdk[\\/]src[\\/]tools[\\/].*.mk", |
| 16 | r"^net[\\/]tools[\\/]spdyshark[\\/].*", |
| 17 | r"^skia[\\/].*", |
Kent Tamura | 32dbbcb | 2018-11-30 12:28:49 | [diff] [blame] | 18 | r"^third_party[\\/]blink[\\/].*", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 19 | r"^third_party[\\/]breakpad[\\/].*", |
Darwin Huang | d74a9d3 | 2019-07-17 17:58:46 | [diff] [blame] | 20 | # sqlite is an imported third party dependency. |
| 21 | r"^third_party[\\/]sqlite[\\/].*", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 22 | r"^v8[\\/].*", |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 23 | r".*MakeFile$", |
[email protected] | 1084ccc | 2012-03-14 03:22:53 | [diff] [blame] | 24 | r".+_autogen\.h$", |
John Budorick | 1e701d32 | 2019-09-11 23:35:12 | [diff] [blame] | 25 | r".+_pb2\.py$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 26 | r".+[\\/]pnacl_shim\.c$", |
| 27 | r"^gpu[\\/]config[\\/].*_list_json\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 28 | r"tools[\\/]md_browser[\\/].*\.css$", |
Kenneth Russell | 077c8d9 | 2017-12-16 02:52:14 | [diff] [blame] | 29 | # Test pages for Maps telemetry tests. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 30 | r"tools[\\/]perf[\\/]page_sets[\\/]maps_perf_test.*", |
ehmaldonado | 78eee2ed | 2017-03-28 13:16:54 | [diff] [blame] | 31 | # Test pages for WebRTC telemetry tests. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 32 | r"tools[\\/]perf[\\/]page_sets[\\/]webrtc_cases.*", |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 33 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 34 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 35 | |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 36 | # Fragment of a regular expression that matches C++ and Objective-C++ |
| 37 | # implementation files. |
| 38 | _IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$' |
| 39 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 40 | |
Wei-Yin Chen (陳威尹) | c0624d00 | 2018-07-30 18:22:19 | [diff] [blame] | 41 | # Fragment of a regular expression that matches C++ and Objective-C++ |
| 42 | # header files. |
| 43 | _HEADER_EXTENSIONS = r'\.(h|hpp|hxx)$' |
| 44 | |
| 45 | |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 46 | # Regular expression that matches code only used for test binaries |
| 47 | # (best effort). |
| 48 | _TEST_CODE_EXCLUDED_PATHS = ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 49 | r'.*[\\/](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS, |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 50 | r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS, |
Steven Holte | 27008b742 | 2018-01-29 20:55:44 | [diff] [blame] | 51 | r'.+_(api|browser|eg|int|perf|pixel|unit|ui)?test(_[a-z]+)?%s' % |
[email protected] | e2d7e6f | 2013-04-23 12:57:12 | [diff] [blame] | 52 | _IMPLEMENTATION_EXTENSIONS, |
Matthew Denton | 63ea1e6 | 2019-03-25 20:39:18 | [diff] [blame] | 53 | r'.+_(fuzz|fuzzer)(_[a-z]+)?%s' % _IMPLEMENTATION_EXTENSIONS, |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 54 | r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS, |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 55 | r'.*[\\/](test|tool(s)?)[\\/].*', |
[email protected] | ef070cc | 2013-05-03 11:53:05 | [diff] [blame] | 56 | # content_shell is used for running layout tests. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 57 | r'content[\\/]shell[\\/].*', |
[email protected] | 7b05498 | 2013-11-27 00:44:47 | [diff] [blame] | 58 | # Non-production example code. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 59 | r'mojo[\\/]examples[\\/].*', |
[email protected] | 8176de1 | 2014-06-20 19:07:08 | [diff] [blame] | 60 | # Launcher for running iOS tests on the simulator. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 61 | r'testing[\\/]iossim[\\/]iossim\.mm$', |
Olivier Robin | bcea0fa | 2019-11-12 08:56:41 | [diff] [blame] | 62 | # EarlGrey app side code for tests. |
| 63 | r'ios[\\/].*_app_interface\.mm$', |
Allen Bauer | 0678d77 | 2020-05-11 22:25:17 | [diff] [blame] | 64 | # Views Examples code |
| 65 | r'ui[\\/]views[\\/]examples[\\/].*', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 66 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 67 | |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 68 | _THIRD_PARTY_EXCEPT_BLINK = 'third_party/(?!blink/)' |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 69 | |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 70 | _TEST_ONLY_WARNING = ( |
| 71 | 'You might be calling functions intended only for testing from\n' |
| 72 | 'production code. It is OK to ignore this warning if you know what\n' |
| 73 | 'you are doing, as the heuristics used to detect the situation are\n' |
Mohamed Heikal | 5cf6316 | 2019-10-25 19:59:07 | [diff] [blame] | 74 | 'not perfect. The commit queue will not block on this warning,\n' |
| 75 | 'however the android-binary-size trybot will block if the method\n' |
| 76 | 'exists in the release apk.') |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 77 | |
| 78 | |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 79 | _INCLUDE_ORDER_WARNING = ( |
marja | a017dc48 | 2015-03-09 17:13:40 | [diff] [blame] | 80 | 'Your #include order seems to be broken. Remember to use the right ' |
avi | ce9a898 | 2015-11-24 20:36:21 | [diff] [blame] | 81 | 'collation (LC_COLLATE=C) and check\nhttps://google.github.io/styleguide/' |
| 82 | 'cppguide.html#Names_and_Order_of_Includes') |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 83 | |
Michael Thiessen | 4445764 | 2020-02-06 00:24:15 | [diff] [blame] | 84 | # Format: Sequence of tuples containing: |
| 85 | # * Full import path. |
| 86 | # * Sequence of strings to show when the pattern matches. |
| 87 | # * Sequence of path or filename exceptions to this rule |
| 88 | _BANNED_JAVA_IMPORTS = ( |
| 89 | ( |
Colin Blundell | 170d78c8 | 2020-03-12 13:56:04 | [diff] [blame] | 90 | 'java.net.URI;', |
Michael Thiessen | 4445764 | 2020-02-06 00:24:15 | [diff] [blame] | 91 | ( |
| 92 | 'Use org.chromium.url.GURL instead of java.net.URI, where possible.', |
| 93 | ), |
| 94 | ( |
| 95 | 'net/android/javatests/src/org/chromium/net/' |
| 96 | 'AndroidProxySelectorTest.java', |
| 97 | 'components/cronet/', |
Ben Joyce | 615ba2b | 2020-05-20 18:22:04 | [diff] [blame] | 98 | 'third_party/robolectric/local/', |
Michael Thiessen | 4445764 | 2020-02-06 00:24:15 | [diff] [blame] | 99 | ), |
| 100 | ), |
| 101 | ) |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 102 | |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 103 | # Format: Sequence of tuples containing: |
| 104 | # * String pattern or, if starting with a slash, a regular expression. |
| 105 | # * Sequence of strings to show when the pattern matches. |
| 106 | # * Error flag. True if a match is a presubmit error, otherwise it's a warning. |
Eric Stevenson | a9a98097 | 2017-09-23 00:04:41 | [diff] [blame] | 107 | _BANNED_JAVA_FUNCTIONS = ( |
| 108 | ( |
| 109 | 'StrictMode.allowThreadDiskReads()', |
| 110 | ( |
| 111 | 'Prefer using StrictModeContext.allowDiskReads() to using StrictMode ' |
| 112 | 'directly.', |
| 113 | ), |
| 114 | False, |
| 115 | ), |
| 116 | ( |
| 117 | 'StrictMode.allowThreadDiskWrites()', |
| 118 | ( |
| 119 | 'Prefer using StrictModeContext.allowDiskWrites() to using StrictMode ' |
| 120 | 'directly.', |
| 121 | ), |
| 122 | False, |
| 123 | ), |
| 124 | ) |
| 125 | |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 126 | # Format: Sequence of tuples containing: |
| 127 | # * String pattern or, if starting with a slash, a regular expression. |
| 128 | # * Sequence of strings to show when the pattern matches. |
| 129 | # * Error flag. True if a match is a presubmit error, otherwise it's a warning. |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 130 | _BANNED_OBJC_FUNCTIONS = ( |
| 131 | ( |
| 132 | 'addTrackingRect:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 133 | ( |
| 134 | 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 135 | 'prohibited. Please use CrTrackingArea instead.', |
| 136 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 137 | ), |
| 138 | False, |
| 139 | ), |
| 140 | ( |
[email protected] | eaae197 | 2014-04-16 04:17:26 | [diff] [blame] | 141 | r'/NSTrackingArea\W', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 142 | ( |
| 143 | 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 144 | 'instead.', |
| 145 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 146 | ), |
| 147 | False, |
| 148 | ), |
| 149 | ( |
| 150 | 'convertPointFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 151 | ( |
| 152 | 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 153 | 'Please use |convertPoint:(point) fromView:nil| instead.', |
| 154 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 155 | ), |
| 156 | True, |
| 157 | ), |
| 158 | ( |
| 159 | 'convertPointToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 160 | ( |
| 161 | 'The use of -[NSView convertPointToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 162 | 'Please use |convertPoint:(point) toView:nil| instead.', |
| 163 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 164 | ), |
| 165 | True, |
| 166 | ), |
| 167 | ( |
| 168 | 'convertRectFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 169 | ( |
| 170 | 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 171 | 'Please use |convertRect:(point) fromView:nil| instead.', |
| 172 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 173 | ), |
| 174 | True, |
| 175 | ), |
| 176 | ( |
| 177 | 'convertRectToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 178 | ( |
| 179 | 'The use of -[NSView convertRectToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 180 | 'Please use |convertRect:(point) toView:nil| instead.', |
| 181 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 182 | ), |
| 183 | True, |
| 184 | ), |
| 185 | ( |
| 186 | 'convertSizeFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 187 | ( |
| 188 | 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 189 | 'Please use |convertSize:(point) fromView:nil| instead.', |
| 190 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 191 | ), |
| 192 | True, |
| 193 | ), |
| 194 | ( |
| 195 | 'convertSizeToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 196 | ( |
| 197 | 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 198 | 'Please use |convertSize:(point) toView:nil| instead.', |
| 199 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 200 | ), |
| 201 | True, |
| 202 | ), |
jif | 6539870 | 2016-10-27 10:19:48 | [diff] [blame] | 203 | ( |
| 204 | r"/\s+UTF8String\s*]", |
| 205 | ( |
| 206 | 'The use of -[NSString UTF8String] is dangerous as it can return null', |
| 207 | 'even if |canBeConvertedToEncoding:NSUTF8StringEncoding| returns YES.', |
| 208 | 'Please use |SysNSStringToUTF8| instead.', |
| 209 | ), |
| 210 | True, |
| 211 | ), |
Sylvain Defresne | 4cf1d18 | 2017-09-18 14:16:34 | [diff] [blame] | 212 | ( |
| 213 | r'__unsafe_unretained', |
| 214 | ( |
| 215 | 'The use of __unsafe_unretained is almost certainly wrong, unless', |
| 216 | 'when interacting with NSFastEnumeration or NSInvocation.', |
| 217 | 'Please use __weak in files build with ARC, nothing otherwise.', |
| 218 | ), |
| 219 | False, |
| 220 | ), |
Avi Drissman | 7382afa0 | 2019-04-29 23:27:13 | [diff] [blame] | 221 | ( |
| 222 | 'freeWhenDone:NO', |
| 223 | ( |
| 224 | 'The use of "freeWhenDone:NO" with the NoCopy creation of ', |
| 225 | 'Foundation types is prohibited.', |
| 226 | ), |
| 227 | True, |
| 228 | ), |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 229 | ) |
| 230 | |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 231 | # Format: Sequence of tuples containing: |
| 232 | # * String pattern or, if starting with a slash, a regular expression. |
| 233 | # * Sequence of strings to show when the pattern matches. |
| 234 | # * Error flag. True if a match is a presubmit error, otherwise it's a warning. |
Sylvain Defresne | a8b73d25 | 2018-02-28 15:45:54 | [diff] [blame] | 235 | _BANNED_IOS_OBJC_FUNCTIONS = ( |
| 236 | ( |
| 237 | r'/\bTEST[(]', |
| 238 | ( |
| 239 | 'TEST() macro should not be used in Objective-C++ code as it does not ', |
| 240 | 'drain the autorelease pool at the end of the test. Use TEST_F() ', |
| 241 | 'macro instead with a fixture inheriting from PlatformTest (or a ', |
| 242 | 'typedef).' |
| 243 | ), |
| 244 | True, |
| 245 | ), |
| 246 | ( |
| 247 | r'/\btesting::Test\b', |
| 248 | ( |
| 249 | 'testing::Test should not be used in Objective-C++ code as it does ', |
| 250 | 'not drain the autorelease pool at the end of the test. Use ', |
| 251 | 'PlatformTest instead.' |
| 252 | ), |
| 253 | True, |
| 254 | ), |
| 255 | ) |
| 256 | |
Peter K. Lee | 6c03ccff | 2019-07-15 14:40:05 | [diff] [blame] | 257 | # Format: Sequence of tuples containing: |
| 258 | # * String pattern or, if starting with a slash, a regular expression. |
| 259 | # * Sequence of strings to show when the pattern matches. |
| 260 | # * Error flag. True if a match is a presubmit error, otherwise it's a warning. |
| 261 | _BANNED_IOS_EGTEST_FUNCTIONS = ( |
| 262 | ( |
| 263 | r'/\bEXPECT_OCMOCK_VERIFY\b', |
| 264 | ( |
| 265 | 'EXPECT_OCMOCK_VERIFY should not be used in EarlGrey tests because ', |
| 266 | 'it is meant for GTests. Use [mock verify] instead.' |
| 267 | ), |
| 268 | True, |
| 269 | ), |
| 270 | ) |
| 271 | |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 272 | # Directories that contain deprecated Bind() or Callback types. |
| 273 | # Find sub-directories from a given directory by running: |
danakj | c857609 | 2019-11-26 19:01:36 | [diff] [blame] | 274 | # for i in `find . -maxdepth 1 -type d|sort`; do |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 275 | # echo "-- $i" |
danakj | 710b4c0 | 2019-11-28 16:08:45 | [diff] [blame] | 276 | # (cd $i; git grep -nP 'base::(Bind\(|(Callback<|Closure))'|wc -l) |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 277 | # done |
| 278 | # |
| 279 | # TODO(crbug.com/714018): Remove (or narrow the scope of) paths from this list |
| 280 | # when they have been converted to modern callback types (OnceCallback, |
| 281 | # RepeatingCallback, BindOnce, BindRepeating) in order to enable presubmit |
| 282 | # checks for them and prevent regressions. |
| 283 | _NOT_CONVERTED_TO_MODERN_BIND_AND_CALLBACK = '|'.join(( |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 284 | '^apps/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 285 | '^base/callback.h', # Intentional. |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 286 | '^chrome/browser/', |
| 287 | '^chrome/chrome_elf/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 288 | '^chrome/installer/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 289 | '^chrome/services/', |
| 290 | '^chrome/test/', |
| 291 | '^chrome/tools/', |
| 292 | '^chrome/utility/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 293 | '^chromecast/media/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 294 | '^chromeos/attestation/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 295 | '^chromeos/components/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 296 | '^chromeos/network/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 297 | '^chromeos/services/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 298 | '^components/arc/', |
| 299 | '^components/assist_ranker/', |
| 300 | '^components/autofill/', |
| 301 | '^components/autofill_assistant/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 302 | '^components/browser_watcher/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 303 | '^components/cast_channel/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 304 | '^components/chromeos_camera/', |
| 305 | '^components/component_updater/', |
| 306 | '^components/content_settings/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 307 | '^components/cronet/', |
| 308 | '^components/data_reduction_proxy/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 309 | '^components/domain_reliability/', |
danakj | c857609 | 2019-11-26 19:01:36 | [diff] [blame] | 310 | '^components/dom_distiller/', |
Joey Scarr | 164d707 | 2020-04-21 03:13:39 | [diff] [blame] | 311 | '^components/download/internal/common/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 312 | '^components/drive/', |
| 313 | '^components/exo/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 314 | '^components/feedback/', |
| 315 | '^components/flags_ui/', |
| 316 | '^components/gcm_driver/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 317 | '^components/guest_view/', |
| 318 | '^components/heap_profiling/', |
| 319 | '^components/history/', |
| 320 | '^components/image_fetcher/', |
| 321 | '^components/invalidation/', |
| 322 | '^components/keyed_service/', |
| 323 | '^components/login/', |
| 324 | '^components/metrics/', |
| 325 | '^components/metrics_services_manager/', |
| 326 | '^components/nacl/', |
| 327 | '^components/navigation_interception/', |
| 328 | '^components/net_log/', |
| 329 | '^components/network_time/', |
| 330 | '^components/ntp_snippets/', |
| 331 | '^components/ntp_tiles/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 332 | '^components/offline_pages/', |
| 333 | '^components/omnibox/', |
| 334 | '^components/ownership/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 335 | '^components/password_manager/', |
| 336 | '^components/payments/', |
| 337 | '^components/plugins/', |
| 338 | '^components/policy/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 339 | '^components/proxy_config/', |
| 340 | '^components/quirks/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 341 | '^components/remote_cocoa/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 342 | '^components/rlz/', |
| 343 | '^components/safe_browsing/', |
| 344 | '^components/search_engines/', |
| 345 | '^components/search_provider_logos/', |
| 346 | '^components/security_interstitials/', |
| 347 | '^components/security_state/', |
| 348 | '^components/services/', |
| 349 | '^components/sessions/', |
| 350 | '^components/signin/', |
| 351 | '^components/ssl_errors/', |
| 352 | '^components/storage_monitor/', |
| 353 | '^components/subresource_filter/', |
| 354 | '^components/suggestions/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 355 | '^components/sync/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 356 | '^components/sync_preferences/', |
| 357 | '^components/sync_sessions/', |
| 358 | '^components/test/', |
| 359 | '^components/tracing/', |
| 360 | '^components/translate/', |
| 361 | '^components/ukm/', |
| 362 | '^components/update_client/', |
| 363 | '^components/upload_list/', |
| 364 | '^components/variations/', |
| 365 | '^components/visitedlink/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 366 | '^components/webcrypto/', |
| 367 | '^components/webdata/', |
| 368 | '^components/webdata_services/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 369 | '^device/bluetooth/', |
Alan Cutter | 04a0064 | 2020-03-02 01:45:20 | [diff] [blame] | 370 | '^extensions/browser/', |
| 371 | '^extensions/renderer/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 372 | '^google_apis/dive/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 373 | '^google_apis/gcm/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 374 | '^ios/chrome/', |
| 375 | '^ios/components/', |
| 376 | '^ios/net/', |
| 377 | '^ios/web/', |
| 378 | '^ios/web_view/', |
| 379 | '^ipc/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 380 | '^media/base/', |
danakj | c857609 | 2019-11-26 19:01:36 | [diff] [blame] | 381 | '^media/blink/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 382 | '^media/cast/', |
| 383 | '^media/cdm/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 384 | '^media/filters/', |
| 385 | '^media/formats/', |
| 386 | '^media/gpu/', |
| 387 | '^media/mojo/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 388 | '^media/renderers/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 389 | '^net/', |
| 390 | '^ppapi/proxy/', |
| 391 | '^ppapi/shared_impl/', |
| 392 | '^ppapi/tests/', |
| 393 | '^ppapi/thunk/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 394 | '^remoting/host/', |
| 395 | '^remoting/internal/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 396 | '^services/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 397 | '^third_party/blink/', |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 398 | '^tools/clang/base_bind_rewriters/', # Intentional. |
| 399 | '^tools/gdb/gdb_chrome.py', # Intentional. |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 400 | )) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 401 | |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 402 | # Format: Sequence of tuples containing: |
| 403 | # * String pattern or, if starting with a slash, a regular expression. |
| 404 | # * Sequence of strings to show when the pattern matches. |
| 405 | # * Error flag. True if a match is a presubmit error, otherwise it's a warning. |
| 406 | # * Sequence of paths to *not* check (regexps). |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 407 | _BANNED_CPP_FUNCTIONS = ( |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 408 | ( |
Dave Tapuska | 98199b61 | 2019-07-10 13:30:44 | [diff] [blame] | 409 | r'/\bNULL\b', |
thomasanderson | e7caaa9b | 2017-03-29 19:22:53 | [diff] [blame] | 410 | ( |
| 411 | 'New code should not use NULL. Use nullptr instead.', |
| 412 | ), |
Mohamed Amir Yosef | ea38107 | 2019-08-09 08:13:20 | [diff] [blame] | 413 | False, |
thomasanderson | e7caaa9b | 2017-03-29 19:22:53 | [diff] [blame] | 414 | (), |
| 415 | ), |
Peter Kasting | 94a56c4 | 2019-10-25 21:54:04 | [diff] [blame] | 416 | ( |
| 417 | r'/\busing namespace ', |
| 418 | ( |
| 419 | 'Using directives ("using namespace x") are banned by the Google Style', |
| 420 | 'Guide ( http://google.github.io/styleguide/cppguide.html#Namespaces ).', |
| 421 | 'Explicitly qualify symbols or use using declarations ("using x::foo").', |
| 422 | ), |
| 423 | True, |
| 424 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 425 | ), |
Antonio Gomes | 07300d0 | 2019-03-13 20:59:57 | [diff] [blame] | 426 | # Make sure that gtest's FRIEND_TEST() macro is not used; the |
| 427 | # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be |
| 428 | # used instead since that allows for FLAKY_ and DISABLED_ prefixes. |
thomasanderson | e7caaa9b | 2017-03-29 19:22:53 | [diff] [blame] | 429 | ( |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 430 | 'FRIEND_TEST(', |
| 431 | ( |
[email protected] | e3c94550 | 2012-06-26 20:01:49 | [diff] [blame] | 432 | 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 433 | 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.', |
| 434 | ), |
| 435 | False, |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 436 | (), |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 437 | ), |
| 438 | ( |
Dave Tapuska | 98199b61 | 2019-07-10 13:30:44 | [diff] [blame] | 439 | r'/XSelectInput|CWEventMask|XCB_CW_EVENT_MASK', |
thomasanderson | 4b56905 | 2016-09-14 20:15:53 | [diff] [blame] | 440 | ( |
| 441 | 'Chrome clients wishing to select events on X windows should use', |
| 442 | 'ui::XScopedEventSelector. It is safe to ignore this warning only if', |
| 443 | 'you are selecting events from the GPU process, or if you are using', |
| 444 | 'an XDisplay other than gfx::GetXDisplay().', |
| 445 | ), |
| 446 | True, |
| 447 | ( |
Nick Diego Yamane | ea6d999a | 2019-07-24 03:22:40 | [diff] [blame] | 448 | r"^ui[\\/]events[\\/]x[\\/].*\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 449 | r"^ui[\\/]gl[\\/].*\.cc$", |
| 450 | r"^media[\\/]gpu[\\/].*\.cc$", |
| 451 | r"^gpu[\\/].*\.cc$", |
Maksim Sisov | a4d1cfbe | 2020-06-16 07:58:37 | [diff] [blame] | 452 | r"^ui[\\/]base[\\/]x[\\/]xwmstartupcheck[\\/]xwmstartupcheck\.cc$", |
| 453 | ), |
thomasanderson | 4b56905 | 2016-09-14 20:15:53 | [diff] [blame] | 454 | ), |
| 455 | ( |
Dave Tapuska | 98199b61 | 2019-07-10 13:30:44 | [diff] [blame] | 456 | r'/XInternAtom|xcb_intern_atom', |
thomasanderson | e043e3ce | 2017-06-08 00:43:20 | [diff] [blame] | 457 | ( |
thomasanderson | 11aa41dc | 2017-06-08 22:22:38 | [diff] [blame] | 458 | 'Use gfx::GetAtom() instead of interning atoms directly.', |
thomasanderson | e043e3ce | 2017-06-08 00:43:20 | [diff] [blame] | 459 | ), |
| 460 | True, |
| 461 | ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 462 | r"^gpu[\\/]ipc[\\/]service[\\/]gpu_watchdog_thread\.cc$", |
| 463 | r"^remoting[\\/]host[\\/]linux[\\/]x_server_clipboard\.cc$", |
| 464 | r"^ui[\\/]gfx[\\/]x[\\/]x11_atom_cache\.cc$", |
thomasanderson | e043e3ce | 2017-06-08 00:43:20 | [diff] [blame] | 465 | ), |
| 466 | ), |
| 467 | ( |
tomhudson | e2c14d55 | 2016-05-26 17:07:46 | [diff] [blame] | 468 | 'setMatrixClip', |
| 469 | ( |
| 470 | 'Overriding setMatrixClip() is prohibited; ', |
| 471 | 'the base function is deprecated. ', |
| 472 | ), |
| 473 | True, |
| 474 | (), |
| 475 | ), |
| 476 | ( |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 477 | 'SkRefPtr', |
| 478 | ( |
| 479 | 'The use of SkRefPtr is prohibited. ', |
tomhudson | 7e6e051 | 2016-04-19 19:27:22 | [diff] [blame] | 480 | 'Please use sk_sp<> instead.' |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 481 | ), |
| 482 | True, |
| 483 | (), |
| 484 | ), |
| 485 | ( |
| 486 | 'SkAutoRef', |
| 487 | ( |
| 488 | 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ', |
tomhudson | 7e6e051 | 2016-04-19 19:27:22 | [diff] [blame] | 489 | 'Please use sk_sp<> instead.' |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 490 | ), |
| 491 | True, |
| 492 | (), |
| 493 | ), |
| 494 | ( |
| 495 | 'SkAutoTUnref', |
| 496 | ( |
| 497 | 'The use of SkAutoTUnref is dangerous because it implicitly ', |
tomhudson | 7e6e051 | 2016-04-19 19:27:22 | [diff] [blame] | 498 | 'converts to a raw pointer. Please use sk_sp<> instead.' |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 499 | ), |
| 500 | True, |
| 501 | (), |
| 502 | ), |
| 503 | ( |
| 504 | 'SkAutoUnref', |
| 505 | ( |
| 506 | 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ', |
| 507 | 'because it implicitly converts to a raw pointer. ', |
tomhudson | 7e6e051 | 2016-04-19 19:27:22 | [diff] [blame] | 508 | 'Please use sk_sp<> instead.' |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 509 | ), |
| 510 | True, |
| 511 | (), |
| 512 | ), |
[email protected] | d89eec8 | 2013-12-03 14:10:59 | [diff] [blame] | 513 | ( |
| 514 | r'/HANDLE_EINTR\(.*close', |
| 515 | ( |
| 516 | 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file', |
| 517 | 'descriptor will be closed, and it is incorrect to retry the close.', |
| 518 | 'Either call close directly and ignore its return value, or wrap close', |
| 519 | 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623' |
| 520 | ), |
| 521 | True, |
| 522 | (), |
| 523 | ), |
| 524 | ( |
| 525 | r'/IGNORE_EINTR\((?!.*close)', |
| 526 | ( |
| 527 | 'IGNORE_EINTR is only valid when wrapping close. To wrap other system', |
| 528 | 'calls, use HANDLE_EINTR. See http://crbug.com/269623', |
| 529 | ), |
| 530 | True, |
| 531 | ( |
| 532 | # Files that #define IGNORE_EINTR. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 533 | r'^base[\\/]posix[\\/]eintr_wrapper\.h$', |
| 534 | r'^ppapi[\\/]tests[\\/]test_broker\.cc$', |
[email protected] | d89eec8 | 2013-12-03 14:10:59 | [diff] [blame] | 535 | ), |
| 536 | ), |
[email protected] | ec5b3f0 | 2014-04-04 18:43:43 | [diff] [blame] | 537 | ( |
| 538 | r'/v8::Extension\(', |
| 539 | ( |
| 540 | 'Do not introduce new v8::Extensions into the code base, use', |
| 541 | 'gin::Wrappable instead. See http://crbug.com/334679', |
| 542 | ), |
| 543 | True, |
[email protected] | f55c90ee6 | 2014-04-12 00:50:03 | [diff] [blame] | 544 | ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 545 | r'extensions[\\/]renderer[\\/]safe_builtins\.*', |
[email protected] | f55c90ee6 | 2014-04-12 00:50:03 | [diff] [blame] | 546 | ), |
[email protected] | ec5b3f0 | 2014-04-04 18:43:43 | [diff] [blame] | 547 | ), |
skyostil | f9469f7 | 2015-04-20 10:38:52 | [diff] [blame] | 548 | ( |
jam | e2d1a95 | 2016-04-02 00:27:10 | [diff] [blame] | 549 | '#pragma comment(lib,', |
| 550 | ( |
| 551 | 'Specify libraries to link with in build files and not in the source.', |
| 552 | ), |
| 553 | True, |
Mirko Bonadei | f4f0f0e | 2018-04-12 09:29:41 | [diff] [blame] | 554 | ( |
tzik | 3f29599 | 2018-12-04 20:32:23 | [diff] [blame] | 555 | r'^base[\\/]third_party[\\/]symbolize[\\/].*', |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 556 | r'^third_party[\\/]abseil-cpp[\\/].*', |
Mirko Bonadei | f4f0f0e | 2018-04-12 09:29:41 | [diff] [blame] | 557 | ), |
jam | e2d1a95 | 2016-04-02 00:27:10 | [diff] [blame] | 558 | ), |
fdoray | c4ac18d | 2017-05-01 21:39:59 | [diff] [blame] | 559 | ( |
Gabriel Charette | 7cc6c43 | 2018-04-25 20:52:02 | [diff] [blame] | 560 | r'/base::SequenceChecker\b', |
gab | d52c912a | 2017-05-11 04:15:59 | [diff] [blame] | 561 | ( |
| 562 | 'Consider using SEQUENCE_CHECKER macros instead of the class directly.', |
| 563 | ), |
| 564 | False, |
| 565 | (), |
| 566 | ), |
| 567 | ( |
Gabriel Charette | 7cc6c43 | 2018-04-25 20:52:02 | [diff] [blame] | 568 | r'/base::ThreadChecker\b', |
gab | d52c912a | 2017-05-11 04:15:59 | [diff] [blame] | 569 | ( |
| 570 | 'Consider using THREAD_CHECKER macros instead of the class directly.', |
| 571 | ), |
| 572 | False, |
| 573 | (), |
| 574 | ), |
dbeam | b6f4fde | 2017-06-15 04:03:06 | [diff] [blame] | 575 | ( |
Yuri Wiitala | 2f8de5c | 2017-07-21 00:11:06 | [diff] [blame] | 576 | r'/(Time(|Delta|Ticks)|ThreadTicks)::FromInternalValue|ToInternalValue', |
| 577 | ( |
| 578 | 'base::TimeXXX::FromInternalValue() and ToInternalValue() are', |
| 579 | 'deprecated (http://crbug.com/634507). Please avoid converting away', |
| 580 | 'from the Time types in Chromium code, especially if any math is', |
| 581 | 'being done on time values. For interfacing with platform/library', |
| 582 | 'APIs, use FromMicroseconds() or InMicroseconds(), or one of the other', |
| 583 | 'type converter methods instead. For faking TimeXXX values (for unit', |
| 584 | 'testing only), use TimeXXX() + TimeDelta::FromMicroseconds(N). For', |
| 585 | 'other use cases, please contact base/time/OWNERS.', |
| 586 | ), |
| 587 | False, |
| 588 | (), |
| 589 | ), |
| 590 | ( |
dbeam | b6f4fde | 2017-06-15 04:03:06 | [diff] [blame] | 591 | 'CallJavascriptFunctionUnsafe', |
| 592 | ( |
| 593 | "Don't use CallJavascriptFunctionUnsafe() in new code. Instead, use", |
| 594 | 'AllowJavascript(), OnJavascriptAllowed()/OnJavascriptDisallowed(),', |
| 595 | 'and CallJavascriptFunction(). See https://goo.gl/qivavq.', |
| 596 | ), |
| 597 | False, |
| 598 | ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 599 | r'^content[\\/]browser[\\/]webui[\\/]web_ui_impl\.(cc|h)$', |
| 600 | r'^content[\\/]public[\\/]browser[\\/]web_ui\.h$', |
| 601 | r'^content[\\/]public[\\/]test[\\/]test_web_ui\.(cc|h)$', |
dbeam | b6f4fde | 2017-06-15 04:03:06 | [diff] [blame] | 602 | ), |
| 603 | ), |
dskiba | 1474c2bfd6 | 2017-07-20 02:19:24 | [diff] [blame] | 604 | ( |
| 605 | 'leveldb::DB::Open', |
| 606 | ( |
| 607 | 'Instead of leveldb::DB::Open() use leveldb_env::OpenDB() from', |
| 608 | 'third_party/leveldatabase/env_chromium.h. It exposes databases to', |
| 609 | "Chrome's tracing, making their memory usage visible.", |
| 610 | ), |
| 611 | True, |
| 612 | ( |
| 613 | r'^third_party/leveldatabase/.*\.(cc|h)$', |
| 614 | ), |
Gabriel Charette | 0592c3a | 2017-07-26 12:02:04 | [diff] [blame] | 615 | ), |
| 616 | ( |
Chris Mumford | c38afb6 | 2017-10-09 17:55:08 | [diff] [blame] | 617 | 'leveldb::NewMemEnv', |
| 618 | ( |
| 619 | 'Instead of leveldb::NewMemEnv() use leveldb_chrome::NewMemEnv() from', |
Chris Mumford | 8d26d10a | 2018-04-20 17:07:58 | [diff] [blame] | 620 | 'third_party/leveldatabase/leveldb_chrome.h. It exposes environments', |
| 621 | "to Chrome's tracing, making their memory usage visible.", |
Chris Mumford | c38afb6 | 2017-10-09 17:55:08 | [diff] [blame] | 622 | ), |
| 623 | True, |
| 624 | ( |
| 625 | r'^third_party/leveldatabase/.*\.(cc|h)$', |
| 626 | ), |
| 627 | ), |
| 628 | ( |
Gabriel Charette | d9839bc | 2017-07-29 14:17:47 | [diff] [blame] | 629 | 'RunLoop::QuitCurrent', |
| 630 | ( |
Robert Liao | 64b7ab2 | 2017-08-04 23:03:43 | [diff] [blame] | 631 | 'Please migrate away from RunLoop::QuitCurrent*() methods. Use member', |
| 632 | 'methods of a specific RunLoop instance instead.', |
Gabriel Charette | d9839bc | 2017-07-29 14:17:47 | [diff] [blame] | 633 | ), |
Gabriel Charette | c0a8f3ee | 2018-04-25 20:49:41 | [diff] [blame] | 634 | False, |
Gabriel Charette | d9839bc | 2017-07-29 14:17:47 | [diff] [blame] | 635 | (), |
Gabriel Charette | a4497505 | 2017-08-21 23:14:04 | [diff] [blame] | 636 | ), |
| 637 | ( |
| 638 | 'base::ScopedMockTimeMessageLoopTaskRunner', |
| 639 | ( |
Gabriel Charette | 87cc1af | 2018-04-25 20:52:51 | [diff] [blame] | 640 | 'ScopedMockTimeMessageLoopTaskRunner is deprecated. Prefer', |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 641 | 'TaskEnvironment::TimeSource::MOCK_TIME. There are still a', |
Gabriel Charette | 87cc1af | 2018-04-25 20:52:51 | [diff] [blame] | 642 | 'few cases that may require a ScopedMockTimeMessageLoopTaskRunner', |
| 643 | '(i.e. mocking the main MessageLoopForUI in browser_tests), but check', |
| 644 | 'with gab@ first if you think you need it)', |
Gabriel Charette | a4497505 | 2017-08-21 23:14:04 | [diff] [blame] | 645 | ), |
Gabriel Charette | 87cc1af | 2018-04-25 20:52:51 | [diff] [blame] | 646 | False, |
Gabriel Charette | a4497505 | 2017-08-21 23:14:04 | [diff] [blame] | 647 | (), |
Eric Stevenson | 6b47b44c | 2017-08-30 20:41:57 | [diff] [blame] | 648 | ), |
| 649 | ( |
Dave Tapuska | 98199b61 | 2019-07-10 13:30:44 | [diff] [blame] | 650 | 'std::regex', |
Eric Stevenson | 6b47b44c | 2017-08-30 20:41:57 | [diff] [blame] | 651 | ( |
| 652 | 'Using std::regex adds unnecessary binary size to Chrome. Please use', |
Mostyn Bramley-Moore | 6b42732 | 2017-12-21 22:11:02 | [diff] [blame] | 653 | 're2::RE2 instead (crbug.com/755321)', |
Eric Stevenson | 6b47b44c | 2017-08-30 20:41:57 | [diff] [blame] | 654 | ), |
| 655 | True, |
| 656 | (), |
Francois Doray | 43670e3 | 2017-09-27 12:40:38 | [diff] [blame] | 657 | ), |
| 658 | ( |
Peter Kasting | 991618a6 | 2019-06-17 22:00:09 | [diff] [blame] | 659 | r'/\bstd::stoi\b', |
| 660 | ( |
| 661 | 'std::stoi uses exceptions to communicate results. ', |
| 662 | 'Use base::StringToInt() instead.', |
| 663 | ), |
| 664 | True, |
| 665 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 666 | ), |
| 667 | ( |
| 668 | r'/\bstd::stol\b', |
| 669 | ( |
| 670 | 'std::stol uses exceptions to communicate results. ', |
| 671 | 'Use base::StringToInt() instead.', |
| 672 | ), |
| 673 | True, |
| 674 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 675 | ), |
| 676 | ( |
| 677 | r'/\bstd::stoul\b', |
| 678 | ( |
| 679 | 'std::stoul uses exceptions to communicate results. ', |
| 680 | 'Use base::StringToUint() instead.', |
| 681 | ), |
| 682 | True, |
| 683 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 684 | ), |
| 685 | ( |
| 686 | r'/\bstd::stoll\b', |
| 687 | ( |
| 688 | 'std::stoll uses exceptions to communicate results. ', |
| 689 | 'Use base::StringToInt64() instead.', |
| 690 | ), |
| 691 | True, |
| 692 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 693 | ), |
| 694 | ( |
| 695 | r'/\bstd::stoull\b', |
| 696 | ( |
| 697 | 'std::stoull uses exceptions to communicate results. ', |
| 698 | 'Use base::StringToUint64() instead.', |
| 699 | ), |
| 700 | True, |
| 701 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 702 | ), |
| 703 | ( |
| 704 | r'/\bstd::stof\b', |
| 705 | ( |
| 706 | 'std::stof uses exceptions to communicate results. ', |
| 707 | 'For locale-independent values, e.g. reading numbers from disk', |
| 708 | 'profiles, use base::StringToDouble().', |
| 709 | 'For user-visible values, parse using ICU.', |
| 710 | ), |
| 711 | True, |
| 712 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 713 | ), |
| 714 | ( |
| 715 | r'/\bstd::stod\b', |
| 716 | ( |
| 717 | 'std::stod uses exceptions to communicate results. ', |
| 718 | 'For locale-independent values, e.g. reading numbers from disk', |
| 719 | 'profiles, use base::StringToDouble().', |
| 720 | 'For user-visible values, parse using ICU.', |
| 721 | ), |
| 722 | True, |
| 723 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 724 | ), |
| 725 | ( |
| 726 | r'/\bstd::stold\b', |
| 727 | ( |
| 728 | 'std::stold uses exceptions to communicate results. ', |
| 729 | 'For locale-independent values, e.g. reading numbers from disk', |
| 730 | 'profiles, use base::StringToDouble().', |
| 731 | 'For user-visible values, parse using ICU.', |
| 732 | ), |
| 733 | True, |
| 734 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 735 | ), |
| 736 | ( |
Daniel Bratell | 69334cc | 2019-03-26 11:07:45 | [diff] [blame] | 737 | r'/\bstd::to_string\b', |
| 738 | ( |
| 739 | 'std::to_string is locale dependent and slower than alternatives.', |
Peter Kasting | 991618a6 | 2019-06-17 22:00:09 | [diff] [blame] | 740 | 'For locale-independent strings, e.g. writing numbers to disk', |
| 741 | 'profiles, use base::NumberToString().', |
Daniel Bratell | 69334cc | 2019-03-26 11:07:45 | [diff] [blame] | 742 | 'For user-visible strings, use base::FormatNumber() and', |
| 743 | 'the related functions in base/i18n/number_formatting.h.', |
| 744 | ), |
Peter Kasting | 991618a6 | 2019-06-17 22:00:09 | [diff] [blame] | 745 | False, # Only a warning since it is already used. |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 746 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
Daniel Bratell | 69334cc | 2019-03-26 11:07:45 | [diff] [blame] | 747 | ), |
| 748 | ( |
| 749 | r'/\bstd::shared_ptr\b', |
| 750 | ( |
| 751 | 'std::shared_ptr should not be used. Use scoped_refptr instead.', |
| 752 | ), |
| 753 | True, |
Andreas Haas | 63f5879 | 2019-11-07 10:56:44 | [diff] [blame] | 754 | [_THIRD_PARTY_EXCEPT_BLINK, |
| 755 | '^third_party/blink/renderer/core/typed_arrays/array_buffer/' + |
| 756 | 'array_buffer_contents\.(cc|h)'], |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 757 | ), |
| 758 | ( |
Peter Kasting | 991618a6 | 2019-06-17 22:00:09 | [diff] [blame] | 759 | r'/\bstd::weak_ptr\b', |
| 760 | ( |
| 761 | 'std::weak_ptr should not be used. Use base::WeakPtr instead.', |
| 762 | ), |
| 763 | True, |
| 764 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 765 | ), |
| 766 | ( |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 767 | r'/\blong long\b', |
| 768 | ( |
| 769 | 'long long is banned. Use stdint.h if you need a 64 bit number.', |
| 770 | ), |
| 771 | False, # Only a warning since it is already used. |
| 772 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 773 | ), |
| 774 | ( |
| 775 | r'/\bstd::bind\b', |
| 776 | ( |
| 777 | 'std::bind is banned because of lifetime risks.', |
| 778 | 'Use base::BindOnce or base::BindRepeating instead.', |
| 779 | ), |
| 780 | True, |
| 781 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 782 | ), |
| 783 | ( |
| 784 | r'/\b#include <chrono>\b', |
| 785 | ( |
| 786 | '<chrono> overlaps with Time APIs in base. Keep using', |
| 787 | 'base classes.', |
| 788 | ), |
| 789 | True, |
| 790 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 791 | ), |
| 792 | ( |
| 793 | r'/\b#include <exception>\b', |
| 794 | ( |
| 795 | 'Exceptions are banned and disabled in Chromium.', |
| 796 | ), |
| 797 | True, |
| 798 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 799 | ), |
| 800 | ( |
| 801 | r'/\bstd::function\b', |
| 802 | ( |
| 803 | 'std::function is banned. Instead use base::Callback which directly', |
| 804 | 'supports Chromium\'s weak pointers, ref counting and more.', |
| 805 | ), |
Peter Kasting | 991618a6 | 2019-06-17 22:00:09 | [diff] [blame] | 806 | False, # Only a warning since it is already used. |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 807 | [_THIRD_PARTY_EXCEPT_BLINK], # Do not warn in third_party folders. |
| 808 | ), |
| 809 | ( |
| 810 | r'/\b#include <random>\b', |
| 811 | ( |
| 812 | 'Do not use any random number engines from <random>. Instead', |
| 813 | 'use base::RandomBitGenerator.', |
| 814 | ), |
| 815 | True, |
| 816 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 817 | ), |
| 818 | ( |
| 819 | r'/\bstd::ratio\b', |
| 820 | ( |
| 821 | 'std::ratio is banned by the Google Style Guide.', |
| 822 | ), |
| 823 | True, |
| 824 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
Daniel Bratell | 69334cc | 2019-03-26 11:07:45 | [diff] [blame] | 825 | ), |
| 826 | ( |
Francois Doray | 43670e3 | 2017-09-27 12:40:38 | [diff] [blame] | 827 | (r'/base::ThreadRestrictions::(ScopedAllowIO|AssertIOAllowed|' |
| 828 | r'DisallowWaiting|AssertWaitAllowed|SetWaitAllowed|ScopedAllowWait)'), |
| 829 | ( |
| 830 | 'Use the new API in base/threading/thread_restrictions.h.', |
| 831 | ), |
Gabriel Charette | 04b138f | 2018-08-06 00:03:22 | [diff] [blame] | 832 | False, |
Francois Doray | 43670e3 | 2017-09-27 12:40:38 | [diff] [blame] | 833 | (), |
| 834 | ), |
Luis Hector Chavez | 9bbaed53 | 2017-11-30 18:25:38 | [diff] [blame] | 835 | ( |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 836 | r'/\bbase::Bind\(', |
| 837 | ( |
| 838 | 'Please use base::Bind{Once,Repeating} instead', |
| 839 | 'of base::Bind. (crbug.com/714018)', |
| 840 | ), |
| 841 | False, |
Erik Staab | a737d760 | 2019-11-25 18:41:07 | [diff] [blame] | 842 | (_NOT_CONVERTED_TO_MODERN_BIND_AND_CALLBACK,), |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 843 | ), |
| 844 | ( |
| 845 | r'/\bbase::Callback[<:]', |
| 846 | ( |
| 847 | 'Please use base::{Once,Repeating}Callback instead', |
| 848 | 'of base::Callback. (crbug.com/714018)', |
| 849 | ), |
| 850 | False, |
Erik Staab | a737d760 | 2019-11-25 18:41:07 | [diff] [blame] | 851 | (_NOT_CONVERTED_TO_MODERN_BIND_AND_CALLBACK,), |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 852 | ), |
| 853 | ( |
| 854 | r'/\bbase::Closure\b', |
| 855 | ( |
| 856 | 'Please use base::{Once,Repeating}Closure instead', |
| 857 | 'of base::Closure. (crbug.com/714018)', |
| 858 | ), |
| 859 | False, |
Erik Staab | a737d760 | 2019-11-25 18:41:07 | [diff] [blame] | 860 | (_NOT_CONVERTED_TO_MODERN_BIND_AND_CALLBACK,), |
danakj | 7a2b708 | 2019-05-21 21:13:51 | [diff] [blame] | 861 | ), |
| 862 | ( |
Michael Giuffrida | 7f93d692 | 2019-04-19 14:39:58 | [diff] [blame] | 863 | r'/\bRunMessageLoop\b', |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 864 | ( |
| 865 | 'RunMessageLoop is deprecated, use RunLoop instead.', |
| 866 | ), |
| 867 | False, |
| 868 | (), |
| 869 | ), |
| 870 | ( |
Dave Tapuska | 98199b61 | 2019-07-10 13:30:44 | [diff] [blame] | 871 | 'RunThisRunLoop', |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 872 | ( |
| 873 | 'RunThisRunLoop is deprecated, use RunLoop directly instead.', |
| 874 | ), |
| 875 | False, |
| 876 | (), |
| 877 | ), |
| 878 | ( |
Dave Tapuska | 98199b61 | 2019-07-10 13:30:44 | [diff] [blame] | 879 | 'RunAllPendingInMessageLoop()', |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 880 | ( |
| 881 | "Prefer RunLoop over RunAllPendingInMessageLoop, please contact gab@", |
| 882 | "if you're convinced you need this.", |
| 883 | ), |
| 884 | False, |
| 885 | (), |
| 886 | ), |
| 887 | ( |
Dave Tapuska | 98199b61 | 2019-07-10 13:30:44 | [diff] [blame] | 888 | 'RunAllPendingInMessageLoop(BrowserThread', |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 889 | ( |
| 890 | 'RunAllPendingInMessageLoop is deprecated. Use RunLoop for', |
Gabriel Charette | 798fde7 | 2019-08-20 22:24:04 | [diff] [blame] | 891 | 'BrowserThread::UI, BrowserTaskEnvironment::RunIOThreadUntilIdle', |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 892 | 'for BrowserThread::IO, and prefer RunLoop::QuitClosure to observe', |
| 893 | 'async events instead of flushing threads.', |
| 894 | ), |
| 895 | False, |
| 896 | (), |
| 897 | ), |
| 898 | ( |
| 899 | r'MessageLoopRunner', |
| 900 | ( |
| 901 | 'MessageLoopRunner is deprecated, use RunLoop instead.', |
| 902 | ), |
| 903 | False, |
| 904 | (), |
| 905 | ), |
| 906 | ( |
Dave Tapuska | 98199b61 | 2019-07-10 13:30:44 | [diff] [blame] | 907 | 'GetDeferredQuitTaskForRunLoop', |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 908 | ( |
| 909 | "GetDeferredQuitTaskForRunLoop shouldn't be needed, please contact", |
| 910 | "gab@ if you found a use case where this is the only solution.", |
| 911 | ), |
| 912 | False, |
| 913 | (), |
| 914 | ), |
| 915 | ( |
Victor Costan | e48a2e8 | 2019-03-15 22:02:34 | [diff] [blame] | 916 | 'sqlite3_initialize(', |
Victor Costan | 3653df6 | 2018-02-08 21:38:16 | [diff] [blame] | 917 | ( |
Victor Costan | e48a2e8 | 2019-03-15 22:02:34 | [diff] [blame] | 918 | 'Instead of calling sqlite3_initialize(), depend on //sql, ', |
Victor Costan | 3653df6 | 2018-02-08 21:38:16 | [diff] [blame] | 919 | '#include "sql/initialize.h" and use sql::EnsureSqliteInitialized().', |
| 920 | ), |
| 921 | True, |
| 922 | ( |
| 923 | r'^sql/initialization\.(cc|h)$', |
| 924 | r'^third_party/sqlite/.*\.(c|cc|h)$', |
| 925 | ), |
| 926 | ), |
Matt Menke | 7f520a8 | 2018-03-28 21:38:37 | [diff] [blame] | 927 | ( |
Dave Tapuska | 98199b61 | 2019-07-10 13:30:44 | [diff] [blame] | 928 | 'std::random_shuffle', |
tzik | 5de2157f | 2018-05-08 03:42:47 | [diff] [blame] | 929 | ( |
| 930 | 'std::random_shuffle is deprecated in C++14, and removed in C++17. Use', |
| 931 | 'base::RandomShuffle instead.' |
| 932 | ), |
| 933 | True, |
| 934 | (), |
| 935 | ), |
Javier Ernesto Flores Robles | 749e6c2 | 2018-10-08 09:36:24 | [diff] [blame] | 936 | ( |
| 937 | 'ios/web/public/test/http_server', |
| 938 | ( |
| 939 | 'web::HTTPserver is deprecated use net::EmbeddedTestServer instead.', |
| 940 | ), |
| 941 | False, |
| 942 | (), |
| 943 | ), |
Robert Liao | 764c949 | 2019-01-24 18:46:28 | [diff] [blame] | 944 | ( |
| 945 | 'GetAddressOf', |
| 946 | ( |
| 947 | 'Improper use of Microsoft::WRL::ComPtr<T>::GetAddressOf() has been ', |
Xiaohan Wang | fb31b4cd | 2020-07-08 01:18:53 | [diff] [blame^] | 948 | 'implicated in a few leaks. ReleaseAndGetAddressOf() is safe but ', |
| 949 | 'operator& is generally recommended. So always use operator& instead. ' |
| 950 | 'See http://crbug.com/914910 for more conversion guidance.' |
Robert Liao | 764c949 | 2019-01-24 18:46:28 | [diff] [blame] | 951 | ), |
| 952 | True, |
| 953 | (), |
| 954 | ), |
Antonio Gomes | 07300d0 | 2019-03-13 20:59:57 | [diff] [blame] | 955 | ( |
| 956 | 'DEFINE_TYPE_CASTS', |
| 957 | ( |
| 958 | 'DEFINE_TYPE_CASTS is deprecated. Instead, use downcast helpers from ', |
| 959 | '//third_party/blink/renderer/platform/casting.h.' |
| 960 | ), |
| 961 | True, |
| 962 | ( |
| 963 | r'^third_party/blink/renderer/.*\.(cc|h)$', |
| 964 | ), |
| 965 | ), |
Carlos Knippschild | ab192b8c | 2019-04-08 20:02:38 | [diff] [blame] | 966 | ( |
Abhijeet Kandalkar | 1e7c250 | 2019-10-29 15:05:45 | [diff] [blame] | 967 | r'/\bIsHTML.+Element\(\b', |
| 968 | ( |
| 969 | 'Function IsHTMLXXXXElement is deprecated. Instead, use downcast ', |
| 970 | ' helpers IsA<HTMLXXXXElement> from ', |
| 971 | '//third_party/blink/renderer/platform/casting.h.' |
| 972 | ), |
| 973 | False, |
| 974 | ( |
| 975 | r'^third_party/blink/renderer/.*\.(cc|h)$', |
| 976 | ), |
| 977 | ), |
| 978 | ( |
| 979 | r'/\bToHTML.+Element(|OrNull)\(\b', |
| 980 | ( |
| 981 | 'Function ToHTMLXXXXElement and ToHTMLXXXXElementOrNull are ' |
| 982 | 'deprecated. Instead, use downcast helpers To<HTMLXXXXElement> ' |
| 983 | 'and DynamicTo<HTMLXXXXElement> from ', |
| 984 | '//third_party/blink/renderer/platform/casting.h.' |
| 985 | 'auto* html_xxxx_ele = To<HTMLXXXXElement>(n)' |
| 986 | 'auto* html_xxxx_ele_or_null = DynamicTo<HTMLXXXXElement>(n)' |
| 987 | ), |
| 988 | False, |
| 989 | ( |
| 990 | r'^third_party/blink/renderer/.*\.(cc|h)$', |
| 991 | ), |
| 992 | ), |
| 993 | ( |
Kinuko Yasuda | 376c2ce1 | 2019-04-16 01:20:37 | [diff] [blame] | 994 | r'/\bmojo::DataPipe\b', |
Carlos Knippschild | ab192b8c | 2019-04-08 20:02:38 | [diff] [blame] | 995 | ( |
| 996 | 'mojo::DataPipe is deprecated. Use mojo::CreateDataPipe instead.', |
| 997 | ), |
| 998 | True, |
| 999 | (), |
| 1000 | ), |
Ben Lewis | a951460 | 2019-04-29 17:53:05 | [diff] [blame] | 1001 | ( |
| 1002 | 'SHFileOperation', |
| 1003 | ( |
| 1004 | 'SHFileOperation was deprecated in Windows Vista, and there are less ', |
| 1005 | 'complex functions to achieve the same goals. Use IFileOperation for ', |
| 1006 | 'any esoteric actions instead.' |
| 1007 | ), |
| 1008 | True, |
| 1009 | (), |
| 1010 | ), |
Cliff Smolinsky | b11abed | 2019-04-29 19:43:18 | [diff] [blame] | 1011 | ( |
Cliff Smolinsky | 8195164 | 2019-04-30 21:39:51 | [diff] [blame] | 1012 | 'StringFromGUID2', |
| 1013 | ( |
| 1014 | 'StringFromGUID2 introduces an unnecessary dependency on ole32.dll.', |
| 1015 | 'Use base::win::String16FromGUID instead.' |
| 1016 | ), |
| 1017 | True, |
| 1018 | ( |
| 1019 | r'/base/win/win_util_unittest.cc' |
| 1020 | ), |
| 1021 | ), |
| 1022 | ( |
| 1023 | 'StringFromCLSID', |
| 1024 | ( |
| 1025 | 'StringFromCLSID introduces an unnecessary dependency on ole32.dll.', |
| 1026 | 'Use base::win::String16FromGUID instead.' |
| 1027 | ), |
| 1028 | True, |
| 1029 | ( |
| 1030 | r'/base/win/win_util_unittest.cc' |
| 1031 | ), |
| 1032 | ), |
| 1033 | ( |
Avi Drissman | 7382afa0 | 2019-04-29 23:27:13 | [diff] [blame] | 1034 | 'kCFAllocatorNull', |
| 1035 | ( |
| 1036 | 'The use of kCFAllocatorNull with the NoCopy creation of ', |
| 1037 | 'CoreFoundation types is prohibited.', |
| 1038 | ), |
| 1039 | True, |
| 1040 | (), |
| 1041 | ), |
Oksana Zhuravlova | fd24777 | 2019-05-16 16:57:29 | [diff] [blame] | 1042 | ( |
| 1043 | 'mojo::ConvertTo', |
| 1044 | ( |
| 1045 | 'mojo::ConvertTo and TypeConverter are deprecated. Please consider', |
| 1046 | 'StructTraits / UnionTraits / EnumTraits / ArrayTraits / MapTraits /', |
| 1047 | 'StringTraits if you would like to convert between custom types and', |
| 1048 | 'the wire format of mojom types.' |
| 1049 | ), |
Oksana Zhuravlova | 1d3b59de | 2019-05-17 00:08:22 | [diff] [blame] | 1050 | False, |
Oksana Zhuravlova | fd24777 | 2019-05-16 16:57:29 | [diff] [blame] | 1051 | ( |
Wez | f89dec09 | 2019-09-11 19:38:33 | [diff] [blame] | 1052 | r'^fuchsia/engine/browser/url_request_rewrite_rules_manager\.cc$', |
| 1053 | r'^fuchsia/engine/url_request_rewrite_type_converters\.cc$', |
Oksana Zhuravlova | fd24777 | 2019-05-16 16:57:29 | [diff] [blame] | 1054 | r'^third_party/blink/.*\.(cc|h)$', |
| 1055 | r'^content/renderer/.*\.(cc|h)$', |
| 1056 | ), |
| 1057 | ), |
Robert Liao | 1d78df5 | 2019-11-11 20:02:01 | [diff] [blame] | 1058 | ( |
Oksana Zhuravlova | c8222d2 | 2019-12-19 19:21:16 | [diff] [blame] | 1059 | 'GetInterfaceProvider', |
| 1060 | ( |
| 1061 | 'InterfaceProvider is deprecated.', |
| 1062 | 'Please use ExecutionContext::GetBrowserInterfaceBroker and overrides', |
| 1063 | 'or Platform::GetBrowserInterfaceBroker.' |
| 1064 | ), |
| 1065 | False, |
| 1066 | (), |
| 1067 | ), |
| 1068 | ( |
Robert Liao | 1d78df5 | 2019-11-11 20:02:01 | [diff] [blame] | 1069 | 'CComPtr', |
| 1070 | ( |
| 1071 | 'New code should use Microsoft::WRL::ComPtr from wrl/client.h as a ', |
| 1072 | 'replacement for CComPtr from ATL. See http://crbug.com/5027 for more ', |
| 1073 | 'details.' |
| 1074 | ), |
| 1075 | False, |
| 1076 | (), |
| 1077 | ), |
Xiaohan Wang | 72bd2ba | 2020-02-18 21:38:20 | [diff] [blame] | 1078 | ( |
| 1079 | r'/\b(IFACE|STD)METHOD_?\(', |
| 1080 | ( |
| 1081 | 'IFACEMETHOD() and STDMETHOD() make code harder to format and read.', |
| 1082 | 'Instead, always use IFACEMETHODIMP in the declaration.' |
| 1083 | ), |
| 1084 | False, |
| 1085 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 1086 | ), |
Allen Bauer | 53b43fb1 | 2020-03-12 17:21:47 | [diff] [blame] | 1087 | ( |
| 1088 | 'set_owned_by_client', |
| 1089 | ( |
| 1090 | 'set_owned_by_client is deprecated.', |
| 1091 | 'views::View already owns the child views by default. This introduces ', |
| 1092 | 'a competing ownership model which makes the code difficult to reason ', |
| 1093 | 'about. See http://crbug.com/1044687 for more details.' |
| 1094 | ), |
| 1095 | False, |
| 1096 | (), |
| 1097 | ), |
Eric Seckler | be6f48d | 2020-05-06 18:09:12 | [diff] [blame] | 1098 | ( |
| 1099 | r'/\bTRACE_EVENT_ASYNC_', |
| 1100 | ( |
| 1101 | 'Please use TRACE_EVENT_NESTABLE_ASYNC_.. macros instead', |
| 1102 | 'of TRACE_EVENT_ASYNC_.. (crbug.com/1038710).', |
| 1103 | ), |
| 1104 | False, |
| 1105 | ( |
| 1106 | r'^base/trace_event/.*', |
| 1107 | r'^base/tracing/.*', |
| 1108 | ), |
| 1109 | ), |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1110 | ) |
| 1111 | |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1112 | # Format: Sequence of tuples containing: |
| 1113 | # * String pattern or, if starting with a slash, a regular expression. |
| 1114 | # * Sequence of strings to show when the pattern matches. |
| 1115 | _DEPRECATED_MOJO_TYPES = ( |
| 1116 | ( |
| 1117 | r'/\bmojo::AssociatedBinding\b', |
| 1118 | ( |
| 1119 | 'mojo::AssociatedBinding<Interface> is deprecated.', |
| 1120 | 'Use mojo::AssociatedReceiver<Interface> instead.', |
| 1121 | ), |
| 1122 | ), |
| 1123 | ( |
| 1124 | r'/\bmojo::AssociatedBindingSet\b', |
| 1125 | ( |
| 1126 | 'mojo::AssociatedBindingSet<Interface> is deprecated.', |
| 1127 | 'Use mojo::AssociatedReceiverSet<Interface> instead.', |
| 1128 | ), |
| 1129 | ), |
| 1130 | ( |
| 1131 | r'/\bmojo::AssociatedInterfacePtr\b', |
| 1132 | ( |
| 1133 | 'mojo::AssociatedInterfacePtr<Interface> is deprecated.', |
| 1134 | 'Use mojo::AssociatedRemote<Interface> instead.', |
| 1135 | ), |
| 1136 | ), |
| 1137 | ( |
| 1138 | r'/\bmojo::AssociatedInterfacePtrInfo\b', |
| 1139 | ( |
| 1140 | 'mojo::AssociatedInterfacePtrInfo<Interface> is deprecated.', |
| 1141 | 'Use mojo::PendingAssociatedRemote<Interface> instead.', |
| 1142 | ), |
| 1143 | ), |
| 1144 | ( |
| 1145 | r'/\bmojo::AssociatedInterfaceRequest\b', |
| 1146 | ( |
| 1147 | 'mojo::AssociatedInterfaceRequest<Interface> is deprecated.', |
| 1148 | 'Use mojo::PendingAssociatedReceiver<Interface> instead.', |
| 1149 | ), |
| 1150 | ), |
| 1151 | ( |
| 1152 | r'/\bmojo::Binding\b', |
| 1153 | ( |
| 1154 | 'mojo::Binding<Interface> is deprecated.', |
| 1155 | 'Use mojo::Receiver<Interface> instead.', |
| 1156 | ), |
| 1157 | ), |
| 1158 | ( |
| 1159 | r'/\bmojo::BindingSet\b', |
| 1160 | ( |
| 1161 | 'mojo::BindingSet<Interface> is deprecated.', |
| 1162 | 'Use mojo::ReceiverSet<Interface> instead.', |
| 1163 | ), |
| 1164 | ), |
| 1165 | ( |
| 1166 | r'/\bmojo::InterfacePtr\b', |
| 1167 | ( |
| 1168 | 'mojo::InterfacePtr<Interface> is deprecated.', |
| 1169 | 'Use mojo::Remote<Interface> instead.', |
| 1170 | ), |
| 1171 | ), |
| 1172 | ( |
| 1173 | r'/\bmojo::InterfacePtrInfo\b', |
| 1174 | ( |
| 1175 | 'mojo::InterfacePtrInfo<Interface> is deprecated.', |
| 1176 | 'Use mojo::PendingRemote<Interface> instead.', |
| 1177 | ), |
| 1178 | ), |
| 1179 | ( |
| 1180 | r'/\bmojo::InterfaceRequest\b', |
| 1181 | ( |
| 1182 | 'mojo::InterfaceRequest<Interface> is deprecated.', |
| 1183 | 'Use mojo::PendingReceiver<Interface> instead.', |
| 1184 | ), |
| 1185 | ), |
| 1186 | ( |
| 1187 | r'/\bmojo::MakeRequest\b', |
| 1188 | ( |
| 1189 | 'mojo::MakeRequest is deprecated.', |
| 1190 | 'Use mojo::Remote::BindNewPipeAndPassReceiver() instead.', |
| 1191 | ), |
| 1192 | ), |
| 1193 | ( |
| 1194 | r'/\bmojo::MakeRequestAssociatedWithDedicatedPipe\b', |
| 1195 | ( |
| 1196 | 'mojo::MakeRequest is deprecated.', |
| 1197 | 'Use mojo::AssociatedRemote::' |
| 1198 | 'BindNewEndpointAndPassDedicatedReceiverForTesting() instead.', |
| 1199 | ), |
| 1200 | ), |
| 1201 | ( |
| 1202 | r'/\bmojo::MakeStrongBinding\b', |
| 1203 | ( |
| 1204 | 'mojo::MakeStrongBinding is deprecated.', |
| 1205 | 'Either migrate to mojo::UniqueReceiverSet, if possible, or use', |
| 1206 | 'mojo::MakeSelfOwnedReceiver() instead.', |
| 1207 | ), |
| 1208 | ), |
| 1209 | ( |
| 1210 | r'/\bmojo::MakeStrongAssociatedBinding\b', |
| 1211 | ( |
| 1212 | 'mojo::MakeStrongAssociatedBinding is deprecated.', |
| 1213 | 'Either migrate to mojo::UniqueAssociatedReceiverSet, if possible, or', |
| 1214 | 'use mojo::MakeSelfOwnedAssociatedReceiver() instead.', |
| 1215 | ), |
| 1216 | ), |
| 1217 | ( |
Gyuyoung Kim | 4952ba6 | 2020-07-07 07:33:44 | [diff] [blame] | 1218 | r'/\bmojo::StrongAssociatedBinding\b', |
| 1219 | ( |
| 1220 | 'mojo::StrongAssociatedBinding<Interface> is deprecated.', |
| 1221 | 'Use mojo::MakeSelfOwnedAssociatedReceiver<Interface> instead.', |
| 1222 | ), |
| 1223 | ), |
| 1224 | ( |
| 1225 | r'/\bmojo::StrongBinding\b', |
| 1226 | ( |
| 1227 | 'mojo::StrongBinding<Interface> is deprecated.', |
| 1228 | 'Use mojo::MakeSelfOwnedReceiver<Interface> instead.', |
| 1229 | ), |
| 1230 | ), |
| 1231 | ( |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1232 | r'/\bmojo::StrongAssociatedBindingSet\b', |
| 1233 | ( |
| 1234 | 'mojo::StrongAssociatedBindingSet<Interface> is deprecated.', |
| 1235 | 'Use mojo::UniqueAssociatedReceiverSet<Interface> instead.', |
| 1236 | ), |
| 1237 | ), |
| 1238 | ( |
| 1239 | r'/\bmojo::StrongBindingSet\b', |
| 1240 | ( |
| 1241 | 'mojo::StrongBindingSet<Interface> is deprecated.', |
| 1242 | 'Use mojo::UniqueReceiverSet<Interface> instead.', |
| 1243 | ), |
| 1244 | ), |
| 1245 | ) |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1246 | |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 1247 | _IPC_ENUM_TRAITS_DEPRECATED = ( |
| 1248 | 'You are using IPC_ENUM_TRAITS() in your code. It has been deprecated.\n' |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 1249 | 'See http://www.chromium.org/Home/chromium-security/education/' |
| 1250 | 'security-tips-for-ipc') |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 1251 | |
Stephen Martinis | 97a39414 | 2018-06-07 23:06:05 | [diff] [blame] | 1252 | _LONG_PATH_ERROR = ( |
| 1253 | 'Some files included in this CL have file names that are too long (> 200' |
| 1254 | ' characters). If committed, these files will cause issues on Windows. See' |
| 1255 | ' https://crbug.com/612667 for more details.' |
| 1256 | ) |
| 1257 | |
Shenghua Zhang | bfaa38b8 | 2017-11-16 21:58:02 | [diff] [blame] | 1258 | _JAVA_MULTIPLE_DEFINITION_EXCLUDED_PATHS = [ |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1259 | r".*[\\/]BuildHooksAndroidImpl\.java", |
| 1260 | r".*[\\/]LicenseContentProvider\.java", |
| 1261 | r".*[\\/]PlatformServiceBridgeImpl.java", |
Patrick Noland | 5475bc0d | 2018-10-01 20:04:28 | [diff] [blame] | 1262 | r".*chrome[\\\/]android[\\\/]feed[\\\/]dummy[\\\/].*\.java", |
Shenghua Zhang | bfaa38b8 | 2017-11-16 21:58:02 | [diff] [blame] | 1263 | ] |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1264 | |
Mohamed Heikal | d048240a | 2019-11-12 16:57:37 | [diff] [blame] | 1265 | # List of image extensions that are used as resources in chromium. |
| 1266 | _IMAGE_EXTENSIONS = ['.svg', '.png', '.webp'] |
| 1267 | |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 1268 | # These paths contain test data and other known invalid JSON files. |
Erik Staab | 2dd72b1 | 2020-04-16 15:03:40 | [diff] [blame] | 1269 | _KNOWN_TEST_DATA_AND_INVALID_JSON_FILE_PATTERNS = [ |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1270 | r'test[\\/]data[\\/]', |
Erik Staab | 2dd72b1 | 2020-04-16 15:03:40 | [diff] [blame] | 1271 | r'testing[\\/]buildbot[\\/]', |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1272 | r'^components[\\/]policy[\\/]resources[\\/]policy_templates\.json$', |
| 1273 | r'^third_party[\\/]protobuf[\\/]', |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1274 | r'^third_party[\\/]blink[\\/]renderer[\\/]devtools[\\/]protocol\.json$', |
Kent Tamura | 77578cc | 2018-11-25 22:33:43 | [diff] [blame] | 1275 | r'^third_party[\\/]blink[\\/]web_tests[\\/]external[\\/]wpt[\\/]', |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 1276 | ] |
| 1277 | |
| 1278 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1279 | _VALID_OS_MACROS = ( |
| 1280 | # Please keep sorted. |
rayb | 0088ee5 | 2017-04-26 22:35:08 | [diff] [blame] | 1281 | 'OS_AIX', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1282 | 'OS_ANDROID', |
Henrique Nakashima | afff050 | 2018-01-24 17:14:12 | [diff] [blame] | 1283 | 'OS_ASMJS', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1284 | 'OS_BSD', |
| 1285 | 'OS_CAT', # For testing. |
| 1286 | 'OS_CHROMEOS', |
Eugene Kliuchnikov | b99125c | 2018-11-26 17:33:04 | [diff] [blame] | 1287 | 'OS_CYGWIN', # third_party code. |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1288 | 'OS_FREEBSD', |
scottmg | 2f97ee12 | 2017-05-12 17:50:37 | [diff] [blame] | 1289 | 'OS_FUCHSIA', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1290 | 'OS_IOS', |
| 1291 | 'OS_LINUX', |
| 1292 | 'OS_MACOSX', |
| 1293 | 'OS_NACL', |
hidehiko | f7295f2 | 2014-10-28 11:57:21 | [diff] [blame] | 1294 | 'OS_NACL_NONSFI', |
| 1295 | 'OS_NACL_SFI', |
krytarowski | 969759f | 2016-07-31 23:55:12 | [diff] [blame] | 1296 | 'OS_NETBSD', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1297 | 'OS_OPENBSD', |
| 1298 | 'OS_POSIX', |
[email protected] | eda7afa1 | 2014-02-06 12:27:37 | [diff] [blame] | 1299 | 'OS_QNX', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1300 | 'OS_SOLARIS', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1301 | 'OS_WIN', |
| 1302 | ) |
| 1303 | |
| 1304 | |
Andrew Grieve | b773bad | 2020-06-05 18:00:38 | [diff] [blame] | 1305 | # These are not checked on the public chromium-presubmit trybot. |
| 1306 | # Add files here that rely on .py files that exists only for target_os="android" |
| 1307 | # checkouts (e.g. //third_party/catapult). |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 1308 | _ANDROID_SPECIFIC_PYDEPS_FILES = [ |
Andrew Luo | b2e4b34 | 2018-09-20 19:32:39 | [diff] [blame] | 1309 | 'android_webview/tools/run_cts.pydeps', |
Andrew Grieve | b773bad | 2020-06-05 18:00:38 | [diff] [blame] | 1310 | 'build/android/devil_chromium.pydeps', |
| 1311 | 'build/android/gyp/create_bundle_wrapper_script.pydeps', |
| 1312 | 'build/android/gyp/jinja_template.pydeps', |
| 1313 | 'build/android/resource_sizes.pydeps', |
| 1314 | 'build/android/test_runner.pydeps', |
| 1315 | 'build/android/test_wrapper/logdog_wrapper.pydeps', |
| 1316 | 'chrome/android/features/create_stripped_java_factory.pydeps', |
| 1317 | 'testing/scripts/run_android_wpt.pydeps', |
| 1318 | 'third_party/android_platform/development/scripts/stack.pydeps', |
| 1319 | ] |
| 1320 | |
| 1321 | |
| 1322 | _GENERIC_PYDEPS_FILES = [ |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1323 | 'base/android/jni_generator/jni_generator.pydeps', |
| 1324 | 'base/android/jni_generator/jni_registration_generator.pydeps', |
| 1325 | 'build/android/gyp/aar.pydeps', |
| 1326 | 'build/android/gyp/aidl.pydeps', |
Tibor Goldschwendt | 0bef2d7a | 2019-10-24 21:19:27 | [diff] [blame] | 1327 | 'build/android/gyp/allot_native_libraries.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1328 | 'build/android/gyp/apkbuilder.pydeps', |
Andrew Grieve | a417ad30 | 2019-02-06 19:54:38 | [diff] [blame] | 1329 | 'build/android/gyp/assert_static_initializers.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1330 | 'build/android/gyp/bytecode_processor.pydeps', |
Andrew Grieve | 8d083ea | 2019-12-13 06:49:11 | [diff] [blame] | 1331 | 'build/android/gyp/compile_java.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1332 | 'build/android/gyp/compile_resources.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1333 | 'build/android/gyp/copy_ex.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1334 | 'build/android/gyp/create_apk_operations_script.pydeps', |
Andrew Grieve | 8d083ea | 2019-12-13 06:49:11 | [diff] [blame] | 1335 | 'build/android/gyp/create_app_bundle_apks.pydeps', |
| 1336 | 'build/android/gyp/create_app_bundle.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1337 | 'build/android/gyp/create_java_binary_script.pydeps', |
Andrew Grieve | b838d83 | 2019-02-11 16:55:22 | [diff] [blame] | 1338 | 'build/android/gyp/create_size_info_files.pydeps', |
Andrew Grieve | 5a01ad3 | 2020-06-25 18:06:00 | [diff] [blame] | 1339 | 'build/android/gyp/create_ui_locale_resources.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1340 | 'build/android/gyp/desugar.pydeps', |
Sam Maier | 3599daa | 2018-11-26 18:02:59 | [diff] [blame] | 1341 | 'build/android/gyp/dexsplitter.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1342 | 'build/android/gyp/dex.pydeps', |
Andrew Grieve | 723c150 | 2020-04-23 16:27:42 | [diff] [blame] | 1343 | 'build/android/gyp/dex_jdk_libs.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1344 | 'build/android/gyp/dist_aar.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1345 | 'build/android/gyp/filter_zip.pydeps', |
| 1346 | 'build/android/gyp/gcc_preprocess.pydeps', |
Christopher Grant | 99e0e2006 | 2018-11-21 21:22:36 | [diff] [blame] | 1347 | 'build/android/gyp/generate_linker_version_script.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1348 | 'build/android/gyp/ijar.pydeps', |
Yun Liu | eb4075ddf | 2019-05-13 19:47:58 | [diff] [blame] | 1349 | 'build/android/gyp/jacoco_instr.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1350 | 'build/android/gyp/java_cpp_enum.pydeps', |
Ian Vollick | b99472e | 2019-03-07 21:35:26 | [diff] [blame] | 1351 | 'build/android/gyp/java_cpp_strings.pydeps', |
Andrew Grieve | 5853fbd | 2020-02-20 17:26:01 | [diff] [blame] | 1352 | 'build/android/gyp/jetify_jar.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1353 | 'build/android/gyp/lint.pydeps', |
| 1354 | 'build/android/gyp/main_dex_list.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1355 | 'build/android/gyp/merge_manifest.pydeps', |
| 1356 | 'build/android/gyp/prepare_resources.pydeps', |
| 1357 | 'build/android/gyp/proguard.pydeps', |
Peter Wen | 578730b | 2020-03-19 19:55:46 | [diff] [blame] | 1358 | 'build/android/gyp/turbine.pydeps', |
Eric Stevenson | a82cf608 | 2019-07-24 14:35:24 | [diff] [blame] | 1359 | 'build/android/gyp/validate_static_library_dex_references.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1360 | 'build/android/gyp/write_build_config.pydeps', |
Tibor Goldschwendt | c4caae9 | 2019-07-12 00:33:46 | [diff] [blame] | 1361 | 'build/android/gyp/write_native_libraries_java.pydeps', |
Andrew Grieve | 9ff1779 | 2018-11-30 04:55:56 | [diff] [blame] | 1362 | 'build/android/gyp/zip.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1363 | 'build/android/incremental_install/generate_android_manifest.pydeps', |
| 1364 | 'build/android/incremental_install/write_installer_json.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 1365 | 'build/protoc_java.pydeps', |
Peter Wen | efb56c7 | 2020-06-04 15:12:27 | [diff] [blame] | 1366 | 'chrome/test/chromedriver/log_replay/client_replay_unittest.pydeps', |
| 1367 | 'chrome/test/chromedriver/test/run_py_tests.pydeps', |
Andrew Grieve | 5a01ad3 | 2020-06-25 18:06:00 | [diff] [blame] | 1368 | 'components/cronet/tools/generate_javadoc.pydeps', |
| 1369 | 'components/cronet/tools/jar_src.pydeps', |
Andrew Grieve | b773bad | 2020-06-05 18:00:38 | [diff] [blame] | 1370 | 'components/module_installer/android/module_desc_java.pydeps', |
Andrew Grieve | 5a01ad3 | 2020-06-25 18:06:00 | [diff] [blame] | 1371 | 'content/public/android/generate_child_service.pydeps', |
Andrew Grieve | b773bad | 2020-06-05 18:00:38 | [diff] [blame] | 1372 | 'net/tools/testserver/testserver.pydeps', |
Hitoshi Yoshida | 0f228c4 | 2019-08-07 09:37:42 | [diff] [blame] | 1373 | 'third_party/blink/renderer/bindings/scripts/build_web_idl_database.pydeps', |
| 1374 | 'third_party/blink/renderer/bindings/scripts/collect_idl_files.pydeps', |
Yuki Shiino | e7827aa | 2019-09-13 12:26:13 | [diff] [blame] | 1375 | 'third_party/blink/renderer/bindings/scripts/generate_bindings.pydeps', |
Caleb Raitto | 28864fc | 2020-01-07 00:18:19 | [diff] [blame] | 1376 | ('third_party/blink/renderer/bindings/scripts/' |
| 1377 | 'generate_high_entropy_list.pydeps'), |
John Budorick | bc3571aa | 2019-04-25 02:20:06 | [diff] [blame] | 1378 | 'tools/binary_size/sizes.pydeps', |
Andrew Grieve | a7f1ee90 | 2018-05-18 16:17:22 | [diff] [blame] | 1379 | 'tools/binary_size/supersize.pydeps', |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 1380 | ] |
| 1381 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1382 | |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 1383 | _ALL_PYDEPS_FILES = _ANDROID_SPECIFIC_PYDEPS_FILES + _GENERIC_PYDEPS_FILES |
| 1384 | |
| 1385 | |
Eric Boren | 6fd2b93 | 2018-01-25 15:05:08 | [diff] [blame] | 1386 | # Bypass the AUTHORS check for these accounts. |
| 1387 | _KNOWN_ROBOTS = set( |
Sergiy Byelozyorov | 47158a5 | 2018-06-13 22:38:59 | [diff] [blame] | 1388 | ) | set('%[email protected]' % s for s in ('findit-for-me',) |
Achuith Bhandarkar | 3590556 | 2018-07-25 19:28:45 | [diff] [blame] | 1389 | ) | set('%[email protected]' % s for s in ('3su6n15k.default',) |
Sergiy Byelozyorov | 47158a5 | 2018-06-13 22:38:59 | [diff] [blame] | 1390 | ) | set('%[email protected]' % s |
smut | de79705 | 2019-12-04 02:03:52 | [diff] [blame] | 1391 | for s in ('bling-autoroll-builder', 'v8-ci-autoroll-builder', |
| 1392 | 'wpt-autoroller',) |
Eric Boren | 835d71f | 2018-09-07 21:09:04 | [diff] [blame] | 1393 | ) | set('%[email protected]' % s |
Eric Boren | 66150e5 | 2020-01-08 11:20:27 | [diff] [blame] | 1394 | for s in ('chromium-autoroll', 'chromium-release-autoroll') |
Eric Boren | 835d71f | 2018-09-07 21:09:04 | [diff] [blame] | 1395 | ) | set('%[email protected]' % s |
Eric Boren | 2b7e3c3c | 2018-09-13 18:14:30 | [diff] [blame] | 1396 | for s in ('chromium-internal-autoroll',)) |
Eric Boren | 6fd2b93 | 2018-01-25 15:05:08 | [diff] [blame] | 1397 | |
| 1398 | |
Daniel Bratell | 65b03326 | 2019-04-23 08:17:06 | [diff] [blame] | 1399 | def _IsCPlusPlusFile(input_api, file_path): |
| 1400 | """Returns True if this file contains C++-like code (and not Python, |
| 1401 | Go, Java, MarkDown, ...)""" |
| 1402 | |
| 1403 | ext = input_api.os_path.splitext(file_path)[1] |
| 1404 | # This list is compatible with CppChecker.IsCppFile but we should |
| 1405 | # consider adding ".c" to it. If we do that we can use this function |
| 1406 | # at more places in the code. |
| 1407 | return ext in ( |
| 1408 | '.h', |
| 1409 | '.cc', |
| 1410 | '.cpp', |
| 1411 | '.m', |
| 1412 | '.mm', |
| 1413 | ) |
| 1414 | |
| 1415 | def _IsCPlusPlusHeaderFile(input_api, file_path): |
| 1416 | return input_api.os_path.splitext(file_path)[1] == ".h" |
| 1417 | |
| 1418 | |
| 1419 | def _IsJavaFile(input_api, file_path): |
| 1420 | return input_api.os_path.splitext(file_path)[1] == ".java" |
| 1421 | |
| 1422 | |
| 1423 | def _IsProtoFile(input_api, file_path): |
| 1424 | return input_api.os_path.splitext(file_path)[1] == ".proto" |
| 1425 | |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1426 | def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): |
| 1427 | """Attempts to prevent use of functions intended only for testing in |
| 1428 | non-testing code. For now this is just a best-effort implementation |
| 1429 | that ignores header files and may have some false positives. A |
| 1430 | better implementation would probably need a proper C++ parser. |
| 1431 | """ |
| 1432 | # We only scan .cc files and the like, as the declaration of |
| 1433 | # for-testing functions in header files are hard to distinguish from |
| 1434 | # calls to such functions without a proper C++ parser. |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1435 | file_inclusion_pattern = [r'.+%s' % _IMPLEMENTATION_EXTENSIONS] |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1436 | |
jochen | c0d4808c | 2015-07-27 09:25:42 | [diff] [blame] | 1437 | base_function_pattern = r'[ :]test::[^\s]+|ForTest(s|ing)?|for_test(s|ing)?' |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1438 | inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern) |
[email protected] | 2350182 | 2014-05-14 02:06:09 | [diff] [blame] | 1439 | comment_pattern = input_api.re.compile(r'//.*(%s)' % base_function_pattern) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1440 | exclusion_pattern = input_api.re.compile( |
| 1441 | r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % ( |
| 1442 | base_function_pattern, base_function_pattern)) |
| 1443 | |
| 1444 | def FilterFile(affected_file): |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1445 | black_list = (_EXCLUDED_PATHS + |
| 1446 | _TEST_CODE_EXCLUDED_PATHS + |
| 1447 | input_api.DEFAULT_BLACK_LIST) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1448 | return input_api.FilterSourceFile( |
| 1449 | affected_file, |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1450 | white_list=file_inclusion_pattern, |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1451 | black_list=black_list) |
| 1452 | |
| 1453 | problems = [] |
| 1454 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 1455 | local_path = f.LocalPath() |
[email protected] | 825d2718 | 2014-01-02 21:24:24 | [diff] [blame] | 1456 | for line_number, line in f.ChangedContents(): |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 1457 | if (inclusion_pattern.search(line) and |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 1458 | not comment_pattern.search(line) and |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 1459 | not exclusion_pattern.search(line)): |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1460 | problems.append( |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 1461 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1462 | |
| 1463 | if problems: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 1464 | return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 1465 | else: |
| 1466 | return [] |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1467 | |
| 1468 | |
Vaclav Brozek | 7dbc28c | 2018-03-27 08:35:23 | [diff] [blame] | 1469 | def _CheckNoProductionCodeUsingTestOnlyFunctionsJava(input_api, output_api): |
| 1470 | """This is a simplified version of |
| 1471 | _CheckNoProductionCodeUsingTestOnlyFunctions for Java files. |
| 1472 | """ |
| 1473 | javadoc_start_re = input_api.re.compile(r'^\s*/\*\*') |
| 1474 | javadoc_end_re = input_api.re.compile(r'^\s*\*/') |
| 1475 | name_pattern = r'ForTest(s|ing)?' |
| 1476 | # Describes an occurrence of "ForTest*" inside a // comment. |
| 1477 | comment_re = input_api.re.compile(r'//.*%s' % name_pattern) |
| 1478 | # Catch calls. |
| 1479 | inclusion_re = input_api.re.compile(r'(%s)\s*\(' % name_pattern) |
| 1480 | # Ignore definitions. (Comments are ignored separately.) |
| 1481 | exclusion_re = input_api.re.compile(r'(%s)[^;]+\{' % name_pattern) |
| 1482 | |
| 1483 | problems = [] |
| 1484 | sources = lambda x: input_api.FilterSourceFile( |
| 1485 | x, |
| 1486 | black_list=(('(?i).*test', r'.*\/junit\/') |
| 1487 | + input_api.DEFAULT_BLACK_LIST), |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1488 | white_list=[r'.*\.java$'] |
Vaclav Brozek | 7dbc28c | 2018-03-27 08:35:23 | [diff] [blame] | 1489 | ) |
| 1490 | for f in input_api.AffectedFiles(include_deletes=False, file_filter=sources): |
| 1491 | local_path = f.LocalPath() |
| 1492 | is_inside_javadoc = False |
| 1493 | for line_number, line in f.ChangedContents(): |
| 1494 | if is_inside_javadoc and javadoc_end_re.search(line): |
| 1495 | is_inside_javadoc = False |
| 1496 | if not is_inside_javadoc and javadoc_start_re.search(line): |
| 1497 | is_inside_javadoc = True |
| 1498 | if is_inside_javadoc: |
| 1499 | continue |
| 1500 | if (inclusion_re.search(line) and |
| 1501 | not comment_re.search(line) and |
| 1502 | not exclusion_re.search(line)): |
| 1503 | problems.append( |
| 1504 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
| 1505 | |
| 1506 | if problems: |
| 1507 | return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)] |
| 1508 | else: |
| 1509 | return [] |
| 1510 | |
| 1511 | |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 1512 | def _CheckNoIOStreamInHeaders(input_api, output_api): |
| 1513 | """Checks to make sure no .h files include <iostream>.""" |
| 1514 | files = [] |
| 1515 | pattern = input_api.re.compile(r'^#include\s*<iostream>', |
| 1516 | input_api.re.MULTILINE) |
| 1517 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 1518 | if not f.LocalPath().endswith('.h'): |
| 1519 | continue |
| 1520 | contents = input_api.ReadFile(f) |
| 1521 | if pattern.search(contents): |
| 1522 | files.append(f) |
| 1523 | |
| 1524 | if len(files): |
yolandyan | daabc6d | 2016-04-18 18:29:39 | [diff] [blame] | 1525 | return [output_api.PresubmitError( |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 1526 | 'Do not #include <iostream> in header files, since it inserts static ' |
| 1527 | 'initialization into every file including the header. Instead, ' |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 1528 | '#include <ostream>. See http://crbug.com/94794', |
| 1529 | files) ] |
| 1530 | return [] |
| 1531 | |
Danil Chapovalov | 3518f36 | 2018-08-11 16:13:43 | [diff] [blame] | 1532 | def _CheckNoStrCatRedefines(input_api, output_api): |
| 1533 | """Checks no windows headers with StrCat redefined are included directly.""" |
| 1534 | files = [] |
| 1535 | pattern_deny = input_api.re.compile( |
| 1536 | r'^#include\s*[<"](shlwapi|atlbase|propvarutil|sphelper).h[">]', |
| 1537 | input_api.re.MULTILINE) |
| 1538 | pattern_allow = input_api.re.compile( |
| 1539 | r'^#include\s"base/win/windows_defines.inc"', |
| 1540 | input_api.re.MULTILINE) |
| 1541 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 1542 | contents = input_api.ReadFile(f) |
| 1543 | if pattern_deny.search(contents) and not pattern_allow.search(contents): |
| 1544 | files.append(f.LocalPath()) |
| 1545 | |
| 1546 | if len(files): |
| 1547 | return [output_api.PresubmitError( |
| 1548 | 'Do not #include shlwapi.h, atlbase.h, propvarutil.h or sphelper.h ' |
| 1549 | 'directly since they pollute code with StrCat macro. Instead, ' |
| 1550 | 'include matching header from base/win. See http://crbug.com/856536', |
| 1551 | files) ] |
| 1552 | return [] |
| 1553 | |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 1554 | |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 1555 | def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api): |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 1556 | """Checks to make sure no source files use UNIT_TEST.""" |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 1557 | problems = [] |
| 1558 | for f in input_api.AffectedFiles(): |
| 1559 | if (not f.LocalPath().endswith(('.cc', '.mm'))): |
| 1560 | continue |
| 1561 | |
| 1562 | for line_num, line in f.ChangedContents(): |
[email protected] | 549f86a | 2013-11-19 13:00:04 | [diff] [blame] | 1563 | if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 1564 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 1565 | |
| 1566 | if not problems: |
| 1567 | return [] |
| 1568 | return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + |
| 1569 | '\n'.join(problems))] |
| 1570 | |
Dominic Battre | 03353105 | 2018-09-24 15:45:34 | [diff] [blame] | 1571 | def _CheckNoDISABLETypoInTests(input_api, output_api): |
| 1572 | """Checks to prevent attempts to disable tests with DISABLE_ prefix. |
| 1573 | |
| 1574 | This test warns if somebody tries to disable a test with the DISABLE_ prefix |
| 1575 | instead of DISABLED_. To filter false positives, reports are only generated |
| 1576 | if a corresponding MAYBE_ line exists. |
| 1577 | """ |
| 1578 | problems = [] |
| 1579 | |
| 1580 | # The following two patterns are looked for in tandem - is a test labeled |
| 1581 | # as MAYBE_ followed by a DISABLE_ (instead of the correct DISABLED) |
| 1582 | maybe_pattern = input_api.re.compile(r'MAYBE_([a-zA-Z0-9_]+)') |
| 1583 | disable_pattern = input_api.re.compile(r'DISABLE_([a-zA-Z0-9_]+)') |
| 1584 | |
| 1585 | # This is for the case that a test is disabled on all platforms. |
| 1586 | full_disable_pattern = input_api.re.compile( |
| 1587 | r'^\s*TEST[^(]*\([a-zA-Z0-9_]+,\s*DISABLE_[a-zA-Z0-9_]+\)', |
| 1588 | input_api.re.MULTILINE) |
| 1589 | |
Katie D | f13948e | 2018-09-25 07:33:44 | [diff] [blame] | 1590 | for f in input_api.AffectedFiles(False): |
Dominic Battre | 03353105 | 2018-09-24 15:45:34 | [diff] [blame] | 1591 | if not 'test' in f.LocalPath() or not f.LocalPath().endswith('.cc'): |
| 1592 | continue |
| 1593 | |
| 1594 | # Search for MABYE_, DISABLE_ pairs. |
| 1595 | disable_lines = {} # Maps of test name to line number. |
| 1596 | maybe_lines = {} |
| 1597 | for line_num, line in f.ChangedContents(): |
| 1598 | disable_match = disable_pattern.search(line) |
| 1599 | if disable_match: |
| 1600 | disable_lines[disable_match.group(1)] = line_num |
| 1601 | maybe_match = maybe_pattern.search(line) |
| 1602 | if maybe_match: |
| 1603 | maybe_lines[maybe_match.group(1)] = line_num |
| 1604 | |
| 1605 | # Search for DISABLE_ occurrences within a TEST() macro. |
| 1606 | disable_tests = set(disable_lines.keys()) |
| 1607 | maybe_tests = set(maybe_lines.keys()) |
| 1608 | for test in disable_tests.intersection(maybe_tests): |
| 1609 | problems.append(' %s:%d' % (f.LocalPath(), disable_lines[test])) |
| 1610 | |
| 1611 | contents = input_api.ReadFile(f) |
| 1612 | full_disable_match = full_disable_pattern.search(contents) |
| 1613 | if full_disable_match: |
| 1614 | problems.append(' %s' % f.LocalPath()) |
| 1615 | |
| 1616 | if not problems: |
| 1617 | return [] |
| 1618 | return [ |
| 1619 | output_api.PresubmitPromptWarning( |
| 1620 | 'Attempt to disable a test with DISABLE_ instead of DISABLED_?\n' + |
| 1621 | '\n'.join(problems)) |
| 1622 | ] |
| 1623 | |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 1624 | |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 1625 | def _CheckDCHECK_IS_ONHasBraces(input_api, output_api): |
kjellander | aee30663 | 2017-02-22 19:26:57 | [diff] [blame] | 1626 | """Checks to make sure DCHECK_IS_ON() does not skip the parentheses.""" |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 1627 | errors = [] |
Hans Wennborg | 944479f | 2020-06-25 21:39:25 | [diff] [blame] | 1628 | pattern = input_api.re.compile(r'DCHECK_IS_ON\b(?!\(\))', |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 1629 | input_api.re.MULTILINE) |
| 1630 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 1631 | if (not f.LocalPath().endswith(('.cc', '.mm', '.h'))): |
| 1632 | continue |
| 1633 | for lnum, line in f.ChangedContents(): |
| 1634 | if input_api.re.search(pattern, line): |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 1635 | errors.append(output_api.PresubmitError( |
| 1636 | ('%s:%d: Use of DCHECK_IS_ON() must be written as "#if ' + |
kjellander | aee30663 | 2017-02-22 19:26:57 | [diff] [blame] | 1637 | 'DCHECK_IS_ON()", not forgetting the parentheses.') |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 1638 | % (f.LocalPath(), lnum))) |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 1639 | return errors |
| 1640 | |
| 1641 | |
Makoto Shimazu | 3ad422cd | 2019-05-08 02:35:14 | [diff] [blame] | 1642 | def _FindHistogramNameInChunk(histogram_name, chunk): |
| 1643 | """Tries to find a histogram name or prefix in a line. |
| 1644 | |
| 1645 | Returns the existence of the histogram name, or None if it needs more chunk |
| 1646 | to determine.""" |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1647 | # A histogram_suffixes tag type has an affected-histogram name as a prefix of |
| 1648 | # the histogram_name. |
Makoto Shimazu | 3ad422cd | 2019-05-08 02:35:14 | [diff] [blame] | 1649 | if '<affected-histogram' in chunk: |
| 1650 | # If the tag is not completed, needs more chunk to get the name. |
| 1651 | if not '>' in chunk: |
| 1652 | return None |
| 1653 | if not 'name="' in chunk: |
| 1654 | return False |
| 1655 | # Retrieve the first portion of the chunk wrapped by double-quotations. We |
| 1656 | # expect the only attribute is the name. |
| 1657 | histogram_prefix = chunk.split('"')[1] |
| 1658 | return histogram_prefix in histogram_name |
| 1659 | # Typically the whole histogram name should in the line. |
| 1660 | return histogram_name in chunk |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1661 | |
| 1662 | |
| 1663 | def _CheckUmaHistogramChanges(input_api, output_api): |
| 1664 | """Check that UMA histogram names in touched lines can still be found in other |
| 1665 | lines of the patch or in histograms.xml. Note that this check would not catch |
| 1666 | the reverse: changes in histograms.xml not matched in the code itself.""" |
| 1667 | touched_histograms = [] |
| 1668 | histograms_xml_modifications = [] |
Vaclav Brozek | bdac817c | 2018-03-24 06:30:47 | [diff] [blame] | 1669 | call_pattern_c = r'\bUMA_HISTOGRAM.*\(' |
| 1670 | call_pattern_java = r'\bRecordHistogram\.record[a-zA-Z]+Histogram\(' |
| 1671 | name_pattern = r'"(.*?)"' |
| 1672 | single_line_c_re = input_api.re.compile(call_pattern_c + name_pattern) |
| 1673 | single_line_java_re = input_api.re.compile(call_pattern_java + name_pattern) |
| 1674 | split_line_c_prefix_re = input_api.re.compile(call_pattern_c) |
| 1675 | split_line_java_prefix_re = input_api.re.compile(call_pattern_java) |
| 1676 | split_line_suffix_re = input_api.re.compile(r'^\s*' + name_pattern) |
Vaclav Brozek | 0e730cbd | 2018-03-24 06:18:17 | [diff] [blame] | 1677 | last_line_matched_prefix = False |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1678 | for f in input_api.AffectedFiles(): |
| 1679 | # If histograms.xml itself is modified, keep the modified lines for later. |
| 1680 | if f.LocalPath().endswith(('histograms.xml')): |
| 1681 | histograms_xml_modifications = f.ChangedContents() |
| 1682 | continue |
Vaclav Brozek | bdac817c | 2018-03-24 06:30:47 | [diff] [blame] | 1683 | if f.LocalPath().endswith(('cc', 'mm', 'cpp')): |
| 1684 | single_line_re = single_line_c_re |
| 1685 | split_line_prefix_re = split_line_c_prefix_re |
| 1686 | elif f.LocalPath().endswith(('java')): |
| 1687 | single_line_re = single_line_java_re |
| 1688 | split_line_prefix_re = split_line_java_prefix_re |
| 1689 | else: |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1690 | continue |
| 1691 | for line_num, line in f.ChangedContents(): |
Vaclav Brozek | 0e730cbd | 2018-03-24 06:18:17 | [diff] [blame] | 1692 | if last_line_matched_prefix: |
| 1693 | suffix_found = split_line_suffix_re.search(line) |
| 1694 | if suffix_found : |
| 1695 | touched_histograms.append([suffix_found.group(1), f, line_num]) |
| 1696 | last_line_matched_prefix = False |
| 1697 | continue |
Vaclav Brozek | 8a8e2e20 | 2018-03-23 22:01:06 | [diff] [blame] | 1698 | found = single_line_re.search(line) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1699 | if found: |
| 1700 | touched_histograms.append([found.group(1), f, line_num]) |
Vaclav Brozek | 0e730cbd | 2018-03-24 06:18:17 | [diff] [blame] | 1701 | continue |
| 1702 | last_line_matched_prefix = split_line_prefix_re.search(line) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1703 | |
| 1704 | # Search for the touched histogram names in the local modifications to |
| 1705 | # histograms.xml, and, if not found, on the base histograms.xml file. |
| 1706 | unmatched_histograms = [] |
| 1707 | for histogram_info in touched_histograms: |
| 1708 | histogram_name_found = False |
Makoto Shimazu | 3ad422cd | 2019-05-08 02:35:14 | [diff] [blame] | 1709 | chunk = '' |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1710 | for line_num, line in histograms_xml_modifications: |
Makoto Shimazu | 3ad422cd | 2019-05-08 02:35:14 | [diff] [blame] | 1711 | chunk += line |
| 1712 | histogram_name_found = _FindHistogramNameInChunk(histogram_info[0], chunk) |
| 1713 | if histogram_name_found is None: |
| 1714 | continue |
| 1715 | chunk = '' |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1716 | if histogram_name_found: |
| 1717 | break |
| 1718 | if not histogram_name_found: |
| 1719 | unmatched_histograms.append(histogram_info) |
| 1720 | |
eroman | b90c82e7e3 | 2015-04-01 15:13:49 | [diff] [blame] | 1721 | histograms_xml_path = 'tools/metrics/histograms/histograms.xml' |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1722 | problems = [] |
| 1723 | if unmatched_histograms: |
eroman | b90c82e7e3 | 2015-04-01 15:13:49 | [diff] [blame] | 1724 | with open(histograms_xml_path) as histograms_xml: |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1725 | for histogram_name, f, line_num in unmatched_histograms: |
mcasas | 39c1b8b | 2015-02-25 15:33:45 | [diff] [blame] | 1726 | histograms_xml.seek(0) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1727 | histogram_name_found = False |
Makoto Shimazu | 3ad422cd | 2019-05-08 02:35:14 | [diff] [blame] | 1728 | chunk = '' |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1729 | for line in histograms_xml: |
Makoto Shimazu | 3ad422cd | 2019-05-08 02:35:14 | [diff] [blame] | 1730 | chunk += line |
| 1731 | histogram_name_found = _FindHistogramNameInChunk(histogram_name, |
| 1732 | chunk) |
| 1733 | if histogram_name_found is None: |
| 1734 | continue |
| 1735 | chunk = '' |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1736 | if histogram_name_found: |
| 1737 | break |
| 1738 | if not histogram_name_found: |
| 1739 | problems.append(' [%s:%d] %s' % |
| 1740 | (f.LocalPath(), line_num, histogram_name)) |
| 1741 | |
| 1742 | if not problems: |
| 1743 | return [] |
| 1744 | return [output_api.PresubmitPromptWarning('Some UMA_HISTOGRAM lines have ' |
| 1745 | 'been modified and the associated histogram name has no match in either ' |
eroman | b90c82e7e3 | 2015-04-01 15:13:49 | [diff] [blame] | 1746 | '%s or the modifications of it:' % (histograms_xml_path), problems)] |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1747 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1748 | |
yolandyan | daabc6d | 2016-04-18 18:29:39 | [diff] [blame] | 1749 | def _CheckFlakyTestUsage(input_api, output_api): |
| 1750 | """Check that FlakyTest annotation is our own instead of the android one""" |
| 1751 | pattern = input_api.re.compile(r'import android.test.FlakyTest;') |
| 1752 | files = [] |
| 1753 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 1754 | if f.LocalPath().endswith('Test.java'): |
| 1755 | if pattern.search(input_api.ReadFile(f)): |
| 1756 | files.append(f) |
| 1757 | if len(files): |
| 1758 | return [output_api.PresubmitError( |
| 1759 | 'Use org.chromium.base.test.util.FlakyTest instead of ' |
| 1760 | 'android.test.FlakyTest', |
| 1761 | files)] |
| 1762 | return [] |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1763 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1764 | |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1765 | def _CheckNoNewWStrings(input_api, output_api): |
| 1766 | """Checks to make sure we don't introduce use of wstrings.""" |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 1767 | problems = [] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1768 | for f in input_api.AffectedFiles(): |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 1769 | if (not f.LocalPath().endswith(('.cc', '.h')) or |
scottmg | e6f0440 | 2014-11-05 01:59:57 | [diff] [blame] | 1770 | f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 1771 | '/win/' in f.LocalPath() or |
| 1772 | 'chrome_elf' in f.LocalPath() or |
| 1773 | 'install_static' in f.LocalPath()): |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 1774 | continue |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1775 | |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 1776 | allowWString = False |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 1777 | for line_num, line in f.ChangedContents(): |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 1778 | if 'presubmit: allow wstring' in line: |
| 1779 | allowWString = True |
| 1780 | elif not allowWString and 'wstring' in line: |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 1781 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 1782 | allowWString = False |
| 1783 | else: |
| 1784 | allowWString = False |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1785 | |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 1786 | if not problems: |
| 1787 | return [] |
| 1788 | return [output_api.PresubmitPromptWarning('New code should not use wstrings.' |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 1789 | ' If you are calling a cross-platform API that accepts a wstring, ' |
| 1790 | 'fix the API.\n' + |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 1791 | '\n'.join(problems))] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1792 | |
| 1793 | |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 1794 | def _CheckNoDEPSGIT(input_api, output_api): |
| 1795 | """Make sure .DEPS.git is never modified manually.""" |
| 1796 | if any(f.LocalPath().endswith('.DEPS.git') for f in |
| 1797 | input_api.AffectedFiles()): |
| 1798 | return [output_api.PresubmitError( |
| 1799 | 'Never commit changes to .DEPS.git. This file is maintained by an\n' |
| 1800 | 'automated system based on what\'s in DEPS and your changes will be\n' |
| 1801 | 'overwritten.\n' |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 1802 | 'See https://sites.google.com/a/chromium.org/dev/developers/how-tos/' |
| 1803 | 'get-the-code#Rolling_DEPS\n' |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 1804 | 'for more information')] |
| 1805 | return [] |
| 1806 | |
| 1807 | |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 1808 | def _CheckValidHostsInDEPS(input_api, output_api): |
| 1809 | """Checks that DEPS file deps are from allowed_hosts.""" |
| 1810 | # Run only if DEPS file has been modified to annoy fewer bystanders. |
| 1811 | if all(f.LocalPath() != 'DEPS' for f in input_api.AffectedFiles()): |
| 1812 | return [] |
| 1813 | # Outsource work to gclient verify |
| 1814 | try: |
John Budorick | f20c004 | 2019-04-25 23:23:40 | [diff] [blame] | 1815 | gclient_path = input_api.os_path.join( |
| 1816 | input_api.PresubmitLocalPath(), |
| 1817 | 'third_party', 'depot_tools', 'gclient.py') |
| 1818 | input_api.subprocess.check_output( |
| 1819 | [input_api.python_executable, gclient_path, 'verify'], |
| 1820 | stderr=input_api.subprocess.STDOUT) |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 1821 | return [] |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 1822 | except input_api.subprocess.CalledProcessError as error: |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 1823 | return [output_api.PresubmitError( |
| 1824 | 'DEPS file must have only git dependencies.', |
| 1825 | long_text=error.output)] |
| 1826 | |
| 1827 | |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1828 | def _GetMessageForMatchingType(input_api, affected_file, line_number, line, |
| 1829 | type_name, message): |
| 1830 | """Helper method for _CheckNoBannedFunctions and _CheckNoDeprecatedMojoTypes. |
| 1831 | |
| 1832 | Returns an string composed of the name of the file, the line number where the |
| 1833 | match has been found and the additional text passed as |message| in case the |
| 1834 | target type name matches the text inside the line passed as parameter. |
| 1835 | """ |
Peng Huang | 9c5949a0 | 2020-06-11 19:20:54 | [diff] [blame] | 1836 | result = [] |
| 1837 | |
| 1838 | if line.endswith(" nocheck"): |
| 1839 | return result |
| 1840 | |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1841 | matched = False |
| 1842 | if type_name[0:1] == '/': |
| 1843 | regex = type_name[1:] |
| 1844 | if input_api.re.search(regex, line): |
| 1845 | matched = True |
| 1846 | elif type_name in line: |
| 1847 | matched = True |
| 1848 | |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1849 | if matched: |
| 1850 | result.append(' %s:%d:' % (affected_file.LocalPath(), line_number)) |
| 1851 | for message_line in message: |
| 1852 | result.append(' %s' % message_line) |
| 1853 | |
| 1854 | return result |
| 1855 | |
| 1856 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1857 | def _CheckNoBannedFunctions(input_api, output_api): |
| 1858 | """Make sure that banned functions are not used.""" |
| 1859 | warnings = [] |
| 1860 | errors = [] |
| 1861 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1862 | def IsBlacklisted(affected_file, blacklist): |
| 1863 | local_path = affected_file.LocalPath() |
| 1864 | for item in blacklist: |
| 1865 | if input_api.re.match(item, local_path): |
| 1866 | return True |
| 1867 | return False |
| 1868 | |
Peter K. Lee | 6c03ccff | 2019-07-15 14:40:05 | [diff] [blame] | 1869 | def IsIosObjcFile(affected_file): |
Sylvain Defresne | a8b73d25 | 2018-02-28 15:45:54 | [diff] [blame] | 1870 | local_path = affected_file.LocalPath() |
| 1871 | if input_api.os_path.splitext(local_path)[-1] not in ('.mm', '.m', '.h'): |
| 1872 | return False |
| 1873 | basename = input_api.os_path.basename(local_path) |
| 1874 | if 'ios' in basename.split('_'): |
| 1875 | return True |
| 1876 | for sep in (input_api.os_path.sep, input_api.os_path.altsep): |
| 1877 | if sep and 'ios' in local_path.split(sep): |
| 1878 | return True |
| 1879 | return False |
| 1880 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1881 | def CheckForMatch(affected_file, line_num, line, func_name, message, error): |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1882 | problems = _GetMessageForMatchingType(input_api, f, line_num, line, |
| 1883 | func_name, message) |
| 1884 | if problems: |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1885 | if error: |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1886 | errors.extend(problems) |
| 1887 | else: |
| 1888 | warnings.extend(problems) |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1889 | |
Eric Stevenson | a9a98097 | 2017-09-23 00:04:41 | [diff] [blame] | 1890 | file_filter = lambda f: f.LocalPath().endswith(('.java')) |
| 1891 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1892 | for line_num, line in f.ChangedContents(): |
| 1893 | for func_name, message, error in _BANNED_JAVA_FUNCTIONS: |
| 1894 | CheckForMatch(f, line_num, line, func_name, message, error) |
| 1895 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1896 | file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) |
| 1897 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1898 | for line_num, line in f.ChangedContents(): |
| 1899 | for func_name, message, error in _BANNED_OBJC_FUNCTIONS: |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1900 | CheckForMatch(f, line_num, line, func_name, message, error) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1901 | |
Peter K. Lee | 6c03ccff | 2019-07-15 14:40:05 | [diff] [blame] | 1902 | for f in input_api.AffectedFiles(file_filter=IsIosObjcFile): |
Sylvain Defresne | a8b73d25 | 2018-02-28 15:45:54 | [diff] [blame] | 1903 | for line_num, line in f.ChangedContents(): |
| 1904 | for func_name, message, error in _BANNED_IOS_OBJC_FUNCTIONS: |
| 1905 | CheckForMatch(f, line_num, line, func_name, message, error) |
| 1906 | |
Peter K. Lee | 6c03ccff | 2019-07-15 14:40:05 | [diff] [blame] | 1907 | egtest_filter = lambda f: f.LocalPath().endswith(('_egtest.mm')) |
| 1908 | for f in input_api.AffectedFiles(file_filter=egtest_filter): |
| 1909 | for line_num, line in f.ChangedContents(): |
| 1910 | for func_name, message, error in _BANNED_IOS_EGTEST_FUNCTIONS: |
| 1911 | CheckForMatch(f, line_num, line, func_name, message, error) |
| 1912 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1913 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h')) |
| 1914 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1915 | for line_num, line in f.ChangedContents(): |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 1916 | for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS: |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 1917 | if IsBlacklisted(f, excluded_paths): |
| 1918 | continue |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1919 | CheckForMatch(f, line_num, line, func_name, message, error) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1920 | |
| 1921 | result = [] |
| 1922 | if (warnings): |
| 1923 | result.append(output_api.PresubmitPromptWarning( |
| 1924 | 'Banned functions were used.\n' + '\n'.join(warnings))) |
| 1925 | if (errors): |
| 1926 | result.append(output_api.PresubmitError( |
| 1927 | 'Banned functions were used.\n' + '\n'.join(errors))) |
| 1928 | return result |
| 1929 | |
| 1930 | |
Michael Thiessen | 4445764 | 2020-02-06 00:24:15 | [diff] [blame] | 1931 | def _CheckAndroidNoBannedImports(input_api, output_api): |
| 1932 | """Make sure that banned java imports are not used.""" |
| 1933 | errors = [] |
| 1934 | |
| 1935 | def IsException(path, exceptions): |
| 1936 | for exception in exceptions: |
| 1937 | if (path.startswith(exception)): |
| 1938 | return True |
| 1939 | return False |
| 1940 | |
| 1941 | file_filter = lambda f: f.LocalPath().endswith(('.java')) |
| 1942 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1943 | for line_num, line in f.ChangedContents(): |
| 1944 | for import_name, message, exceptions in _BANNED_JAVA_IMPORTS: |
| 1945 | if IsException(f.LocalPath(), exceptions): |
| 1946 | continue; |
| 1947 | problems = _GetMessageForMatchingType(input_api, f, line_num, line, |
| 1948 | 'import ' + import_name, message) |
| 1949 | if problems: |
| 1950 | errors.extend(problems) |
| 1951 | result = [] |
| 1952 | if (errors): |
| 1953 | result.append(output_api.PresubmitError( |
| 1954 | 'Banned imports were used.\n' + '\n'.join(errors))) |
| 1955 | return result |
| 1956 | |
| 1957 | |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1958 | def _CheckNoDeprecatedMojoTypes(input_api, output_api): |
| 1959 | """Make sure that old Mojo types are not used.""" |
| 1960 | warnings = [] |
Mario Sanchez Prada | cec9cef | 2019-12-15 11:54:57 | [diff] [blame] | 1961 | errors = [] |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1962 | |
Mario Sanchez Prada | aab9138 | 2019-12-19 08:57:09 | [diff] [blame] | 1963 | # For any path that is not an "ok" or an "error" path, a warning will be |
| 1964 | # raised if deprecated mojo types are found. |
| 1965 | ok_paths = ['components/arc'] |
| 1966 | error_paths = ['third_party/blink', 'content'] |
| 1967 | |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1968 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h')) |
| 1969 | for f in input_api.AffectedFiles(file_filter=file_filter): |
Mario Sanchez Prada | cec9cef | 2019-12-15 11:54:57 | [diff] [blame] | 1970 | # Don't check //components/arc, not yet migrated (see crrev.com/c/1868870). |
Mario Sanchez Prada | aab9138 | 2019-12-19 08:57:09 | [diff] [blame] | 1971 | if any(map(lambda path: f.LocalPath().startswith(path), ok_paths)): |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1972 | continue |
| 1973 | |
| 1974 | for line_num, line in f.ChangedContents(): |
| 1975 | for func_name, message in _DEPRECATED_MOJO_TYPES: |
| 1976 | problems = _GetMessageForMatchingType(input_api, f, line_num, line, |
| 1977 | func_name, message) |
Mario Sanchez Prada | cec9cef | 2019-12-15 11:54:57 | [diff] [blame] | 1978 | |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1979 | if problems: |
Mario Sanchez Prada | aab9138 | 2019-12-19 08:57:09 | [diff] [blame] | 1980 | # Raise errors inside |error_paths| and warnings everywhere else. |
| 1981 | if any(map(lambda path: f.LocalPath().startswith(path), error_paths)): |
Mario Sanchez Prada | cec9cef | 2019-12-15 11:54:57 | [diff] [blame] | 1982 | errors.extend(problems) |
| 1983 | else: |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1984 | warnings.extend(problems) |
| 1985 | |
| 1986 | result = [] |
| 1987 | if (warnings): |
| 1988 | result.append(output_api.PresubmitPromptWarning( |
| 1989 | 'Banned Mojo types were used.\n' + '\n'.join(warnings))) |
Mario Sanchez Prada | cec9cef | 2019-12-15 11:54:57 | [diff] [blame] | 1990 | if (errors): |
| 1991 | result.append(output_api.PresubmitError( |
| 1992 | 'Banned Mojo types were used.\n' + '\n'.join(errors))) |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 1993 | return result |
| 1994 | |
| 1995 | |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 1996 | def _CheckNoPragmaOnce(input_api, output_api): |
| 1997 | """Make sure that banned functions are not used.""" |
| 1998 | files = [] |
| 1999 | pattern = input_api.re.compile(r'^#pragma\s+once', |
| 2000 | input_api.re.MULTILINE) |
| 2001 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 2002 | if not f.LocalPath().endswith('.h'): |
| 2003 | continue |
| 2004 | contents = input_api.ReadFile(f) |
| 2005 | if pattern.search(contents): |
| 2006 | files.append(f) |
| 2007 | |
| 2008 | if files: |
| 2009 | return [output_api.PresubmitError( |
| 2010 | 'Do not use #pragma once in header files.\n' |
| 2011 | 'See http://www.chromium.org/developers/coding-style#TOC-File-headers', |
| 2012 | files)] |
| 2013 | return [] |
| 2014 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 2015 | |
[email protected] | e747905 | 2012-09-19 00:26:12 | [diff] [blame] | 2016 | def _CheckNoTrinaryTrueFalse(input_api, output_api): |
| 2017 | """Checks to make sure we don't introduce use of foo ? true : false.""" |
| 2018 | problems = [] |
| 2019 | pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)') |
| 2020 | for f in input_api.AffectedFiles(): |
| 2021 | if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')): |
| 2022 | continue |
| 2023 | |
| 2024 | for line_num, line in f.ChangedContents(): |
| 2025 | if pattern.match(line): |
| 2026 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 2027 | |
| 2028 | if not problems: |
| 2029 | return [] |
| 2030 | return [output_api.PresubmitPromptWarning( |
| 2031 | 'Please consider avoiding the "? true : false" pattern if possible.\n' + |
| 2032 | '\n'.join(problems))] |
| 2033 | |
| 2034 | |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2035 | def _CheckUnwantedDependencies(input_api, output_api): |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 2036 | """Runs checkdeps on #include and import statements added in this |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2037 | change. Breaking - rules is an error, breaking ! rules is a |
| 2038 | warning. |
| 2039 | """ |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 2040 | import sys |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2041 | # We need to wait until we have an input_api object and use this |
| 2042 | # roundabout construct to import checkdeps because this file is |
| 2043 | # eval-ed and thus doesn't have __file__. |
| 2044 | original_sys_path = sys.path |
| 2045 | try: |
| 2046 | sys.path = sys.path + [input_api.os_path.join( |
[email protected] | 5298cc98 | 2014-05-29 20:53:47 | [diff] [blame] | 2047 | input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2048 | import checkdeps |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2049 | from rules import Rule |
| 2050 | finally: |
| 2051 | # Restore sys.path to what it was before. |
| 2052 | sys.path = original_sys_path |
| 2053 | |
| 2054 | added_includes = [] |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 2055 | added_imports = [] |
Jinsuk Kim | 5a09267 | 2017-10-24 22:42:24 | [diff] [blame] | 2056 | added_java_imports = [] |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2057 | for f in input_api.AffectedFiles(): |
Daniel Bratell | 65b03326 | 2019-04-23 08:17:06 | [diff] [blame] | 2058 | if _IsCPlusPlusFile(input_api, f.LocalPath()): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 2059 | changed_lines = [line for _, line in f.ChangedContents()] |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 2060 | added_includes.append([f.AbsoluteLocalPath(), changed_lines]) |
Daniel Bratell | 65b03326 | 2019-04-23 08:17:06 | [diff] [blame] | 2061 | elif _IsProtoFile(input_api, f.LocalPath()): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 2062 | changed_lines = [line for _, line in f.ChangedContents()] |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 2063 | added_imports.append([f.AbsoluteLocalPath(), changed_lines]) |
Daniel Bratell | 65b03326 | 2019-04-23 08:17:06 | [diff] [blame] | 2064 | elif _IsJavaFile(input_api, f.LocalPath()): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 2065 | changed_lines = [line for _, line in f.ChangedContents()] |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 2066 | added_java_imports.append([f.AbsoluteLocalPath(), changed_lines]) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2067 | |
[email protected] | 2638517 | 2013-05-09 23:11:35 | [diff] [blame] | 2068 | deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2069 | |
| 2070 | error_descriptions = [] |
| 2071 | warning_descriptions = [] |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 2072 | error_subjects = set() |
| 2073 | warning_subjects = set() |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2074 | for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( |
| 2075 | added_includes): |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 2076 | path = input_api.os_path.relpath(path, input_api.PresubmitLocalPath()) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2077 | description_with_path = '%s\n %s' % (path, rule_description) |
| 2078 | if rule_type == Rule.DISALLOW: |
| 2079 | error_descriptions.append(description_with_path) |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 2080 | error_subjects.add("#includes") |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2081 | else: |
| 2082 | warning_descriptions.append(description_with_path) |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 2083 | warning_subjects.add("#includes") |
| 2084 | |
| 2085 | for path, rule_type, rule_description in deps_checker.CheckAddedProtoImports( |
| 2086 | added_imports): |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 2087 | path = input_api.os_path.relpath(path, input_api.PresubmitLocalPath()) |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 2088 | description_with_path = '%s\n %s' % (path, rule_description) |
| 2089 | if rule_type == Rule.DISALLOW: |
| 2090 | error_descriptions.append(description_with_path) |
| 2091 | error_subjects.add("imports") |
| 2092 | else: |
| 2093 | warning_descriptions.append(description_with_path) |
| 2094 | warning_subjects.add("imports") |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2095 | |
Jinsuk Kim | 5a09267 | 2017-10-24 22:42:24 | [diff] [blame] | 2096 | for path, rule_type, rule_description in deps_checker.CheckAddedJavaImports( |
Shenghua Zhang | bfaa38b8 | 2017-11-16 21:58:02 | [diff] [blame] | 2097 | added_java_imports, _JAVA_MULTIPLE_DEFINITION_EXCLUDED_PATHS): |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 2098 | path = input_api.os_path.relpath(path, input_api.PresubmitLocalPath()) |
Jinsuk Kim | 5a09267 | 2017-10-24 22:42:24 | [diff] [blame] | 2099 | description_with_path = '%s\n %s' % (path, rule_description) |
| 2100 | if rule_type == Rule.DISALLOW: |
| 2101 | error_descriptions.append(description_with_path) |
| 2102 | error_subjects.add("imports") |
| 2103 | else: |
| 2104 | warning_descriptions.append(description_with_path) |
| 2105 | warning_subjects.add("imports") |
| 2106 | |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2107 | results = [] |
| 2108 | if error_descriptions: |
| 2109 | results.append(output_api.PresubmitError( |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 2110 | 'You added one or more %s that violate checkdeps rules.' |
| 2111 | % " and ".join(error_subjects), |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2112 | error_descriptions)) |
| 2113 | if warning_descriptions: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 2114 | results.append(output_api.PresubmitPromptOrNotify( |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 2115 | 'You added one or more %s of files that are temporarily\n' |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2116 | 'allowed but being removed. Can you avoid introducing the\n' |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 2117 | '%s? See relevant DEPS file(s) for details and contacts.' % |
| 2118 | (" and ".join(warning_subjects), "/".join(warning_subjects)), |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 2119 | warning_descriptions)) |
| 2120 | return results |
| 2121 | |
| 2122 | |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 2123 | def _CheckFilePermissions(input_api, output_api): |
| 2124 | """Check that all files have their permissions properly set.""" |
[email protected] | 79150720 | 2014-02-03 23:19:15 | [diff] [blame] | 2125 | if input_api.platform == 'win32': |
| 2126 | return [] |
raphael.kubo.da.costa | c1d13e60b | 2016-04-01 11:49:29 | [diff] [blame] | 2127 | checkperms_tool = input_api.os_path.join( |
| 2128 | input_api.PresubmitLocalPath(), |
| 2129 | 'tools', 'checkperms', 'checkperms.py') |
| 2130 | args = [input_api.python_executable, checkperms_tool, |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 2131 | '--root', input_api.change.RepositoryRoot()] |
Raphael Kubo da Costa | 6ff391d | 2017-11-13 16:43:39 | [diff] [blame] | 2132 | with input_api.CreateTemporaryFile() as file_list: |
| 2133 | for f in input_api.AffectedFiles(): |
| 2134 | # checkperms.py file/directory arguments must be relative to the |
| 2135 | # repository. |
| 2136 | file_list.write(f.LocalPath() + '\n') |
| 2137 | file_list.close() |
| 2138 | args += ['--file-list', file_list.name] |
| 2139 | try: |
| 2140 | input_api.subprocess.check_output(args) |
| 2141 | return [] |
| 2142 | except input_api.subprocess.CalledProcessError as error: |
| 2143 | return [output_api.PresubmitError( |
| 2144 | 'checkperms.py failed:', |
| 2145 | long_text=error.output)] |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 2146 | |
| 2147 | |
robertocn | 832f599 | 2017-01-04 19:01:30 | [diff] [blame] | 2148 | def _CheckTeamTags(input_api, output_api): |
| 2149 | """Checks that OWNERS files have consistent TEAM and COMPONENT tags.""" |
| 2150 | checkteamtags_tool = input_api.os_path.join( |
| 2151 | input_api.PresubmitLocalPath(), |
| 2152 | 'tools', 'checkteamtags', 'checkteamtags.py') |
| 2153 | args = [input_api.python_executable, checkteamtags_tool, |
| 2154 | '--root', input_api.change.RepositoryRoot()] |
robertocn | 5eb8231 | 2017-01-09 20:27:22 | [diff] [blame] | 2155 | files = [f.LocalPath() for f in input_api.AffectedFiles(include_deletes=False) |
robertocn | 832f599 | 2017-01-04 19:01:30 | [diff] [blame] | 2156 | if input_api.os_path.basename(f.AbsoluteLocalPath()).upper() == |
| 2157 | 'OWNERS'] |
| 2158 | try: |
| 2159 | if files: |
Roberto Carrillo | 8465e7a | 2019-07-17 18:39:05 | [diff] [blame] | 2160 | warnings = input_api.subprocess.check_output(args + files).splitlines() |
| 2161 | if warnings: |
| 2162 | return [output_api.PresubmitPromptWarning(warnings[0], warnings[1:])] |
robertocn | 832f599 | 2017-01-04 19:01:30 | [diff] [blame] | 2163 | return [] |
| 2164 | except input_api.subprocess.CalledProcessError as error: |
| 2165 | return [output_api.PresubmitError( |
| 2166 | 'checkteamtags.py failed:', |
| 2167 | long_text=error.output)] |
| 2168 | |
| 2169 | |
[email protected] | c8278b3 | 2012-10-30 20:35:49 | [diff] [blame] | 2170 | def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api): |
| 2171 | """Makes sure we don't include ui/aura/window_property.h |
| 2172 | in header files. |
| 2173 | """ |
| 2174 | pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"') |
| 2175 | errors = [] |
| 2176 | for f in input_api.AffectedFiles(): |
| 2177 | if not f.LocalPath().endswith('.h'): |
| 2178 | continue |
| 2179 | for line_num, line in f.ChangedContents(): |
| 2180 | if pattern.match(line): |
| 2181 | errors.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 2182 | |
| 2183 | results = [] |
| 2184 | if errors: |
| 2185 | results.append(output_api.PresubmitError( |
| 2186 | 'Header files should not include ui/aura/window_property.h', errors)) |
| 2187 | return results |
| 2188 | |
| 2189 | |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 2190 | def _CheckForVersionControlConflictsInFile(input_api, f): |
| 2191 | pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$') |
| 2192 | errors = [] |
| 2193 | for line_num, line in f.ChangedContents(): |
Luke Zielinski | 9bc14ac7 | 2019-03-04 19:02:16 | [diff] [blame] | 2194 | if f.LocalPath().endswith(('.md', '.rst', '.txt')): |
dbeam | 95c35a2f | 2015-06-02 01:40:23 | [diff] [blame] | 2195 | # First-level headers in markdown look a lot like version control |
| 2196 | # conflict markers. http://daringfireball.net/projects/markdown/basics |
| 2197 | continue |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 2198 | if pattern.match(line): |
| 2199 | errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) |
| 2200 | return errors |
| 2201 | |
| 2202 | |
| 2203 | def _CheckForVersionControlConflicts(input_api, output_api): |
| 2204 | """Usually this is not intentional and will cause a compile failure.""" |
| 2205 | errors = [] |
| 2206 | for f in input_api.AffectedFiles(): |
| 2207 | errors.extend(_CheckForVersionControlConflictsInFile(input_api, f)) |
| 2208 | |
| 2209 | results = [] |
| 2210 | if errors: |
| 2211 | results.append(output_api.PresubmitError( |
| 2212 | 'Version control conflict markers found, please resolve.', errors)) |
| 2213 | return results |
| 2214 | |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 2215 | |
estade | e17314a0 | 2017-01-12 16:22:16 | [diff] [blame] | 2216 | def _CheckGoogleSupportAnswerUrl(input_api, output_api): |
| 2217 | pattern = input_api.re.compile('support\.google\.com\/chrome.*/answer') |
| 2218 | errors = [] |
| 2219 | for f in input_api.AffectedFiles(): |
| 2220 | for line_num, line in f.ChangedContents(): |
| 2221 | if pattern.search(line): |
| 2222 | errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) |
| 2223 | |
| 2224 | results = [] |
| 2225 | if errors: |
| 2226 | results.append(output_api.PresubmitPromptWarning( |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 2227 | 'Found Google support URL addressed by answer number. Please replace ' |
| 2228 | 'with a p= identifier instead. See crbug.com/679462\n', errors)) |
estade | e17314a0 | 2017-01-12 16:22:16 | [diff] [blame] | 2229 | return results |
| 2230 | |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 2231 | |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 2232 | def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api): |
| 2233 | def FilterFile(affected_file): |
| 2234 | """Filter function for use with input_api.AffectedSourceFiles, |
| 2235 | below. This filters out everything except non-test files from |
| 2236 | top-level directories that generally speaking should not hard-code |
| 2237 | service URLs (e.g. src/android_webview/, src/content/ and others). |
| 2238 | """ |
| 2239 | return input_api.FilterSourceFile( |
| 2240 | affected_file, |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2241 | white_list=[r'^(android_webview|base|content|net)[\\/].*'], |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 2242 | black_list=(_EXCLUDED_PATHS + |
| 2243 | _TEST_CODE_EXCLUDED_PATHS + |
| 2244 | input_api.DEFAULT_BLACK_LIST)) |
| 2245 | |
reillyi | 3896573 | 2015-11-16 18:27:33 | [diff] [blame] | 2246 | base_pattern = ('"[^"]*(google|googleapis|googlezip|googledrive|appspot)' |
| 2247 | '\.(com|net)[^"]*"') |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 2248 | comment_pattern = input_api.re.compile('//.*%s' % base_pattern) |
| 2249 | pattern = input_api.re.compile(base_pattern) |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 2250 | problems = [] # items are (filename, line_number, line) |
| 2251 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 2252 | for line_num, line in f.ChangedContents(): |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 2253 | if not comment_pattern.search(line) and pattern.search(line): |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 2254 | problems.append((f.LocalPath(), line_num, line)) |
| 2255 | |
| 2256 | if problems: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 2257 | return [output_api.PresubmitPromptOrNotify( |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 2258 | 'Most layers below src/chrome/ should not hardcode service URLs.\n' |
[email protected] | b014977 | 2014-03-27 16:47:58 | [diff] [blame] | 2259 | 'Are you sure this is correct?', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 2260 | [' %s:%d: %s' % ( |
| 2261 | problem[0], problem[1], problem[2]) for problem in problems])] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 2262 | else: |
| 2263 | return [] |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 2264 | |
| 2265 | |
James Cook | 6b6597c | 2019-11-06 22:05:29 | [diff] [blame] | 2266 | def _CheckChromeOsSyncedPrefRegistration(input_api, output_api): |
| 2267 | """Warns if Chrome OS C++ files register syncable prefs as browser prefs.""" |
| 2268 | def FileFilter(affected_file): |
| 2269 | """Includes directories known to be Chrome OS only.""" |
| 2270 | return input_api.FilterSourceFile( |
| 2271 | affected_file, |
| 2272 | white_list=('^ash/', |
| 2273 | '^chromeos/', # Top-level src/chromeos. |
| 2274 | '/chromeos/', # Any path component. |
| 2275 | '^components/arc', |
| 2276 | '^components/exo'), |
| 2277 | black_list=(input_api.DEFAULT_BLACK_LIST)) |
| 2278 | |
| 2279 | prefs = [] |
| 2280 | priority_prefs = [] |
| 2281 | for f in input_api.AffectedFiles(file_filter=FileFilter): |
| 2282 | for line_num, line in f.ChangedContents(): |
| 2283 | if input_api.re.search('PrefRegistrySyncable::SYNCABLE_PREF', line): |
| 2284 | prefs.append(' %s:%d:' % (f.LocalPath(), line_num)) |
| 2285 | prefs.append(' %s' % line) |
| 2286 | if input_api.re.search( |
| 2287 | 'PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF', line): |
| 2288 | priority_prefs.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 2289 | priority_prefs.append(' %s' % line) |
| 2290 | |
| 2291 | results = [] |
| 2292 | if (prefs): |
| 2293 | results.append(output_api.PresubmitPromptWarning( |
| 2294 | 'Preferences were registered as SYNCABLE_PREF and will be controlled ' |
| 2295 | 'by browser sync settings. If these prefs should be controlled by OS ' |
| 2296 | 'sync settings use SYNCABLE_OS_PREF instead.\n' + '\n'.join(prefs))) |
| 2297 | if (priority_prefs): |
| 2298 | results.append(output_api.PresubmitPromptWarning( |
| 2299 | 'Preferences were registered as SYNCABLE_PRIORITY_PREF and will be ' |
| 2300 | 'controlled by browser sync settings. If these prefs should be ' |
| 2301 | 'controlled by OS sync settings use SYNCABLE_OS_PRIORITY_PREF ' |
| 2302 | 'instead.\n' + '\n'.join(prefs))) |
| 2303 | return results |
| 2304 | |
| 2305 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2306 | # TODO: add unit tests. |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 2307 | def _CheckNoAbbreviationInPngFileName(input_api, output_api): |
| 2308 | """Makes sure there are no abbreviations in the name of PNG files. |
binji | 0dcdf34 | 2014-12-12 18:32:31 | [diff] [blame] | 2309 | The native_client_sdk directory is excluded because it has auto-generated PNG |
| 2310 | files for documentation. |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 2311 | """ |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 2312 | errors = [] |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2313 | white_list = [r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$'] |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2314 | black_list = [r'^native_client_sdk[\\/]'] |
binji | 0dcdf34 | 2014-12-12 18:32:31 | [diff] [blame] | 2315 | file_filter = lambda f: input_api.FilterSourceFile( |
| 2316 | f, white_list=white_list, black_list=black_list) |
| 2317 | for f in input_api.AffectedFiles(include_deletes=False, |
| 2318 | file_filter=file_filter): |
| 2319 | errors.append(' %s' % f.LocalPath()) |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 2320 | |
| 2321 | results = [] |
| 2322 | if errors: |
| 2323 | results.append(output_api.PresubmitError( |
| 2324 | 'The name of PNG files should not have abbreviations. \n' |
| 2325 | 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n' |
| 2326 | 'Contact [email protected] if you have questions.', errors)) |
| 2327 | return results |
| 2328 | |
| 2329 | |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 2330 | def _ExtractAddRulesFromParsedDeps(parsed_deps): |
| 2331 | """Extract the rules that add dependencies from a parsed DEPS file. |
| 2332 | |
| 2333 | Args: |
| 2334 | parsed_deps: the locals dictionary from evaluating the DEPS file.""" |
| 2335 | add_rules = set() |
| 2336 | add_rules.update([ |
| 2337 | rule[1:] for rule in parsed_deps.get('include_rules', []) |
| 2338 | if rule.startswith('+') or rule.startswith('!') |
| 2339 | ]) |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 2340 | for _, rules in parsed_deps.get('specific_include_rules', |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 2341 | {}).iteritems(): |
| 2342 | add_rules.update([ |
| 2343 | rule[1:] for rule in rules |
| 2344 | if rule.startswith('+') or rule.startswith('!') |
| 2345 | ]) |
| 2346 | return add_rules |
| 2347 | |
| 2348 | |
| 2349 | def _ParseDeps(contents): |
| 2350 | """Simple helper for parsing DEPS files.""" |
| 2351 | # Stubs for handling special syntax in the root DEPS file. |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 2352 | class _VarImpl: |
| 2353 | |
| 2354 | def __init__(self, local_scope): |
| 2355 | self._local_scope = local_scope |
| 2356 | |
| 2357 | def Lookup(self, var_name): |
| 2358 | """Implements the Var syntax.""" |
| 2359 | try: |
| 2360 | return self._local_scope['vars'][var_name] |
| 2361 | except KeyError: |
| 2362 | raise Exception('Var is not defined: %s' % var_name) |
| 2363 | |
| 2364 | local_scope = {} |
| 2365 | global_scope = { |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 2366 | 'Var': _VarImpl(local_scope).Lookup, |
Ben Pastene | 3e49749c | 2020-07-06 20:22:59 | [diff] [blame] | 2367 | 'Str': str, |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 2368 | } |
| 2369 | exec contents in global_scope, local_scope |
| 2370 | return local_scope |
| 2371 | |
| 2372 | |
| 2373 | def _CalculateAddedDeps(os_path, old_contents, new_contents): |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 2374 | """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 2375 | a set of DEPS entries that we should look up. |
| 2376 | |
| 2377 | For a directory (rather than a specific filename) we fake a path to |
| 2378 | a specific filename by adding /DEPS. This is chosen as a file that |
| 2379 | will seldom or never be subject to per-file include_rules. |
| 2380 | """ |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 2381 | # We ignore deps entries on auto-generated directories. |
| 2382 | AUTO_GENERATED_DIRS = ['grit', 'jni'] |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 2383 | |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 2384 | old_deps = _ExtractAddRulesFromParsedDeps(_ParseDeps(old_contents)) |
| 2385 | new_deps = _ExtractAddRulesFromParsedDeps(_ParseDeps(new_contents)) |
| 2386 | |
| 2387 | added_deps = new_deps.difference(old_deps) |
| 2388 | |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 2389 | results = set() |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 2390 | for added_dep in added_deps: |
| 2391 | if added_dep.split('/')[0] in AUTO_GENERATED_DIRS: |
| 2392 | continue |
| 2393 | # Assume that a rule that ends in .h is a rule for a specific file. |
| 2394 | if added_dep.endswith('.h'): |
| 2395 | results.add(added_dep) |
| 2396 | else: |
| 2397 | results.add(os_path.join(added_dep, 'DEPS')) |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 2398 | return results |
| 2399 | |
| 2400 | |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2401 | def _CheckAddedDepsHaveTargetApprovals(input_api, output_api): |
| 2402 | """When a dependency prefixed with + is added to a DEPS file, we |
| 2403 | want to make sure that the change is reviewed by an OWNER of the |
| 2404 | target file or directory, to avoid layering violations from being |
| 2405 | introduced. This check verifies that this happens. |
| 2406 | """ |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 2407 | virtual_depended_on_files = set() |
jochen | 53efcdd | 2016-01-29 05:09:24 | [diff] [blame] | 2408 | |
| 2409 | file_filter = lambda f: not input_api.re.match( |
Kent Tamura | 32dbbcb | 2018-11-30 12:28:49 | [diff] [blame] | 2410 | r"^third_party[\\/]blink[\\/].*", f.LocalPath()) |
jochen | 53efcdd | 2016-01-29 05:09:24 | [diff] [blame] | 2411 | for f in input_api.AffectedFiles(include_deletes=False, |
| 2412 | file_filter=file_filter): |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2413 | filename = input_api.os_path.basename(f.LocalPath()) |
| 2414 | if filename == 'DEPS': |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 2415 | virtual_depended_on_files.update(_CalculateAddedDeps( |
| 2416 | input_api.os_path, |
| 2417 | '\n'.join(f.OldContents()), |
| 2418 | '\n'.join(f.NewContents()))) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2419 | |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2420 | if not virtual_depended_on_files: |
| 2421 | return [] |
| 2422 | |
| 2423 | if input_api.is_committing: |
| 2424 | if input_api.tbr: |
| 2425 | return [output_api.PresubmitNotifyResult( |
| 2426 | '--tbr was specified, skipping OWNERS check for DEPS additions')] |
Paweł Hajdan, Jr | be6739ea | 2016-04-28 15:07:27 | [diff] [blame] | 2427 | if input_api.dry_run: |
| 2428 | return [output_api.PresubmitNotifyResult( |
| 2429 | 'This is a dry run, skipping OWNERS check for DEPS additions')] |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2430 | if not input_api.change.issue: |
| 2431 | return [output_api.PresubmitError( |
| 2432 | "DEPS approval by OWNERS check failed: this change has " |
Aaron Gable | 65a99d9 | 2017-10-09 19:17:40 | [diff] [blame] | 2433 | "no change number, so we can't check it for approvals.")] |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2434 | output = output_api.PresubmitError |
| 2435 | else: |
| 2436 | output = output_api.PresubmitNotifyResult |
| 2437 | |
| 2438 | owners_db = input_api.owners_db |
tandrii | ed3b7e1 | 2016-05-12 14:38:50 | [diff] [blame] | 2439 | owner_email, reviewers = ( |
| 2440 | input_api.canned_checks.GetCodereviewOwnerAndReviewers( |
| 2441 | input_api, |
| 2442 | owners_db.email_regexp, |
| 2443 | approval_needed=input_api.is_committing)) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2444 | |
| 2445 | owner_email = owner_email or input_api.change.author_email |
| 2446 | |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 2447 | reviewers_plus_owner = set(reviewers) |
[email protected] | e71c608 | 2013-05-22 02:28:51 | [diff] [blame] | 2448 | if owner_email: |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 2449 | reviewers_plus_owner.add(owner_email) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2450 | missing_files = owners_db.files_not_covered_by(virtual_depended_on_files, |
| 2451 | reviewers_plus_owner) |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 2452 | |
| 2453 | # We strip the /DEPS part that was added by |
| 2454 | # _FilesToCheckForIncomingDeps to fake a path to a file in a |
| 2455 | # directory. |
| 2456 | def StripDeps(path): |
| 2457 | start_deps = path.rfind('/DEPS') |
| 2458 | if start_deps != -1: |
| 2459 | return path[:start_deps] |
| 2460 | else: |
| 2461 | return path |
| 2462 | unapproved_dependencies = ["'+%s'," % StripDeps(path) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2463 | for path in missing_files] |
| 2464 | |
| 2465 | if unapproved_dependencies: |
| 2466 | output_list = [ |
Paweł Hajdan, Jr | ec17f88 | 2016-07-04 14:16:15 | [diff] [blame] | 2467 | output('You need LGTM from owners of depends-on paths in DEPS that were ' |
| 2468 | 'modified in this CL:\n %s' % |
| 2469 | '\n '.join(sorted(unapproved_dependencies)))] |
| 2470 | suggested_owners = owners_db.reviewers_for(missing_files, owner_email) |
| 2471 | output_list.append(output( |
| 2472 | 'Suggested missing target path OWNERS:\n %s' % |
| 2473 | '\n '.join(suggested_owners or []))) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 2474 | return output_list |
| 2475 | |
| 2476 | return [] |
| 2477 | |
| 2478 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2479 | # TODO: add unit tests. |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 2480 | def _CheckSpamLogging(input_api, output_api): |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2481 | file_inclusion_pattern = [r'.+%s' % _IMPLEMENTATION_EXTENSIONS] |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 2482 | black_list = (_EXCLUDED_PATHS + |
| 2483 | _TEST_CODE_EXCLUDED_PATHS + |
| 2484 | input_api.DEFAULT_BLACK_LIST + |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2485 | (r"^base[\\/]logging\.h$", |
| 2486 | r"^base[\\/]logging\.cc$", |
Francois Doray | 177da2c | 2019-06-20 14:14:22 | [diff] [blame] | 2487 | r"^base[\\/]task[\\/]thread_pool[\\/]task_tracker\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2488 | r"^chrome[\\/]app[\\/]chrome_main_delegate\.cc$", |
| 2489 | r"^chrome[\\/]browser[\\/]chrome_browser_main\.cc$", |
| 2490 | r"^chrome[\\/]browser[\\/]ui[\\/]startup[\\/]" |
[email protected] | 4de7526 | 2013-12-18 23:16:12 | [diff] [blame] | 2491 | r"startup_browser_creator\.cc$", |
Nicolas Ouellet-Payeur | 16730ab | 2019-04-09 15:39:18 | [diff] [blame] | 2492 | r"^chrome[\\/]browser[\\/]browser_switcher[\\/]bho[\\/].*", |
Patrick Monette | 0196be2 | 2019-05-10 03:33:15 | [diff] [blame] | 2493 | r"^chrome[\\/]browser[\\/]diagnostics[\\/]" + |
[email protected] | f5b9a3f34 | 2014-08-08 22:06:03 | [diff] [blame] | 2494 | r"diagnostics_writer\.cc$", |
Patrick Monette | 0196be2 | 2019-05-10 03:33:15 | [diff] [blame] | 2495 | r"^chrome[\\/]chrome_cleaner[\\/].*", |
| 2496 | r"^chrome[\\/]chrome_elf[\\/]dll_hash[\\/]dll_hash_main\.cc$", |
| 2497 | r"^chrome[\\/]installer[\\/]setup[\\/].*", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2498 | r"^chromecast[\\/]", |
| 2499 | r"^cloud_print[\\/]", |
| 2500 | r"^components[\\/]browser_watcher[\\/]" |
manzagop | 85e629e | 2017-05-09 22:11:48 | [diff] [blame] | 2501 | r"dump_stability_report_main_win.cc$", |
Sharon Yang | 5ee61d7e | 2020-04-15 23:39:05 | [diff] [blame] | 2502 | r"^components[\\/]media_control[\\/]renderer[\\/]" |
| 2503 | r"media_playback_options\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2504 | r"^components[\\/]zucchini[\\/].*", |
peter | 80739bb | 2015-10-20 11:17:46 | [diff] [blame] | 2505 | # TODO(peter): Remove this exception. https://crbug.com/534537 |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2506 | r"^content[\\/]browser[\\/]notifications[\\/]" |
peter | 80739bb | 2015-10-20 11:17:46 | [diff] [blame] | 2507 | r"notification_event_dispatcher_impl\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2508 | r"^content[\\/]common[\\/]gpu[\\/]client[\\/]" |
[email protected] | 9056e73 | 2014-01-08 06:25:25 | [diff] [blame] | 2509 | r"gl_helper_benchmark\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2510 | r"^courgette[\\/]courgette_minimal_tool\.cc$", |
| 2511 | r"^courgette[\\/]courgette_tool\.cc$", |
| 2512 | r"^extensions[\\/]renderer[\\/]logging_native_handler\.cc$", |
Fabrice de Gans-Riberi | 3fa1c0fa | 2019-02-08 18:55:27 | [diff] [blame] | 2513 | r"^fuchsia[\\/]engine[\\/]browser[\\/]frame_impl.cc$", |
Wez | d39b367f | 2019-11-05 00:37:00 | [diff] [blame] | 2514 | r"^fuchsia[\\/]engine[\\/]context_provider_main.cc$", |
Fabrice de Gans-Riberi | 570201a2 | 2019-01-17 23:32:33 | [diff] [blame] | 2515 | r"^headless[\\/]app[\\/]headless_shell\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2516 | r"^ipc[\\/]ipc_logging\.cc$", |
| 2517 | r"^native_client_sdk[\\/]", |
| 2518 | r"^remoting[\\/]base[\\/]logging\.h$", |
| 2519 | r"^remoting[\\/]host[\\/].*", |
| 2520 | r"^sandbox[\\/]linux[\\/].*", |
DongJun Kim | febb3c2 | 2019-10-21 02:08:06 | [diff] [blame] | 2521 | r"^storage[\\/]browser[\\/]file_system[\\/]" + |
Fabrice de Gans-Riberi | 570201a2 | 2019-01-17 23:32:33 | [diff] [blame] | 2522 | r"dump_file_system.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2523 | r"^tools[\\/]", |
| 2524 | r"^ui[\\/]base[\\/]resource[\\/]data_pack.cc$", |
| 2525 | r"^ui[\\/]aura[\\/]bench[\\/]bench_main\.cc$", |
Maksim Sisov | a4d1cfbe | 2020-06-16 07:58:37 | [diff] [blame] | 2526 | r"^ui[\\/]ozone[\\/]platform[\\/]cast[\\/]", |
| 2527 | r"^ui[\\/]base[\\/]x[\\/]xwmstartupcheck[\\/]" |
| 2528 | r"xwmstartupcheck\.cc$")) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 2529 | source_file_filter = lambda x: input_api.FilterSourceFile( |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2530 | x, white_list=file_inclusion_pattern, black_list=black_list) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 2531 | |
thomasanderson | 625d393 | 2017-03-29 07:16:58 | [diff] [blame] | 2532 | log_info = set([]) |
| 2533 | printf = set([]) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 2534 | |
| 2535 | for f in input_api.AffectedSourceFiles(source_file_filter): |
thomasanderson | 625d393 | 2017-03-29 07:16:58 | [diff] [blame] | 2536 | for _, line in f.ChangedContents(): |
| 2537 | if input_api.re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", line): |
| 2538 | log_info.add(f.LocalPath()) |
| 2539 | elif input_api.re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", line): |
| 2540 | log_info.add(f.LocalPath()) |
[email protected] | 18b466b | 2013-12-02 22:01:37 | [diff] [blame] | 2541 | |
thomasanderson | 625d393 | 2017-03-29 07:16:58 | [diff] [blame] | 2542 | if input_api.re.search(r"\bprintf\(", line): |
| 2543 | printf.add(f.LocalPath()) |
| 2544 | elif input_api.re.search(r"\bfprintf\((stdout|stderr)", line): |
| 2545 | printf.add(f.LocalPath()) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 2546 | |
| 2547 | if log_info: |
| 2548 | return [output_api.PresubmitError( |
| 2549 | 'These files spam the console log with LOG(INFO):', |
| 2550 | items=log_info)] |
| 2551 | if printf: |
| 2552 | return [output_api.PresubmitError( |
| 2553 | 'These files spam the console log with printf/fprintf:', |
| 2554 | items=printf)] |
| 2555 | return [] |
| 2556 | |
| 2557 | |
[email protected] | 49aa76a | 2013-12-04 06:59:16 | [diff] [blame] | 2558 | def _CheckForAnonymousVariables(input_api, output_api): |
| 2559 | """These types are all expected to hold locks while in scope and |
| 2560 | so should never be anonymous (which causes them to be immediately |
| 2561 | destroyed).""" |
| 2562 | they_who_must_be_named = [ |
| 2563 | 'base::AutoLock', |
| 2564 | 'base::AutoReset', |
| 2565 | 'base::AutoUnlock', |
| 2566 | 'SkAutoAlphaRestore', |
| 2567 | 'SkAutoBitmapShaderInstall', |
| 2568 | 'SkAutoBlitterChoose', |
| 2569 | 'SkAutoBounderCommit', |
| 2570 | 'SkAutoCallProc', |
| 2571 | 'SkAutoCanvasRestore', |
| 2572 | 'SkAutoCommentBlock', |
| 2573 | 'SkAutoDescriptor', |
| 2574 | 'SkAutoDisableDirectionCheck', |
| 2575 | 'SkAutoDisableOvalCheck', |
| 2576 | 'SkAutoFree', |
| 2577 | 'SkAutoGlyphCache', |
| 2578 | 'SkAutoHDC', |
| 2579 | 'SkAutoLockColors', |
| 2580 | 'SkAutoLockPixels', |
| 2581 | 'SkAutoMalloc', |
| 2582 | 'SkAutoMaskFreeImage', |
| 2583 | 'SkAutoMutexAcquire', |
| 2584 | 'SkAutoPathBoundsUpdate', |
| 2585 | 'SkAutoPDFRelease', |
| 2586 | 'SkAutoRasterClipValidate', |
| 2587 | 'SkAutoRef', |
| 2588 | 'SkAutoTime', |
| 2589 | 'SkAutoTrace', |
| 2590 | 'SkAutoUnref', |
| 2591 | ] |
| 2592 | anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named) |
| 2593 | # bad: base::AutoLock(lock.get()); |
| 2594 | # not bad: base::AutoLock lock(lock.get()); |
| 2595 | bad_pattern = input_api.re.compile(anonymous) |
| 2596 | # good: new base::AutoLock(lock.get()) |
| 2597 | good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous) |
| 2598 | errors = [] |
| 2599 | |
| 2600 | for f in input_api.AffectedFiles(): |
| 2601 | if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')): |
| 2602 | continue |
| 2603 | for linenum, line in f.ChangedContents(): |
| 2604 | if bad_pattern.search(line) and not good_pattern.search(line): |
| 2605 | errors.append('%s:%d' % (f.LocalPath(), linenum)) |
| 2606 | |
| 2607 | if errors: |
| 2608 | return [output_api.PresubmitError( |
| 2609 | 'These lines create anonymous variables that need to be named:', |
| 2610 | items=errors)] |
| 2611 | return [] |
| 2612 | |
| 2613 | |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 2614 | def _CheckUniquePtr(input_api, output_api): |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 2615 | # Returns whether |template_str| is of the form <T, U...> for some types T |
| 2616 | # and U. Assumes that |template_str| is already in the form <...>. |
| 2617 | def HasMoreThanOneArg(template_str): |
| 2618 | # Level of <...> nesting. |
| 2619 | nesting = 0 |
| 2620 | for c in template_str: |
| 2621 | if c == '<': |
| 2622 | nesting += 1 |
| 2623 | elif c == '>': |
| 2624 | nesting -= 1 |
| 2625 | elif c == ',' and nesting == 1: |
| 2626 | return True |
| 2627 | return False |
| 2628 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2629 | file_inclusion_pattern = [r'.+%s' % _IMPLEMENTATION_EXTENSIONS] |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 2630 | sources = lambda affected_file: input_api.FilterSourceFile( |
| 2631 | affected_file, |
| 2632 | black_list=(_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS + |
| 2633 | input_api.DEFAULT_BLACK_LIST), |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2634 | white_list=file_inclusion_pattern) |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 2635 | |
| 2636 | # Pattern to capture a single "<...>" block of template arguments. It can |
| 2637 | # handle linearly nested blocks, such as "<std::vector<std::set<T>>>", but |
| 2638 | # cannot handle branching structures, such as "<pair<set<T>,set<U>>". The |
| 2639 | # latter would likely require counting that < and > match, which is not |
| 2640 | # expressible in regular languages. Should the need arise, one can introduce |
| 2641 | # limited counting (matching up to a total number of nesting depth), which |
| 2642 | # should cover all practical cases for already a low nesting limit. |
| 2643 | template_arg_pattern = ( |
| 2644 | r'<[^>]*' # Opening block of <. |
| 2645 | r'>([^<]*>)?') # Closing block of >. |
| 2646 | # Prefix expressing that whatever follows is not already inside a <...> |
| 2647 | # block. |
| 2648 | not_inside_template_arg_pattern = r'(^|[^<,\s]\s*)' |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 2649 | null_construct_pattern = input_api.re.compile( |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 2650 | not_inside_template_arg_pattern |
| 2651 | + r'\bstd::unique_ptr' |
| 2652 | + template_arg_pattern |
| 2653 | + r'\(\)') |
| 2654 | |
| 2655 | # Same as template_arg_pattern, but excluding type arrays, e.g., <T[]>. |
| 2656 | template_arg_no_array_pattern = ( |
| 2657 | r'<[^>]*[^]]' # Opening block of <. |
| 2658 | r'>([^(<]*[^]]>)?') # Closing block of >. |
| 2659 | # Prefix saying that what follows is the start of an expression. |
| 2660 | start_of_expr_pattern = r'(=|\breturn|^)\s*' |
| 2661 | # Suffix saying that what follows are call parentheses with a non-empty list |
| 2662 | # of arguments. |
| 2663 | nonempty_arg_list_pattern = r'\(([^)]|$)' |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 2664 | # Put the template argument into a capture group for deeper examination later. |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 2665 | return_construct_pattern = input_api.re.compile( |
| 2666 | start_of_expr_pattern |
| 2667 | + r'std::unique_ptr' |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 2668 | + '(?P<template_arg>' |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 2669 | + template_arg_no_array_pattern |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 2670 | + ')' |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 2671 | + nonempty_arg_list_pattern) |
| 2672 | |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 2673 | problems_constructor = [] |
| 2674 | problems_nullptr = [] |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 2675 | for f in input_api.AffectedSourceFiles(sources): |
| 2676 | for line_number, line in f.ChangedContents(): |
| 2677 | # Disallow: |
| 2678 | # return std::unique_ptr<T>(foo); |
| 2679 | # bar = std::unique_ptr<T>(foo); |
| 2680 | # But allow: |
| 2681 | # return std::unique_ptr<T[]>(foo); |
| 2682 | # bar = std::unique_ptr<T[]>(foo); |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 2683 | # And also allow cases when the second template argument is present. Those |
| 2684 | # cases cannot be handled by std::make_unique: |
| 2685 | # return std::unique_ptr<T, U>(foo); |
| 2686 | # bar = std::unique_ptr<T, U>(foo); |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 2687 | local_path = f.LocalPath() |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 2688 | return_construct_result = return_construct_pattern.search(line) |
| 2689 | if return_construct_result and not HasMoreThanOneArg( |
| 2690 | return_construct_result.group('template_arg')): |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 2691 | problems_constructor.append( |
| 2692 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 2693 | # Disallow: |
| 2694 | # std::unique_ptr<T>() |
| 2695 | if null_construct_pattern.search(line): |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 2696 | problems_nullptr.append( |
| 2697 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
| 2698 | |
| 2699 | errors = [] |
Vaclav Brozek | c2fecf4 | 2018-04-06 16:40:16 | [diff] [blame] | 2700 | if problems_nullptr: |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 2701 | errors.append(output_api.PresubmitError( |
| 2702 | 'The following files use std::unique_ptr<T>(). Use nullptr instead.', |
Vaclav Brozek | c2fecf4 | 2018-04-06 16:40:16 | [diff] [blame] | 2703 | problems_nullptr)) |
| 2704 | if problems_constructor: |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 2705 | errors.append(output_api.PresubmitError( |
| 2706 | 'The following files use explicit std::unique_ptr constructor.' |
| 2707 | 'Use std::make_unique<T>() instead.', |
Vaclav Brozek | c2fecf4 | 2018-04-06 16:40:16 | [diff] [blame] | 2708 | problems_constructor)) |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 2709 | return errors |
| 2710 | |
| 2711 | |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2712 | def _CheckUserActionUpdate(input_api, output_api): |
| 2713 | """Checks if any new user action has been added.""" |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 2714 | if any('actions.xml' == input_api.os_path.basename(f) for f in |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2715 | input_api.LocalPaths()): |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 2716 | # If actions.xml is already included in the changelist, the PRESUBMIT |
| 2717 | # for actions.xml will do a more complete presubmit check. |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2718 | return [] |
| 2719 | |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2720 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm')) |
| 2721 | action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)' |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 2722 | current_actions = None |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2723 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 2724 | for line_num, line in f.ChangedContents(): |
| 2725 | match = input_api.re.search(action_re, line) |
| 2726 | if match: |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 2727 | # Loads contents in tools/metrics/actions/actions.xml to memory. It's |
| 2728 | # loaded only once. |
| 2729 | if not current_actions: |
| 2730 | with open('tools/metrics/actions/actions.xml') as actions_f: |
| 2731 | current_actions = actions_f.read() |
| 2732 | # Search for the matched user action name in |current_actions|. |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2733 | for action_name in match.groups(): |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 2734 | action = 'name="{0}"'.format(action_name) |
| 2735 | if action not in current_actions: |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2736 | return [output_api.PresubmitPromptWarning( |
| 2737 | 'File %s line %d: %s is missing in ' |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 2738 | 'tools/metrics/actions/actions.xml. Please run ' |
| 2739 | 'tools/metrics/actions/extract_actions.py to update.' |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2740 | % (f.LocalPath(), line_num, action_name))] |
| 2741 | return [] |
| 2742 | |
| 2743 | |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2744 | def _ImportJSONCommentEater(input_api): |
| 2745 | import sys |
| 2746 | sys.path = sys.path + [input_api.os_path.join( |
| 2747 | input_api.PresubmitLocalPath(), |
| 2748 | 'tools', 'json_comment_eater')] |
| 2749 | import json_comment_eater |
| 2750 | return json_comment_eater |
| 2751 | |
| 2752 | |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2753 | def _GetJSONParseError(input_api, filename, eat_comments=True): |
| 2754 | try: |
| 2755 | contents = input_api.ReadFile(filename) |
| 2756 | if eat_comments: |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2757 | json_comment_eater = _ImportJSONCommentEater(input_api) |
plundblad | 1f5a4509f | 2015-07-23 11:31:13 | [diff] [blame] | 2758 | contents = json_comment_eater.Nom(contents) |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2759 | |
| 2760 | input_api.json.loads(contents) |
| 2761 | except ValueError as e: |
| 2762 | return e |
| 2763 | return None |
| 2764 | |
| 2765 | |
| 2766 | def _GetIDLParseError(input_api, filename): |
| 2767 | try: |
| 2768 | contents = input_api.ReadFile(filename) |
| 2769 | idl_schema = input_api.os_path.join( |
| 2770 | input_api.PresubmitLocalPath(), |
| 2771 | 'tools', 'json_schema_compiler', 'idl_schema.py') |
| 2772 | process = input_api.subprocess.Popen( |
| 2773 | [input_api.python_executable, idl_schema], |
| 2774 | stdin=input_api.subprocess.PIPE, |
| 2775 | stdout=input_api.subprocess.PIPE, |
| 2776 | stderr=input_api.subprocess.PIPE, |
| 2777 | universal_newlines=True) |
| 2778 | (_, error) = process.communicate(input=contents) |
| 2779 | return error or None |
| 2780 | except ValueError as e: |
| 2781 | return e |
| 2782 | |
| 2783 | |
| 2784 | def _CheckParseErrors(input_api, output_api): |
| 2785 | """Check that IDL and JSON files do not contain syntax errors.""" |
| 2786 | actions = { |
| 2787 | '.idl': _GetIDLParseError, |
| 2788 | '.json': _GetJSONParseError, |
| 2789 | } |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2790 | # Most JSON files are preprocessed and support comments, but these do not. |
| 2791 | json_no_comments_patterns = [ |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2792 | r'^testing[\\/]', |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2793 | ] |
| 2794 | # Only run IDL checker on files in these directories. |
| 2795 | idl_included_patterns = [ |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2796 | r'^chrome[\\/]common[\\/]extensions[\\/]api[\\/]', |
| 2797 | r'^extensions[\\/]common[\\/]api[\\/]', |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2798 | ] |
| 2799 | |
| 2800 | def get_action(affected_file): |
| 2801 | filename = affected_file.LocalPath() |
| 2802 | return actions.get(input_api.os_path.splitext(filename)[1]) |
| 2803 | |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2804 | def FilterFile(affected_file): |
| 2805 | action = get_action(affected_file) |
| 2806 | if not action: |
| 2807 | return False |
| 2808 | path = affected_file.LocalPath() |
| 2809 | |
Erik Staab | 2dd72b1 | 2020-04-16 15:03:40 | [diff] [blame] | 2810 | if _MatchesFile(input_api, |
| 2811 | _KNOWN_TEST_DATA_AND_INVALID_JSON_FILE_PATTERNS, |
| 2812 | path): |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2813 | return False |
| 2814 | |
| 2815 | if (action == _GetIDLParseError and |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 2816 | not _MatchesFile(input_api, idl_included_patterns, path)): |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2817 | return False |
| 2818 | return True |
| 2819 | |
| 2820 | results = [] |
| 2821 | for affected_file in input_api.AffectedFiles( |
| 2822 | file_filter=FilterFile, include_deletes=False): |
| 2823 | action = get_action(affected_file) |
| 2824 | kwargs = {} |
| 2825 | if (action == _GetJSONParseError and |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 2826 | _MatchesFile(input_api, json_no_comments_patterns, |
| 2827 | affected_file.LocalPath())): |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2828 | kwargs['eat_comments'] = False |
| 2829 | parse_error = action(input_api, |
| 2830 | affected_file.AbsoluteLocalPath(), |
| 2831 | **kwargs) |
| 2832 | if parse_error: |
| 2833 | results.append(output_api.PresubmitError('%s could not be parsed: %s' % |
| 2834 | (affected_file.LocalPath(), parse_error))) |
| 2835 | return results |
| 2836 | |
| 2837 | |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 2838 | def _CheckJavaStyle(input_api, output_api): |
| 2839 | """Runs checkstyle on changed java files and returns errors if any exist.""" |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 2840 | import sys |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 2841 | original_sys_path = sys.path |
| 2842 | try: |
| 2843 | sys.path = sys.path + [input_api.os_path.join( |
| 2844 | input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] |
| 2845 | import checkstyle |
| 2846 | finally: |
| 2847 | # Restore sys.path to what it was before. |
| 2848 | sys.path = original_sys_path |
| 2849 | |
| 2850 | return checkstyle.RunCheckstyle( |
davileen | 72d7653 | 2015-01-20 22:30:09 | [diff] [blame] | 2851 | input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml', |
newt | d8b7d30e9 | 2015-01-23 18:10:51 | [diff] [blame] | 2852 | black_list=_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 2853 | |
| 2854 | |
Nate Fischer | dfd9812e | 2019-07-18 22:03:00 | [diff] [blame] | 2855 | def _CheckPythonDevilInit(input_api, output_api): |
| 2856 | """Checks to make sure devil is initialized correctly in python scripts.""" |
| 2857 | script_common_initialize_pattern = input_api.re.compile( |
| 2858 | r'script_common\.InitializeEnvironment\(') |
| 2859 | devil_env_config_initialize = input_api.re.compile( |
| 2860 | r'devil_env\.config\.Initialize\(') |
| 2861 | |
| 2862 | errors = [] |
| 2863 | |
| 2864 | sources = lambda affected_file: input_api.FilterSourceFile( |
| 2865 | affected_file, |
| 2866 | black_list=(_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST + |
| 2867 | (r'^build[\\/]android[\\/]devil_chromium\.py', |
| 2868 | r'^third_party[\\/].*',)), |
| 2869 | white_list=[r'.*\.py$']) |
| 2870 | |
| 2871 | for f in input_api.AffectedSourceFiles(sources): |
| 2872 | for line_num, line in f.ChangedContents(): |
| 2873 | if (script_common_initialize_pattern.search(line) or |
| 2874 | devil_env_config_initialize.search(line)): |
| 2875 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 2876 | |
| 2877 | results = [] |
| 2878 | |
| 2879 | if errors: |
| 2880 | results.append(output_api.PresubmitError( |
| 2881 | 'Devil initialization should always be done using ' |
| 2882 | 'devil_chromium.Initialize() in the chromium project, to use better ' |
| 2883 | 'defaults for dependencies (ex. up-to-date version of adb).', |
| 2884 | errors)) |
| 2885 | |
| 2886 | return results |
| 2887 | |
| 2888 | |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 2889 | def _MatchesFile(input_api, patterns, path): |
| 2890 | for pattern in patterns: |
| 2891 | if input_api.re.search(pattern, path): |
| 2892 | return True |
| 2893 | return False |
| 2894 | |
| 2895 | |
Daniel Cheng | 7052cdf | 2017-11-21 19:23:29 | [diff] [blame] | 2896 | def _GetOwnersFilesToCheckForIpcOwners(input_api): |
| 2897 | """Gets a list of OWNERS files to check for correct security owners. |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2898 | |
Daniel Cheng | 7052cdf | 2017-11-21 19:23:29 | [diff] [blame] | 2899 | Returns: |
| 2900 | A dictionary mapping an OWNER file to the list of OWNERS rules it must |
| 2901 | contain to cover IPC-related files with noparent reviewer rules. |
| 2902 | """ |
| 2903 | # Whether or not a file affects IPC is (mostly) determined by a simple list |
| 2904 | # of filename patterns. |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2905 | file_patterns = [ |
palmer | b19a093 | 2017-01-24 04:00:31 | [diff] [blame] | 2906 | # Legacy IPC: |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2907 | '*_messages.cc', |
| 2908 | '*_messages*.h', |
| 2909 | '*_param_traits*.*', |
palmer | b19a093 | 2017-01-24 04:00:31 | [diff] [blame] | 2910 | # Mojo IPC: |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2911 | '*.mojom', |
Daniel Cheng | 1f38693 | 2018-01-29 19:56:47 | [diff] [blame] | 2912 | '*_mojom_traits*.*', |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2913 | '*_struct_traits*.*', |
| 2914 | '*_type_converter*.*', |
palmer | b19a093 | 2017-01-24 04:00:31 | [diff] [blame] | 2915 | '*.typemap', |
| 2916 | # Android native IPC: |
| 2917 | '*.aidl', |
| 2918 | # Blink uses a different file naming convention: |
| 2919 | '*EnumTraits*.*', |
Daniel Cheng | e0bf3f6 | 2018-01-30 01:56:47 | [diff] [blame] | 2920 | "*MojomTraits*.*", |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2921 | '*StructTraits*.*', |
| 2922 | '*TypeConverter*.*', |
| 2923 | ] |
| 2924 | |
scottmg | 7a6ed5ba | 2016-11-04 18:22:04 | [diff] [blame] | 2925 | # These third_party directories do not contain IPCs, but contain files |
| 2926 | # matching the above patterns, which trigger false positives. |
| 2927 | exclude_paths = [ |
| 2928 | 'third_party/crashpad/*', |
Raphael Kubo da Costa | 4a224cf4 | 2019-11-19 18:44:16 | [diff] [blame] | 2929 | 'third_party/blink/renderer/platform/bindings/*', |
Andres Medina | e684cf4 | 2018-08-27 18:48:23 | [diff] [blame] | 2930 | 'third_party/protobuf/benchmarks/python/*', |
Nico Weber | ee3dc9b | 2017-08-31 17:09:29 | [diff] [blame] | 2931 | 'third_party/win_build_output/*', |
Dan Harrington | b60e1aa | 2019-11-20 08:48:54 | [diff] [blame] | 2932 | 'third_party/feed_library/*', |
Scott Violet | 9f82d36 | 2019-11-06 21:42:16 | [diff] [blame] | 2933 | # These files are just used to communicate between class loaders running |
| 2934 | # in the same process. |
| 2935 | 'weblayer/browser/java/org/chromium/weblayer_private/interfaces/*', |
Mugdha Lakhani | 6230b96 | 2020-01-13 13:00:57 | [diff] [blame] | 2936 | 'weblayer/browser/java/org/chromium/weblayer_private/test_interfaces/*', |
| 2937 | |
scottmg | 7a6ed5ba | 2016-11-04 18:22:04 | [diff] [blame] | 2938 | ] |
| 2939 | |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2940 | # Dictionary mapping an OWNERS file path to Patterns. |
| 2941 | # Patterns is a dictionary mapping glob patterns (suitable for use in per-file |
| 2942 | # rules ) to a PatternEntry. |
| 2943 | # PatternEntry is a dictionary with two keys: |
| 2944 | # - 'files': the files that are matched by this pattern |
| 2945 | # - 'rules': the per-file rules needed for this pattern |
| 2946 | # For example, if we expect OWNERS file to contain rules for *.mojom and |
| 2947 | # *_struct_traits*.*, Patterns might look like this: |
| 2948 | # { |
| 2949 | # '*.mojom': { |
| 2950 | # 'files': ..., |
| 2951 | # 'rules': [ |
| 2952 | # 'per-file *.mojom=set noparent', |
| 2953 | # 'per-file *.mojom=file://ipc/SECURITY_OWNERS', |
| 2954 | # ], |
| 2955 | # }, |
| 2956 | # '*_struct_traits*.*': { |
| 2957 | # 'files': ..., |
| 2958 | # 'rules': [ |
| 2959 | # 'per-file *_struct_traits*.*=set noparent', |
| 2960 | # 'per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS', |
| 2961 | # ], |
| 2962 | # }, |
| 2963 | # } |
| 2964 | to_check = {} |
| 2965 | |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2966 | def AddPatternToCheck(input_file, pattern): |
| 2967 | owners_file = input_api.os_path.join( |
| 2968 | input_api.os_path.dirname(input_file.LocalPath()), 'OWNERS') |
| 2969 | if owners_file not in to_check: |
| 2970 | to_check[owners_file] = {} |
| 2971 | if pattern not in to_check[owners_file]: |
| 2972 | to_check[owners_file][pattern] = { |
| 2973 | 'files': [], |
| 2974 | 'rules': [ |
| 2975 | 'per-file %s=set noparent' % pattern, |
| 2976 | 'per-file %s=file://ipc/SECURITY_OWNERS' % pattern, |
| 2977 | ] |
| 2978 | } |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 2979 | to_check[owners_file][pattern]['files'].append(input_file) |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2980 | |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2981 | # Iterate through the affected files to see what we actually need to check |
| 2982 | # for. We should only nag patch authors about per-file rules if a file in that |
| 2983 | # directory would match that pattern. If a directory only contains *.mojom |
| 2984 | # files and no *_messages*.h files, we should only nag about rules for |
| 2985 | # *.mojom files. |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2986 | for f in input_api.AffectedFiles(include_deletes=False): |
Daniel Cheng | 76f49cc | 2020-04-21 01:48:26 | [diff] [blame] | 2987 | # Manifest files don't have a strong naming convention. Instead, try to find |
| 2988 | # affected .cc and .h files which look like they contain a manifest |
| 2989 | # definition. |
| 2990 | manifest_pattern = input_api.re.compile('manifests?\.(cc|h)$') |
| 2991 | test_manifest_pattern = input_api.re.compile('test_manifests?\.(cc|h)') |
| 2992 | if (manifest_pattern.search(f.LocalPath()) and not |
| 2993 | test_manifest_pattern.search(f.LocalPath())): |
| 2994 | # We expect all actual service manifest files to contain at least one |
| 2995 | # qualified reference to service_manager::Manifest. |
| 2996 | if 'service_manager::Manifest' in '\n'.join(f.NewContents()): |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2997 | AddPatternToCheck(f, input_api.os_path.basename(f.LocalPath())) |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2998 | for pattern in file_patterns: |
| 2999 | if input_api.fnmatch.fnmatch( |
| 3000 | input_api.os_path.basename(f.LocalPath()), pattern): |
scottmg | 7a6ed5ba | 2016-11-04 18:22:04 | [diff] [blame] | 3001 | skip = False |
| 3002 | for exclude in exclude_paths: |
| 3003 | if input_api.fnmatch.fnmatch(f.LocalPath(), exclude): |
| 3004 | skip = True |
| 3005 | break |
| 3006 | if skip: |
| 3007 | continue |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 3008 | AddPatternToCheck(f, pattern) |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 3009 | break |
| 3010 | |
Daniel Cheng | 7052cdf | 2017-11-21 19:23:29 | [diff] [blame] | 3011 | return to_check |
| 3012 | |
| 3013 | |
Wez | 17c6696 | 2020-04-29 15:26:03 | [diff] [blame] | 3014 | def _AddOwnersFilesToCheckForFuchsiaSecurityOwners(input_api, to_check): |
| 3015 | """Adds OWNERS files to check for correct Fuchsia security owners.""" |
| 3016 | |
| 3017 | file_patterns = [ |
| 3018 | # Component specifications. |
| 3019 | '*.cml', # Component Framework v2. |
| 3020 | '*.cmx', # Component Framework v1. |
| 3021 | |
| 3022 | # Fuchsia IDL protocol specifications. |
| 3023 | '*.fidl', |
| 3024 | ] |
| 3025 | |
| 3026 | def AddPatternToCheck(input_file, pattern): |
| 3027 | owners_file = input_api.os_path.join( |
| 3028 | input_api.os_path.dirname(input_file.LocalPath()), 'OWNERS') |
| 3029 | if owners_file not in to_check: |
| 3030 | to_check[owners_file] = {} |
| 3031 | if pattern not in to_check[owners_file]: |
| 3032 | to_check[owners_file][pattern] = { |
| 3033 | 'files': [], |
| 3034 | 'rules': [ |
| 3035 | 'per-file %s=set noparent' % pattern, |
| 3036 | 'per-file %s=file://fuchsia/SECURITY_OWNERS' % pattern, |
| 3037 | ] |
| 3038 | } |
| 3039 | to_check[owners_file][pattern]['files'].append(input_file) |
| 3040 | |
| 3041 | # Iterate through the affected files to see what we actually need to check |
| 3042 | # for. We should only nag patch authors about per-file rules if a file in that |
| 3043 | # directory would match that pattern. |
| 3044 | for f in input_api.AffectedFiles(include_deletes=False): |
| 3045 | for pattern in file_patterns: |
| 3046 | if input_api.fnmatch.fnmatch( |
| 3047 | input_api.os_path.basename(f.LocalPath()), pattern): |
| 3048 | AddPatternToCheck(f, pattern) |
| 3049 | break |
| 3050 | |
| 3051 | return to_check |
| 3052 | |
| 3053 | |
| 3054 | def _CheckSecurityOwners(input_api, output_api): |
Daniel Cheng | 7052cdf | 2017-11-21 19:23:29 | [diff] [blame] | 3055 | """Checks that affected files involving IPC have an IPC OWNERS rule.""" |
| 3056 | to_check = _GetOwnersFilesToCheckForIpcOwners(input_api) |
Wez | 17c6696 | 2020-04-29 15:26:03 | [diff] [blame] | 3057 | _AddOwnersFilesToCheckForFuchsiaSecurityOwners(input_api, to_check) |
Daniel Cheng | 7052cdf | 2017-11-21 19:23:29 | [diff] [blame] | 3058 | |
| 3059 | if to_check: |
| 3060 | # If there are any OWNERS files to check, there are IPC-related changes in |
| 3061 | # this CL. Auto-CC the review list. |
| 3062 | output_api.AppendCC('[email protected]') |
| 3063 | |
| 3064 | # Go through the OWNERS files to check, filtering out rules that are already |
| 3065 | # present in that OWNERS file. |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 3066 | for owners_file, patterns in to_check.iteritems(): |
| 3067 | try: |
| 3068 | with file(owners_file) as f: |
| 3069 | lines = set(f.read().splitlines()) |
| 3070 | for entry in patterns.itervalues(): |
| 3071 | entry['rules'] = [rule for rule in entry['rules'] if rule not in lines |
| 3072 | ] |
| 3073 | except IOError: |
| 3074 | # No OWNERS file, so all the rules are definitely missing. |
| 3075 | continue |
| 3076 | |
| 3077 | # All the remaining lines weren't found in OWNERS files, so emit an error. |
| 3078 | errors = [] |
| 3079 | for owners_file, patterns in to_check.iteritems(): |
| 3080 | missing_lines = [] |
| 3081 | files = [] |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 3082 | for _, entry in patterns.iteritems(): |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 3083 | missing_lines.extend(entry['rules']) |
| 3084 | files.extend([' %s' % f.LocalPath() for f in entry['files']]) |
| 3085 | if missing_lines: |
| 3086 | errors.append( |
Vaclav Brozek | 1893a97 | 2018-04-25 05:48:05 | [diff] [blame] | 3087 | 'Because of the presence of files:\n%s\n\n' |
| 3088 | '%s needs the following %d lines added:\n\n%s' % |
| 3089 | ('\n'.join(files), owners_file, len(missing_lines), |
| 3090 | '\n'.join(missing_lines))) |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 3091 | |
| 3092 | results = [] |
| 3093 | if errors: |
vabr | f5ce3bf9 | 2016-07-11 14:52:41 | [diff] [blame] | 3094 | if input_api.is_committing: |
| 3095 | output = output_api.PresubmitError |
| 3096 | else: |
| 3097 | output = output_api.PresubmitPromptWarning |
| 3098 | results.append(output( |
Daniel Cheng | 5211169 | 2017-06-14 08:00:59 | [diff] [blame] | 3099 | 'Found OWNERS files that need to be updated for IPC security ' + |
| 3100 | 'review coverage.\nPlease update the OWNERS files below:', |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 3101 | long_text='\n\n'.join(errors))) |
| 3102 | |
| 3103 | return results |
| 3104 | |
| 3105 | |
Robert Sesek | 2c90533 | 2020-05-06 23:17:13 | [diff] [blame] | 3106 | def _GetFilesUsingSecurityCriticalFunctions(input_api): |
| 3107 | """Checks affected files for changes to security-critical calls. This |
| 3108 | function checks the full change diff, to catch both additions/changes |
| 3109 | and removals. |
| 3110 | |
| 3111 | Returns a dict keyed by file name, and the value is a set of detected |
| 3112 | functions. |
| 3113 | """ |
| 3114 | # Map of function pretty name (displayed in an error) to the pattern to |
| 3115 | # match it with. |
| 3116 | _PATTERNS_TO_CHECK = { |
Alex Gough | bc964dd | 2020-06-15 17:52:37 | [diff] [blame] | 3117 | 'content::GetServiceSandboxType<>()': |
| 3118 | 'GetServiceSandboxType\\<' |
Robert Sesek | 2c90533 | 2020-05-06 23:17:13 | [diff] [blame] | 3119 | } |
| 3120 | _PATTERNS_TO_CHECK = { |
| 3121 | k: input_api.re.compile(v) |
| 3122 | for k, v in _PATTERNS_TO_CHECK.items() |
| 3123 | } |
| 3124 | |
| 3125 | # Scan all affected files for changes touching _FUNCTIONS_TO_CHECK. |
| 3126 | files_to_functions = {} |
| 3127 | for f in input_api.AffectedFiles(): |
| 3128 | diff = f.GenerateScmDiff() |
| 3129 | for line in diff.split('\n'): |
| 3130 | # Not using just RightHandSideLines() because removing a |
| 3131 | # call to a security-critical function can be just as important |
| 3132 | # as adding or changing the arguments. |
| 3133 | if line.startswith('-') or (line.startswith('+') and |
| 3134 | not line.startswith('++')): |
| 3135 | for name, pattern in _PATTERNS_TO_CHECK.items(): |
| 3136 | if pattern.search(line): |
| 3137 | path = f.LocalPath() |
| 3138 | if not path in files_to_functions: |
| 3139 | files_to_functions[path] = set() |
| 3140 | files_to_functions[path].add(name) |
| 3141 | return files_to_functions |
| 3142 | |
| 3143 | |
| 3144 | def _CheckSecurityChanges(input_api, output_api): |
| 3145 | """Checks that changes involving security-critical functions are reviewed |
| 3146 | by the security team. |
| 3147 | """ |
| 3148 | files_to_functions = _GetFilesUsingSecurityCriticalFunctions(input_api) |
| 3149 | if len(files_to_functions): |
| 3150 | owners_db = input_api.owners_db |
| 3151 | owner_email, reviewers = ( |
| 3152 | input_api.canned_checks.GetCodereviewOwnerAndReviewers( |
| 3153 | input_api, |
| 3154 | owners_db.email_regexp, |
| 3155 | approval_needed=input_api.is_committing)) |
| 3156 | |
| 3157 | # Load the OWNERS file for security changes. |
| 3158 | owners_file = 'ipc/SECURITY_OWNERS' |
| 3159 | security_owners = owners_db.owners_rooted_at_file(owners_file) |
| 3160 | |
| 3161 | has_security_owner = any([owner in reviewers for owner in security_owners]) |
| 3162 | if not has_security_owner: |
| 3163 | msg = 'The following files change calls to security-sensive functions\n' \ |
| 3164 | 'that need to be reviewed by {}.\n'.format(owners_file) |
| 3165 | for path, names in files_to_functions.items(): |
| 3166 | msg += ' {}\n'.format(path) |
| 3167 | for name in names: |
| 3168 | msg += ' {}\n'.format(name) |
| 3169 | msg += '\n' |
| 3170 | |
| 3171 | if input_api.is_committing: |
| 3172 | output = output_api.PresubmitError |
| 3173 | else: |
| 3174 | output = output_api.PresubmitNotifyResult |
| 3175 | return [output(msg)] |
| 3176 | |
| 3177 | return [] |
| 3178 | |
| 3179 | |
Jochen Eisinger | f9fbe7b6c3 | 2019-11-18 09:37:26 | [diff] [blame] | 3180 | def _CheckSetNoParent(input_api, output_api): |
| 3181 | """Checks that set noparent is only used together with an OWNERS file in |
| 3182 | //build/OWNERS.setnoparent (see also |
| 3183 | //docs/code_reviews.md#owners-files-details) |
| 3184 | """ |
| 3185 | errors = [] |
| 3186 | |
| 3187 | allowed_owners_files_file = 'build/OWNERS.setnoparent' |
| 3188 | allowed_owners_files = set() |
| 3189 | with open(allowed_owners_files_file, 'r') as f: |
| 3190 | for line in f: |
| 3191 | line = line.strip() |
| 3192 | if not line or line.startswith('#'): |
| 3193 | continue |
| 3194 | allowed_owners_files.add(line) |
| 3195 | |
| 3196 | per_file_pattern = input_api.re.compile('per-file (.+)=(.+)') |
| 3197 | |
| 3198 | for f in input_api.AffectedFiles(include_deletes=False): |
| 3199 | if not f.LocalPath().endswith('OWNERS'): |
| 3200 | continue |
| 3201 | |
| 3202 | found_owners_files = set() |
| 3203 | found_set_noparent_lines = dict() |
| 3204 | |
| 3205 | # Parse the OWNERS file. |
| 3206 | for lineno, line in enumerate(f.NewContents(), 1): |
| 3207 | line = line.strip() |
| 3208 | if line.startswith('set noparent'): |
| 3209 | found_set_noparent_lines[''] = lineno |
| 3210 | if line.startswith('file://'): |
| 3211 | if line in allowed_owners_files: |
| 3212 | found_owners_files.add('') |
| 3213 | if line.startswith('per-file'): |
| 3214 | match = per_file_pattern.match(line) |
| 3215 | if match: |
| 3216 | glob = match.group(1).strip() |
| 3217 | directive = match.group(2).strip() |
| 3218 | if directive == 'set noparent': |
| 3219 | found_set_noparent_lines[glob] = lineno |
| 3220 | if directive.startswith('file://'): |
| 3221 | if directive in allowed_owners_files: |
| 3222 | found_owners_files.add(glob) |
| 3223 | |
| 3224 | # Check that every set noparent line has a corresponding file:// line |
| 3225 | # listed in build/OWNERS.setnoparent. |
| 3226 | for set_noparent_line in found_set_noparent_lines: |
| 3227 | if set_noparent_line in found_owners_files: |
| 3228 | continue |
| 3229 | errors.append(' %s:%d' % (f.LocalPath(), |
| 3230 | found_set_noparent_lines[set_noparent_line])) |
| 3231 | |
| 3232 | results = [] |
| 3233 | if errors: |
| 3234 | if input_api.is_committing: |
| 3235 | output = output_api.PresubmitError |
| 3236 | else: |
| 3237 | output = output_api.PresubmitPromptWarning |
| 3238 | results.append(output( |
| 3239 | 'Found the following "set noparent" restrictions in OWNERS files that ' |
| 3240 | 'do not include owners from build/OWNERS.setnoparent:', |
| 3241 | long_text='\n\n'.join(errors))) |
| 3242 | return results |
| 3243 | |
| 3244 | |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 3245 | def _CheckUselessForwardDeclarations(input_api, output_api): |
jbriance | 2c51e821a | 2016-12-12 08:24:31 | [diff] [blame] | 3246 | """Checks that added or removed lines in non third party affected |
| 3247 | header files do not lead to new useless class or struct forward |
| 3248 | declaration. |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 3249 | """ |
| 3250 | results = [] |
| 3251 | class_pattern = input_api.re.compile(r'^class\s+(\w+);$', |
| 3252 | input_api.re.MULTILINE) |
| 3253 | struct_pattern = input_api.re.compile(r'^struct\s+(\w+);$', |
| 3254 | input_api.re.MULTILINE) |
| 3255 | for f in input_api.AffectedFiles(include_deletes=False): |
jbriance | 2c51e821a | 2016-12-12 08:24:31 | [diff] [blame] | 3256 | if (f.LocalPath().startswith('third_party') and |
Kent Tamura | e9b3a9ec | 2017-08-31 02:20:19 | [diff] [blame] | 3257 | not f.LocalPath().startswith('third_party/blink') and |
Kent Tamura | 32dbbcb | 2018-11-30 12:28:49 | [diff] [blame] | 3258 | not f.LocalPath().startswith('third_party\\blink')): |
jbriance | 2c51e821a | 2016-12-12 08:24:31 | [diff] [blame] | 3259 | continue |
| 3260 | |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 3261 | if not f.LocalPath().endswith('.h'): |
| 3262 | continue |
| 3263 | |
| 3264 | contents = input_api.ReadFile(f) |
| 3265 | fwd_decls = input_api.re.findall(class_pattern, contents) |
| 3266 | fwd_decls.extend(input_api.re.findall(struct_pattern, contents)) |
| 3267 | |
| 3268 | useless_fwd_decls = [] |
| 3269 | for decl in fwd_decls: |
| 3270 | count = sum(1 for _ in input_api.re.finditer( |
| 3271 | r'\b%s\b' % input_api.re.escape(decl), contents)) |
| 3272 | if count == 1: |
| 3273 | useless_fwd_decls.append(decl) |
| 3274 | |
| 3275 | if not useless_fwd_decls: |
| 3276 | continue |
| 3277 | |
| 3278 | for line in f.GenerateScmDiff().splitlines(): |
| 3279 | if (line.startswith('-') and not line.startswith('--') or |
| 3280 | line.startswith('+') and not line.startswith('++')): |
| 3281 | for decl in useless_fwd_decls: |
| 3282 | if input_api.re.search(r'\b%s\b' % decl, line[1:]): |
| 3283 | results.append(output_api.PresubmitPromptWarning( |
ricea | 6416dea | 2017-05-19 12:39:24 | [diff] [blame] | 3284 | '%s: %s forward declaration is no longer needed' % |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 3285 | (f.LocalPath(), decl))) |
| 3286 | useless_fwd_decls.remove(decl) |
| 3287 | |
| 3288 | return results |
| 3289 | |
Jinsong Fan | 91ebbbd | 2019-04-16 14:57:17 | [diff] [blame] | 3290 | def _CheckAndroidDebuggableBuild(input_api, output_api): |
| 3291 | """Checks that code uses BuildInfo.isDebugAndroid() instead of |
| 3292 | Build.TYPE.equals('') or ''.equals(Build.TYPE) to check if |
| 3293 | this is a debuggable build of Android. |
| 3294 | """ |
| 3295 | build_type_check_pattern = input_api.re.compile( |
| 3296 | r'\bBuild\.TYPE\.equals\(|\.equals\(\s*\bBuild\.TYPE\)') |
| 3297 | |
| 3298 | errors = [] |
| 3299 | |
| 3300 | sources = lambda affected_file: input_api.FilterSourceFile( |
| 3301 | affected_file, |
| 3302 | black_list=(_EXCLUDED_PATHS + |
| 3303 | _TEST_CODE_EXCLUDED_PATHS + |
| 3304 | input_api.DEFAULT_BLACK_LIST + |
| 3305 | (r"^android_webview[\\/]support_library[\\/]" |
| 3306 | "boundary_interfaces[\\/]", |
| 3307 | r"^chrome[\\/]android[\\/]webapk[\\/].*", |
| 3308 | r'^third_party[\\/].*', |
| 3309 | r"tools[\\/]android[\\/]customtabs_benchmark[\\/].*", |
| 3310 | r"webview[\\/]chromium[\\/]License.*",)), |
| 3311 | white_list=[r'.*\.java$']) |
| 3312 | |
| 3313 | for f in input_api.AffectedSourceFiles(sources): |
| 3314 | for line_num, line in f.ChangedContents(): |
| 3315 | if build_type_check_pattern.search(line): |
| 3316 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 3317 | |
| 3318 | results = [] |
| 3319 | |
| 3320 | if errors: |
| 3321 | results.append(output_api.PresubmitPromptWarning( |
| 3322 | 'Build.TYPE.equals or .equals(Build.TYPE) usage is detected.' |
| 3323 | ' Please use BuildInfo.isDebugAndroid() instead.', |
| 3324 | errors)) |
| 3325 | |
| 3326 | return results |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 3327 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 3328 | # TODO: add unit tests |
dskiba | 88634f4e | 2015-08-14 23:03:29 | [diff] [blame] | 3329 | def _CheckAndroidToastUsage(input_api, output_api): |
| 3330 | """Checks that code uses org.chromium.ui.widget.Toast instead of |
| 3331 | android.widget.Toast (Chromium Toast doesn't force hardware |
| 3332 | acceleration on low-end devices, saving memory). |
| 3333 | """ |
| 3334 | toast_import_pattern = input_api.re.compile( |
| 3335 | r'^import android\.widget\.Toast;$') |
| 3336 | |
| 3337 | errors = [] |
| 3338 | |
| 3339 | sources = lambda affected_file: input_api.FilterSourceFile( |
| 3340 | affected_file, |
| 3341 | black_list=(_EXCLUDED_PATHS + |
| 3342 | _TEST_CODE_EXCLUDED_PATHS + |
| 3343 | input_api.DEFAULT_BLACK_LIST + |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 3344 | (r'^chromecast[\\/].*', |
| 3345 | r'^remoting[\\/].*')), |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 3346 | white_list=[r'.*\.java$']) |
dskiba | 88634f4e | 2015-08-14 23:03:29 | [diff] [blame] | 3347 | |
| 3348 | for f in input_api.AffectedSourceFiles(sources): |
| 3349 | for line_num, line in f.ChangedContents(): |
| 3350 | if toast_import_pattern.search(line): |
| 3351 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 3352 | |
| 3353 | results = [] |
| 3354 | |
| 3355 | if errors: |
| 3356 | results.append(output_api.PresubmitError( |
| 3357 | 'android.widget.Toast usage is detected. Android toasts use hardware' |
| 3358 | ' acceleration, and can be\ncostly on low-end devices. Please use' |
| 3359 | ' org.chromium.ui.widget.Toast instead.\n' |
| 3360 | 'Contact [email protected] if you have any questions.', |
| 3361 | errors)) |
| 3362 | |
| 3363 | return results |
| 3364 | |
| 3365 | |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3366 | def _CheckAndroidCrLogUsage(input_api, output_api): |
| 3367 | """Checks that new logs using org.chromium.base.Log: |
| 3368 | - Are using 'TAG' as variable name for the tags (warn) |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 3369 | - Are using a tag that is shorter than 20 characters (error) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3370 | """ |
pkotwicz | a1dd0b00 | 2016-05-16 14:41:04 | [diff] [blame] | 3371 | |
torne | 8954062 | 2017-03-24 19:41:30 | [diff] [blame] | 3372 | # Do not check format of logs in the given files |
pkotwicz | a1dd0b00 | 2016-05-16 14:41:04 | [diff] [blame] | 3373 | cr_log_check_excluded_paths = [ |
torne | 8954062 | 2017-03-24 19:41:30 | [diff] [blame] | 3374 | # //chrome/android/webapk cannot depend on //base |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 3375 | r"^chrome[\\/]android[\\/]webapk[\\/].*", |
torne | 8954062 | 2017-03-24 19:41:30 | [diff] [blame] | 3376 | # WebView license viewer code cannot depend on //base; used in stub APK. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 3377 | r"^android_webview[\\/]glue[\\/]java[\\/]src[\\/]com[\\/]android[\\/]" |
| 3378 | r"webview[\\/]chromium[\\/]License.*", |
Egor Pasko | a5c05b0 | 2018-09-28 16:04:09 | [diff] [blame] | 3379 | # The customtabs_benchmark is a small app that does not depend on Chromium |
| 3380 | # java pieces. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 3381 | r"tools[\\/]android[\\/]customtabs_benchmark[\\/].*", |
pkotwicz | a1dd0b00 | 2016-05-16 14:41:04 | [diff] [blame] | 3382 | ] |
| 3383 | |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3384 | cr_log_import_pattern = input_api.re.compile( |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 3385 | r'^import org\.chromium\.base\.Log;$', input_api.re.MULTILINE) |
| 3386 | class_in_base_pattern = input_api.re.compile( |
| 3387 | r'^package org\.chromium\.base;$', input_api.re.MULTILINE) |
| 3388 | has_some_log_import_pattern = input_api.re.compile( |
| 3389 | r'^import .*\.Log;$', input_api.re.MULTILINE) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3390 | # Extract the tag from lines like `Log.d(TAG, "*");` or `Log.d("TAG", "*");` |
Tomasz Śniatowski | 3ae2f10 | 2020-03-23 15:35:55 | [diff] [blame] | 3391 | log_call_pattern = input_api.re.compile(r'\bLog\.\w\((?P<tag>\"?\w+)') |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3392 | log_decl_pattern = input_api.re.compile( |
Torne (Richard Coles) | 3bd7ad0 | 2019-10-22 21:20:46 | [diff] [blame] | 3393 | r'static final String TAG = "(?P<name>(.*))"') |
Tomasz Śniatowski | 3ae2f10 | 2020-03-23 15:35:55 | [diff] [blame] | 3394 | rough_log_decl_pattern = input_api.re.compile(r'\bString TAG\s*=') |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3395 | |
Torne (Richard Coles) | 3bd7ad0 | 2019-10-22 21:20:46 | [diff] [blame] | 3396 | REF_MSG = ('See docs/android_logging.md for more info.') |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 3397 | sources = lambda x: input_api.FilterSourceFile(x, white_list=[r'.*\.java$'], |
pkotwicz | a1dd0b00 | 2016-05-16 14:41:04 | [diff] [blame] | 3398 | black_list=cr_log_check_excluded_paths) |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 3399 | |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3400 | tag_decl_errors = [] |
| 3401 | tag_length_errors = [] |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 3402 | tag_errors = [] |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 3403 | tag_with_dot_errors = [] |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 3404 | util_log_errors = [] |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3405 | |
| 3406 | for f in input_api.AffectedSourceFiles(sources): |
| 3407 | file_content = input_api.ReadFile(f) |
| 3408 | has_modified_logs = False |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3409 | # Per line checks |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 3410 | if (cr_log_import_pattern.search(file_content) or |
| 3411 | (class_in_base_pattern.search(file_content) and |
| 3412 | not has_some_log_import_pattern.search(file_content))): |
| 3413 | # Checks to run for files using cr log |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3414 | for line_num, line in f.ChangedContents(): |
Tomasz Śniatowski | 3ae2f10 | 2020-03-23 15:35:55 | [diff] [blame] | 3415 | if rough_log_decl_pattern.search(line): |
| 3416 | has_modified_logs = True |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3417 | |
| 3418 | # Check if the new line is doing some logging |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 3419 | match = log_call_pattern.search(line) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3420 | if match: |
| 3421 | has_modified_logs = True |
| 3422 | |
| 3423 | # Make sure it uses "TAG" |
| 3424 | if not match.group('tag') == 'TAG': |
| 3425 | tag_errors.append("%s:%d" % (f.LocalPath(), line_num)) |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 3426 | else: |
| 3427 | # Report non cr Log function calls in changed lines |
| 3428 | for line_num, line in f.ChangedContents(): |
| 3429 | if log_call_pattern.search(line): |
| 3430 | util_log_errors.append("%s:%d" % (f.LocalPath(), line_num)) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3431 | |
| 3432 | # Per file checks |
| 3433 | if has_modified_logs: |
| 3434 | # Make sure the tag is using the "cr" prefix and is not too long |
| 3435 | match = log_decl_pattern.search(file_content) |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 3436 | tag_name = match.group('name') if match else None |
| 3437 | if not tag_name: |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3438 | tag_decl_errors.append(f.LocalPath()) |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 3439 | elif len(tag_name) > 20: |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3440 | tag_length_errors.append(f.LocalPath()) |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 3441 | elif '.' in tag_name: |
| 3442 | tag_with_dot_errors.append(f.LocalPath()) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3443 | |
| 3444 | results = [] |
| 3445 | if tag_decl_errors: |
| 3446 | results.append(output_api.PresubmitPromptWarning( |
| 3447 | 'Please define your tags using the suggested format: .\n' |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 3448 | '"private static final String TAG = "<package tag>".\n' |
| 3449 | 'They will be prepended with "cr_" automatically.\n' + REF_MSG, |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3450 | tag_decl_errors)) |
| 3451 | |
| 3452 | if tag_length_errors: |
| 3453 | results.append(output_api.PresubmitError( |
| 3454 | 'The tag length is restricted by the system to be at most ' |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 3455 | '20 characters.\n' + REF_MSG, |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3456 | tag_length_errors)) |
| 3457 | |
| 3458 | if tag_errors: |
| 3459 | results.append(output_api.PresubmitPromptWarning( |
| 3460 | 'Please use a variable named "TAG" for your log tags.\n' + REF_MSG, |
| 3461 | tag_errors)) |
| 3462 | |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 3463 | if util_log_errors: |
dgn | 4401aa5 | 2015-04-29 16:26:17 | [diff] [blame] | 3464 | results.append(output_api.PresubmitPromptWarning( |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 3465 | 'Please use org.chromium.base.Log for new logs.\n' + REF_MSG, |
| 3466 | util_log_errors)) |
| 3467 | |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 3468 | if tag_with_dot_errors: |
| 3469 | results.append(output_api.PresubmitPromptWarning( |
| 3470 | 'Dot in log tags cause them to be elided in crash reports.\n' + REF_MSG, |
| 3471 | tag_with_dot_errors)) |
| 3472 | |
dgn | 4401aa5 | 2015-04-29 16:26:17 | [diff] [blame] | 3473 | return results |
| 3474 | |
| 3475 | |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 3476 | def _CheckAndroidTestJUnitFrameworkImport(input_api, output_api): |
| 3477 | """Checks that junit.framework.* is no longer used.""" |
| 3478 | deprecated_junit_framework_pattern = input_api.re.compile( |
| 3479 | r'^import junit\.framework\..*;', |
| 3480 | input_api.re.MULTILINE) |
| 3481 | sources = lambda x: input_api.FilterSourceFile( |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 3482 | x, white_list=[r'.*\.java$'], black_list=None) |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 3483 | errors = [] |
Edward Lemur | 7bbfdf1 | 2020-01-15 02:06:13 | [diff] [blame] | 3484 | for f in input_api.AffectedFiles(file_filter=sources): |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 3485 | for line_num, line in f.ChangedContents(): |
| 3486 | if deprecated_junit_framework_pattern.search(line): |
| 3487 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 3488 | |
| 3489 | results = [] |
| 3490 | if errors: |
| 3491 | results.append(output_api.PresubmitError( |
| 3492 | 'APIs from junit.framework.* are deprecated, please use JUnit4 framework' |
| 3493 | '(org.junit.*) from //third_party/junit. Contact [email protected]' |
| 3494 | ' if you have any question.', errors)) |
| 3495 | return results |
| 3496 | |
| 3497 | |
| 3498 | def _CheckAndroidTestJUnitInheritance(input_api, output_api): |
| 3499 | """Checks that if new Java test classes have inheritance. |
| 3500 | Either the new test class is JUnit3 test or it is a JUnit4 test class |
| 3501 | with a base class, either case is undesirable. |
| 3502 | """ |
| 3503 | class_declaration_pattern = input_api.re.compile(r'^public class \w*Test ') |
| 3504 | |
| 3505 | sources = lambda x: input_api.FilterSourceFile( |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 3506 | x, white_list=[r'.*Test\.java$'], black_list=None) |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 3507 | errors = [] |
Edward Lemur | 7bbfdf1 | 2020-01-15 02:06:13 | [diff] [blame] | 3508 | for f in input_api.AffectedFiles(file_filter=sources): |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 3509 | if not f.OldContents(): |
| 3510 | class_declaration_start_flag = False |
| 3511 | for line_num, line in f.ChangedContents(): |
| 3512 | if class_declaration_pattern.search(line): |
| 3513 | class_declaration_start_flag = True |
| 3514 | if class_declaration_start_flag and ' extends ' in line: |
| 3515 | errors.append('%s:%d' % (f.LocalPath(), line_num)) |
| 3516 | if '{' in line: |
| 3517 | class_declaration_start_flag = False |
| 3518 | |
| 3519 | results = [] |
| 3520 | if errors: |
| 3521 | results.append(output_api.PresubmitPromptWarning( |
| 3522 | 'The newly created files include Test classes that inherits from base' |
| 3523 | ' class. Please do not use inheritance in JUnit4 tests or add new' |
| 3524 | ' JUnit3 tests. Contact [email protected] if you have any' |
| 3525 | ' questions.', errors)) |
| 3526 | return results |
| 3527 | |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 3528 | |
yolandyan | 4500147 | 2016-12-21 21:12:42 | [diff] [blame] | 3529 | def _CheckAndroidTestAnnotationUsage(input_api, output_api): |
| 3530 | """Checks that android.test.suitebuilder.annotation.* is no longer used.""" |
| 3531 | deprecated_annotation_import_pattern = input_api.re.compile( |
| 3532 | r'^import android\.test\.suitebuilder\.annotation\..*;', |
| 3533 | input_api.re.MULTILINE) |
| 3534 | sources = lambda x: input_api.FilterSourceFile( |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 3535 | x, white_list=[r'.*\.java$'], black_list=None) |
yolandyan | 4500147 | 2016-12-21 21:12:42 | [diff] [blame] | 3536 | errors = [] |
Edward Lemur | 7bbfdf1 | 2020-01-15 02:06:13 | [diff] [blame] | 3537 | for f in input_api.AffectedFiles(file_filter=sources): |
yolandyan | 4500147 | 2016-12-21 21:12:42 | [diff] [blame] | 3538 | for line_num, line in f.ChangedContents(): |
| 3539 | if deprecated_annotation_import_pattern.search(line): |
| 3540 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 3541 | |
| 3542 | results = [] |
| 3543 | if errors: |
| 3544 | results.append(output_api.PresubmitError( |
| 3545 | 'Annotations in android.test.suitebuilder.annotation have been' |
| 3546 | ' deprecated since API level 24. Please use android.support.test.filters' |
| 3547 | ' from //third_party/android_support_test_runner:runner_java instead.' |
| 3548 | ' Contact [email protected] if you have any questions.', errors)) |
| 3549 | return results |
| 3550 | |
| 3551 | |
agrieve | 7b6479d8 | 2015-10-07 14:24:22 | [diff] [blame] | 3552 | def _CheckAndroidNewMdpiAssetLocation(input_api, output_api): |
| 3553 | """Checks if MDPI assets are placed in a correct directory.""" |
| 3554 | file_filter = lambda f: (f.LocalPath().endswith('.png') and |
| 3555 | ('/res/drawable/' in f.LocalPath() or |
| 3556 | '/res/drawable-ldrtl/' in f.LocalPath())) |
| 3557 | errors = [] |
| 3558 | for f in input_api.AffectedFiles(include_deletes=False, |
| 3559 | file_filter=file_filter): |
| 3560 | errors.append(' %s' % f.LocalPath()) |
| 3561 | |
| 3562 | results = [] |
| 3563 | if errors: |
| 3564 | results.append(output_api.PresubmitError( |
| 3565 | 'MDPI assets should be placed in /res/drawable-mdpi/ or ' |
| 3566 | '/res/drawable-ldrtl-mdpi/\ninstead of /res/drawable/ and' |
| 3567 | '/res/drawable-ldrtl/.\n' |
| 3568 | 'Contact [email protected] if you have questions.', errors)) |
| 3569 | return results |
| 3570 | |
| 3571 | |
Nate Fischer | 535972b | 2017-09-16 01:06:18 | [diff] [blame] | 3572 | def _CheckAndroidWebkitImports(input_api, output_api): |
| 3573 | """Checks that code uses org.chromium.base.Callback instead of |
Bo Liu | bfde1c0 | 2019-09-24 23:08:35 | [diff] [blame] | 3574 | android.webview.ValueCallback except in the WebView glue layer |
| 3575 | and WebLayer. |
Nate Fischer | 535972b | 2017-09-16 01:06:18 | [diff] [blame] | 3576 | """ |
| 3577 | valuecallback_import_pattern = input_api.re.compile( |
| 3578 | r'^import android\.webkit\.ValueCallback;$') |
| 3579 | |
| 3580 | errors = [] |
| 3581 | |
| 3582 | sources = lambda affected_file: input_api.FilterSourceFile( |
| 3583 | affected_file, |
| 3584 | black_list=(_EXCLUDED_PATHS + |
| 3585 | _TEST_CODE_EXCLUDED_PATHS + |
| 3586 | input_api.DEFAULT_BLACK_LIST + |
Bo Liu | bfde1c0 | 2019-09-24 23:08:35 | [diff] [blame] | 3587 | (r'^android_webview[\\/]glue[\\/].*', |
| 3588 | r'^weblayer[\\/].*',)), |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 3589 | white_list=[r'.*\.java$']) |
Nate Fischer | 535972b | 2017-09-16 01:06:18 | [diff] [blame] | 3590 | |
| 3591 | for f in input_api.AffectedSourceFiles(sources): |
| 3592 | for line_num, line in f.ChangedContents(): |
| 3593 | if valuecallback_import_pattern.search(line): |
| 3594 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 3595 | |
| 3596 | results = [] |
| 3597 | |
| 3598 | if errors: |
| 3599 | results.append(output_api.PresubmitError( |
| 3600 | 'android.webkit.ValueCallback usage is detected outside of the glue' |
| 3601 | ' layer. To stay compatible with the support library, android.webkit.*' |
| 3602 | ' classes should only be used inside the glue layer and' |
| 3603 | ' org.chromium.base.Callback should be used instead.', |
| 3604 | errors)) |
| 3605 | |
| 3606 | return results |
| 3607 | |
| 3608 | |
Becky Zhou | 7c69b5099 | 2018-12-10 19:37:57 | [diff] [blame] | 3609 | def _CheckAndroidXmlStyle(input_api, output_api, is_check_on_upload): |
| 3610 | """Checks Android XML styles """ |
| 3611 | import sys |
| 3612 | original_sys_path = sys.path |
| 3613 | try: |
| 3614 | sys.path = sys.path + [input_api.os_path.join( |
| 3615 | input_api.PresubmitLocalPath(), 'tools', 'android', 'checkxmlstyle')] |
| 3616 | import checkxmlstyle |
| 3617 | finally: |
| 3618 | # Restore sys.path to what it was before. |
| 3619 | sys.path = original_sys_path |
| 3620 | |
| 3621 | if is_check_on_upload: |
| 3622 | return checkxmlstyle.CheckStyleOnUpload(input_api, output_api) |
| 3623 | else: |
| 3624 | return checkxmlstyle.CheckStyleOnCommit(input_api, output_api) |
| 3625 | |
| 3626 | |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3627 | class PydepsChecker(object): |
| 3628 | def __init__(self, input_api, pydeps_files): |
| 3629 | self._file_cache = {} |
| 3630 | self._input_api = input_api |
| 3631 | self._pydeps_files = pydeps_files |
| 3632 | |
| 3633 | def _LoadFile(self, path): |
| 3634 | """Returns the list of paths within a .pydeps file relative to //.""" |
| 3635 | if path not in self._file_cache: |
| 3636 | with open(path) as f: |
| 3637 | self._file_cache[path] = f.read() |
| 3638 | return self._file_cache[path] |
| 3639 | |
| 3640 | def _ComputeNormalizedPydepsEntries(self, pydeps_path): |
| 3641 | """Returns an interable of paths within the .pydep, relativized to //.""" |
| 3642 | os_path = self._input_api.os_path |
| 3643 | pydeps_dir = os_path.dirname(pydeps_path) |
| 3644 | entries = (l.rstrip() for l in self._LoadFile(pydeps_path).splitlines() |
| 3645 | if not l.startswith('*')) |
| 3646 | return (os_path.normpath(os_path.join(pydeps_dir, e)) for e in entries) |
| 3647 | |
| 3648 | def _CreateFilesToPydepsMap(self): |
| 3649 | """Returns a map of local_path -> list_of_pydeps.""" |
| 3650 | ret = {} |
| 3651 | for pydep_local_path in self._pydeps_files: |
| 3652 | for path in self._ComputeNormalizedPydepsEntries(pydep_local_path): |
| 3653 | ret.setdefault(path, []).append(pydep_local_path) |
| 3654 | return ret |
| 3655 | |
| 3656 | def ComputeAffectedPydeps(self): |
| 3657 | """Returns an iterable of .pydeps files that might need regenerating.""" |
| 3658 | affected_pydeps = set() |
| 3659 | file_to_pydeps_map = None |
| 3660 | for f in self._input_api.AffectedFiles(include_deletes=True): |
| 3661 | local_path = f.LocalPath() |
Andrew Grieve | 892bb3f | 2019-03-20 17:33:46 | [diff] [blame] | 3662 | # Changes to DEPS can lead to .pydeps changes if any .py files are in |
| 3663 | # subrepositories. We can't figure out which files change, so re-check |
| 3664 | # all files. |
| 3665 | # Changes to print_python_deps.py affect all .pydeps. |
Andrew Grieve | b773bad | 2020-06-05 18:00:38 | [diff] [blame] | 3666 | if local_path in ('DEPS', 'PRESUBMIT.py') or local_path.endswith( |
| 3667 | 'print_python_deps.py'): |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3668 | return self._pydeps_files |
| 3669 | elif local_path.endswith('.pydeps'): |
| 3670 | if local_path in self._pydeps_files: |
| 3671 | affected_pydeps.add(local_path) |
| 3672 | elif local_path.endswith('.py'): |
| 3673 | if file_to_pydeps_map is None: |
| 3674 | file_to_pydeps_map = self._CreateFilesToPydepsMap() |
| 3675 | affected_pydeps.update(file_to_pydeps_map.get(local_path, ())) |
| 3676 | return affected_pydeps |
| 3677 | |
| 3678 | def DetermineIfStale(self, pydeps_path): |
| 3679 | """Runs print_python_deps.py to see if the files is stale.""" |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 3680 | import difflib |
John Budorick | 47ca3fe | 2018-02-10 00:53:10 | [diff] [blame] | 3681 | import os |
| 3682 | |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3683 | old_pydeps_data = self._LoadFile(pydeps_path).splitlines() |
Mohamed Heikal | e217fc85 | 2020-07-06 19:44:03 | [diff] [blame] | 3684 | if old_pydeps_data: |
| 3685 | cmd = old_pydeps_data[1][1:].strip() |
| 3686 | old_contents = old_pydeps_data[2:] |
| 3687 | else: |
| 3688 | # A default cmd that should work in most cases (as long as pydeps filename |
| 3689 | # matches the script name) so that PRESUBMIT.py does not crash if pydeps |
| 3690 | # file is empty/new. |
| 3691 | cmd = 'build/print_python_deps.py {} --root={} --output={}'.format( |
| 3692 | pydeps_path[:-4], os.path.dirname(pydeps_path), pydeps_path) |
| 3693 | old_contents = [] |
John Budorick | 47ca3fe | 2018-02-10 00:53:10 | [diff] [blame] | 3694 | env = dict(os.environ) |
| 3695 | env['PYTHONDONTWRITEBYTECODE'] = '1' |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3696 | new_pydeps_data = self._input_api.subprocess.check_output( |
John Budorick | 47ca3fe | 2018-02-10 00:53:10 | [diff] [blame] | 3697 | cmd + ' --output ""', shell=True, env=env) |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 3698 | new_contents = new_pydeps_data.splitlines()[2:] |
Mohamed Heikal | e217fc85 | 2020-07-06 19:44:03 | [diff] [blame] | 3699 | if old_contents != new_contents: |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 3700 | return cmd, '\n'.join(difflib.context_diff(old_contents, new_contents)) |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3701 | |
| 3702 | |
Tibor Goldschwendt | 360793f7 | 2019-06-25 18:23:49 | [diff] [blame] | 3703 | def _ParseGclientArgs(): |
| 3704 | args = {} |
| 3705 | with open('build/config/gclient_args.gni', 'r') as f: |
| 3706 | for line in f: |
| 3707 | line = line.strip() |
| 3708 | if not line or line.startswith('#'): |
| 3709 | continue |
| 3710 | attribute, value = line.split('=') |
| 3711 | args[attribute.strip()] = value.strip() |
| 3712 | return args |
| 3713 | |
| 3714 | |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3715 | def _CheckPydepsNeedsUpdating(input_api, output_api, checker_for_tests=None): |
| 3716 | """Checks if a .pydeps file needs to be regenerated.""" |
John Chen | cde8919 | 2018-01-27 21:18:40 | [diff] [blame] | 3717 | # This check is for Python dependency lists (.pydeps files), and involves |
| 3718 | # paths not only in the PRESUBMIT.py, but also in the .pydeps files. It |
| 3719 | # doesn't work on Windows and Mac, so skip it on other platforms. |
agrieve | 9bc4200b | 2016-05-04 16:33:28 | [diff] [blame] | 3720 | if input_api.platform != 'linux2': |
agrieve | bb9c5b47 | 2016-04-22 15:13:00 | [diff] [blame] | 3721 | return [] |
Tibor Goldschwendt | 360793f7 | 2019-06-25 18:23:49 | [diff] [blame] | 3722 | is_android = _ParseGclientArgs().get('checkout_android', 'false') == 'true' |
Mohamed Heikal | 7cd4d831 | 2020-06-16 16:49:40 | [diff] [blame] | 3723 | pydeps_to_check = _ALL_PYDEPS_FILES if is_android else _GENERIC_PYDEPS_FILES |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3724 | results = [] |
| 3725 | # First, check for new / deleted .pydeps. |
| 3726 | for f in input_api.AffectedFiles(include_deletes=True): |
Zhiling Huang | 45cabf3 | 2018-03-10 00:50:03 | [diff] [blame] | 3727 | # Check whether we are running the presubmit check for a file in src. |
| 3728 | # f.LocalPath is relative to repo (src, or internal repo). |
| 3729 | # os_path.exists is relative to src repo. |
| 3730 | # Therefore if os_path.exists is true, it means f.LocalPath is relative |
| 3731 | # to src and we can conclude that the pydeps is in src. |
| 3732 | if input_api.os_path.exists(f.LocalPath()): |
| 3733 | if f.LocalPath().endswith('.pydeps'): |
| 3734 | if f.Action() == 'D' and f.LocalPath() in _ALL_PYDEPS_FILES: |
| 3735 | results.append(output_api.PresubmitError( |
| 3736 | 'Please update _ALL_PYDEPS_FILES within //PRESUBMIT.py to ' |
| 3737 | 'remove %s' % f.LocalPath())) |
| 3738 | elif f.Action() != 'D' and f.LocalPath() not in _ALL_PYDEPS_FILES: |
| 3739 | results.append(output_api.PresubmitError( |
| 3740 | 'Please update _ALL_PYDEPS_FILES within //PRESUBMIT.py to ' |
| 3741 | 'include %s' % f.LocalPath())) |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3742 | |
| 3743 | if results: |
| 3744 | return results |
| 3745 | |
Mohamed Heikal | 7cd4d831 | 2020-06-16 16:49:40 | [diff] [blame] | 3746 | checker = checker_for_tests or PydepsChecker(input_api, _ALL_PYDEPS_FILES) |
| 3747 | affected_pydeps = set(checker.ComputeAffectedPydeps()) |
| 3748 | affected_android_pydeps = affected_pydeps.intersection( |
| 3749 | set(_ANDROID_SPECIFIC_PYDEPS_FILES)) |
| 3750 | if affected_android_pydeps and not is_android: |
| 3751 | results.append(output_api.PresubmitPromptOrNotify( |
| 3752 | 'You have changed python files that may affect pydeps for android\n' |
| 3753 | 'specific scripts. However, the relevant presumbit check cannot be\n' |
| 3754 | 'run because you are not using an Android checkout. To validate that\n' |
| 3755 | 'the .pydeps are correct, re-run presubmit in an Android checkout, or\n' |
| 3756 | 'use the android-internal-presubmit optional trybot.\n' |
| 3757 | 'Possibly stale pydeps files:\n{}'.format( |
| 3758 | '\n'.join(affected_android_pydeps)))) |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3759 | |
Mohamed Heikal | 7cd4d831 | 2020-06-16 16:49:40 | [diff] [blame] | 3760 | affected_pydeps_to_check = affected_pydeps.intersection(set(pydeps_to_check)) |
| 3761 | for pydep_path in affected_pydeps_to_check: |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3762 | try: |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 3763 | result = checker.DetermineIfStale(pydep_path) |
| 3764 | if result: |
| 3765 | cmd, diff = result |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3766 | results.append(output_api.PresubmitError( |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 3767 | 'File is stale: %s\nDiff (apply to fix):\n%s\n' |
| 3768 | 'To regenerate, run:\n\n %s' % |
| 3769 | (pydep_path, diff, cmd))) |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3770 | except input_api.subprocess.CalledProcessError as error: |
| 3771 | return [output_api.PresubmitError('Error running: %s' % error.cmd, |
| 3772 | long_text=error.output)] |
| 3773 | |
| 3774 | return results |
| 3775 | |
| 3776 | |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 3777 | def _CheckSingletonInHeaders(input_api, output_api): |
| 3778 | """Checks to make sure no header files have |Singleton<|.""" |
| 3779 | def FileFilter(affected_file): |
| 3780 | # It's ok for base/memory/singleton.h to have |Singleton<|. |
| 3781 | black_list = (_EXCLUDED_PATHS + |
| 3782 | input_api.DEFAULT_BLACK_LIST + |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 3783 | (r"^base[\\/]memory[\\/]singleton\.h$", |
| 3784 | r"^net[\\/]quic[\\/]platform[\\/]impl[\\/]" |
Michael Warres | e445149 | 2018-03-07 04:42:47 | [diff] [blame] | 3785 | r"quic_singleton_impl\.h$")) |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 3786 | return input_api.FilterSourceFile(affected_file, black_list=black_list) |
| 3787 | |
sergeyu | 34d2122 | 2015-09-16 00:11:44 | [diff] [blame] | 3788 | pattern = input_api.re.compile(r'(?<!class\sbase::)Singleton\s*<') |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 3789 | files = [] |
| 3790 | for f in input_api.AffectedSourceFiles(FileFilter): |
| 3791 | if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or |
| 3792 | f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): |
| 3793 | contents = input_api.ReadFile(f) |
| 3794 | for line in contents.splitlines(False): |
oysteine | c430ad4 | 2015-10-22 20:55:24 | [diff] [blame] | 3795 | if (not line.lstrip().startswith('//') and # Strip C++ comment. |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 3796 | pattern.search(line)): |
| 3797 | files.append(f) |
| 3798 | break |
| 3799 | |
| 3800 | if files: |
yolandyan | daabc6d | 2016-04-18 18:29:39 | [diff] [blame] | 3801 | return [output_api.PresubmitError( |
sergeyu | 34d2122 | 2015-09-16 00:11:44 | [diff] [blame] | 3802 | 'Found base::Singleton<T> in the following header files.\n' + |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 3803 | 'Please move them to an appropriate source file so that the ' + |
| 3804 | 'template gets instantiated in a single compilation unit.', |
| 3805 | files) ] |
| 3806 | return [] |
| 3807 | |
| 3808 | |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 3809 | _DEPRECATED_CSS = [ |
| 3810 | # Values |
| 3811 | ( "-webkit-box", "flex" ), |
| 3812 | ( "-webkit-inline-box", "inline-flex" ), |
| 3813 | ( "-webkit-flex", "flex" ), |
| 3814 | ( "-webkit-inline-flex", "inline-flex" ), |
| 3815 | ( "-webkit-min-content", "min-content" ), |
| 3816 | ( "-webkit-max-content", "max-content" ), |
| 3817 | |
| 3818 | # Properties |
| 3819 | ( "-webkit-background-clip", "background-clip" ), |
| 3820 | ( "-webkit-background-origin", "background-origin" ), |
| 3821 | ( "-webkit-background-size", "background-size" ), |
| 3822 | ( "-webkit-box-shadow", "box-shadow" ), |
dbeam | 6936c67f | 2017-01-19 01:51:44 | [diff] [blame] | 3823 | ( "-webkit-user-select", "user-select" ), |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 3824 | |
| 3825 | # Functions |
| 3826 | ( "-webkit-gradient", "gradient" ), |
| 3827 | ( "-webkit-repeating-gradient", "repeating-gradient" ), |
| 3828 | ( "-webkit-linear-gradient", "linear-gradient" ), |
| 3829 | ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ), |
| 3830 | ( "-webkit-radial-gradient", "radial-gradient" ), |
| 3831 | ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ), |
| 3832 | ] |
| 3833 | |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 3834 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 3835 | # TODO: add unit tests |
dbeam | 1ec68ac | 2016-12-15 05:22:24 | [diff] [blame] | 3836 | def _CheckNoDeprecatedCss(input_api, output_api): |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 3837 | """ Make sure that we don't use deprecated CSS |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 3838 | properties, functions or values. Our external |
mdjones | ae0286c3 | 2015-06-10 18:10:34 | [diff] [blame] | 3839 | documentation and iOS CSS for dom distiller |
| 3840 | (reader mode) are ignored by the hooks as it |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 3841 | needs to be consumed by WebKit. """ |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 3842 | results = [] |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 3843 | file_inclusion_pattern = [r".+\.css$"] |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 3844 | black_list = (_EXCLUDED_PATHS + |
| 3845 | _TEST_CODE_EXCLUDED_PATHS + |
| 3846 | input_api.DEFAULT_BLACK_LIST + |
| 3847 | (r"^chrome/common/extensions/docs", |
| 3848 | r"^chrome/docs", |
mdjones | ae0286c3 | 2015-06-10 18:10:34 | [diff] [blame] | 3849 | r"^components/dom_distiller/core/css/distilledpage_ios.css", |
sdefresne | 6308d7f | 2016-02-15 09:38:44 | [diff] [blame] | 3850 | r"^components/neterror/resources/neterror.css", |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 3851 | r"^native_client_sdk")) |
| 3852 | file_filter = lambda f: input_api.FilterSourceFile( |
| 3853 | f, white_list=file_inclusion_pattern, black_list=black_list) |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 3854 | for fpath in input_api.AffectedFiles(file_filter=file_filter): |
| 3855 | for line_num, line in fpath.ChangedContents(): |
| 3856 | for (deprecated_value, value) in _DEPRECATED_CSS: |
dbeam | 070cfe6 | 2014-10-22 06:44:02 | [diff] [blame] | 3857 | if deprecated_value in line: |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 3858 | results.append(output_api.PresubmitError( |
| 3859 | "%s:%d: Use of deprecated CSS %s, use %s instead" % |
| 3860 | (fpath.LocalPath(), line_num, deprecated_value, value))) |
| 3861 | return results |
| 3862 | |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 3863 | |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 3864 | def _CheckForRelativeIncludes(input_api, output_api): |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 3865 | bad_files = {} |
| 3866 | for f in input_api.AffectedFiles(include_deletes=False): |
| 3867 | if (f.LocalPath().startswith('third_party') and |
Kent Tamura | 32dbbcb | 2018-11-30 12:28:49 | [diff] [blame] | 3868 | not f.LocalPath().startswith('third_party/blink') and |
| 3869 | not f.LocalPath().startswith('third_party\\blink')): |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 3870 | continue |
| 3871 | |
Daniel Bratell | 65b03326 | 2019-04-23 08:17:06 | [diff] [blame] | 3872 | if not _IsCPlusPlusFile(input_api, f.LocalPath()): |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 3873 | continue |
| 3874 | |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 3875 | relative_includes = [line for _, line in f.ChangedContents() |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 3876 | if "#include" in line and "../" in line] |
| 3877 | if not relative_includes: |
| 3878 | continue |
| 3879 | bad_files[f.LocalPath()] = relative_includes |
| 3880 | |
| 3881 | if not bad_files: |
| 3882 | return [] |
| 3883 | |
| 3884 | error_descriptions = [] |
| 3885 | for file_path, bad_lines in bad_files.iteritems(): |
| 3886 | error_description = file_path |
| 3887 | for line in bad_lines: |
| 3888 | error_description += '\n ' + line |
| 3889 | error_descriptions.append(error_description) |
| 3890 | |
| 3891 | results = [] |
| 3892 | results.append(output_api.PresubmitError( |
| 3893 | 'You added one or more relative #include paths (including "../").\n' |
| 3894 | 'These shouldn\'t be used because they can be used to include headers\n' |
| 3895 | 'from code that\'s not correctly specified as a dependency in the\n' |
| 3896 | 'relevant BUILD.gn file(s).', |
| 3897 | error_descriptions)) |
| 3898 | |
| 3899 | return results |
| 3900 | |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3901 | |
Daniel Bratell | 65b03326 | 2019-04-23 08:17:06 | [diff] [blame] | 3902 | def _CheckForCcIncludes(input_api, output_api): |
| 3903 | """Check that nobody tries to include a cc file. It's a relatively |
| 3904 | common error which results in duplicate symbols in object |
| 3905 | files. This may not always break the build until someone later gets |
| 3906 | very confusing linking errors.""" |
| 3907 | results = [] |
| 3908 | for f in input_api.AffectedFiles(include_deletes=False): |
| 3909 | # We let third_party code do whatever it wants |
| 3910 | if (f.LocalPath().startswith('third_party') and |
| 3911 | not f.LocalPath().startswith('third_party/blink') and |
| 3912 | not f.LocalPath().startswith('third_party\\blink')): |
| 3913 | continue |
| 3914 | |
| 3915 | if not _IsCPlusPlusFile(input_api, f.LocalPath()): |
| 3916 | continue |
| 3917 | |
| 3918 | for _, line in f.ChangedContents(): |
| 3919 | if line.startswith('#include "'): |
| 3920 | included_file = line.split('"')[1] |
| 3921 | if _IsCPlusPlusFile(input_api, included_file): |
| 3922 | # The most common naming for external files with C++ code, |
| 3923 | # apart from standard headers, is to call them foo.inc, but |
| 3924 | # Chromium sometimes uses foo-inc.cc so allow that as well. |
| 3925 | if not included_file.endswith(('.h', '-inc.cc')): |
| 3926 | results.append(output_api.PresubmitError( |
| 3927 | 'Only header files or .inc files should be included in other\n' |
| 3928 | 'C++ files. Compiling the contents of a cc file more than once\n' |
| 3929 | 'will cause duplicate information in the build which may later\n' |
| 3930 | 'result in strange link_errors.\n' + |
| 3931 | f.LocalPath() + ':\n ' + |
| 3932 | line)) |
| 3933 | |
| 3934 | return results |
| 3935 | |
| 3936 | |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3937 | def _CheckWatchlistDefinitionsEntrySyntax(key, value, ast): |
| 3938 | if not isinstance(key, ast.Str): |
| 3939 | return 'Key at line %d must be a string literal' % key.lineno |
| 3940 | if not isinstance(value, ast.Dict): |
| 3941 | return 'Value at line %d must be a dict' % value.lineno |
| 3942 | if len(value.keys) != 1: |
| 3943 | return 'Dict at line %d must have single entry' % value.lineno |
| 3944 | if not isinstance(value.keys[0], ast.Str) or value.keys[0].s != 'filepath': |
| 3945 | return ( |
| 3946 | 'Entry at line %d must have a string literal \'filepath\' as key' % |
| 3947 | value.lineno) |
| 3948 | return None |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3949 | |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3950 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 3951 | def _CheckWatchlistsEntrySyntax(key, value, ast, email_regex): |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3952 | if not isinstance(key, ast.Str): |
| 3953 | return 'Key at line %d must be a string literal' % key.lineno |
| 3954 | if not isinstance(value, ast.List): |
| 3955 | return 'Value at line %d must be a list' % value.lineno |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 3956 | for element in value.elts: |
| 3957 | if not isinstance(element, ast.Str): |
| 3958 | return 'Watchlist elements on line %d is not a string' % key.lineno |
| 3959 | if not email_regex.match(element.s): |
| 3960 | return ('Watchlist element on line %d doesn\'t look like a valid ' + |
| 3961 | 'email: %s') % (key.lineno, element.s) |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3962 | return None |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3963 | |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3964 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 3965 | def _CheckWATCHLISTSEntries(wd_dict, w_dict, input_api): |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3966 | mismatch_template = ( |
| 3967 | 'Mismatch between WATCHLIST_DEFINITIONS entry (%s) and WATCHLISTS ' |
| 3968 | 'entry (%s)') |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3969 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 3970 | email_regex = input_api.re.compile( |
| 3971 | r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+$") |
| 3972 | |
| 3973 | ast = input_api.ast |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3974 | i = 0 |
| 3975 | last_key = '' |
| 3976 | while True: |
| 3977 | if i >= len(wd_dict.keys): |
| 3978 | if i >= len(w_dict.keys): |
| 3979 | return None |
| 3980 | return mismatch_template % ('missing', 'line %d' % w_dict.keys[i].lineno) |
| 3981 | elif i >= len(w_dict.keys): |
| 3982 | return ( |
| 3983 | mismatch_template % ('line %d' % wd_dict.keys[i].lineno, 'missing')) |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3984 | |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3985 | wd_key = wd_dict.keys[i] |
| 3986 | w_key = w_dict.keys[i] |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3987 | |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3988 | result = _CheckWatchlistDefinitionsEntrySyntax( |
| 3989 | wd_key, wd_dict.values[i], ast) |
| 3990 | if result is not None: |
| 3991 | return 'Bad entry in WATCHLIST_DEFINITIONS dict: %s' % result |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3992 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 3993 | result = _CheckWatchlistsEntrySyntax( |
| 3994 | w_key, w_dict.values[i], ast, email_regex) |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3995 | if result is not None: |
| 3996 | return 'Bad entry in WATCHLISTS dict: %s' % result |
| 3997 | |
| 3998 | if wd_key.s != w_key.s: |
| 3999 | return mismatch_template % ( |
| 4000 | '%s at line %d' % (wd_key.s, wd_key.lineno), |
| 4001 | '%s at line %d' % (w_key.s, w_key.lineno)) |
| 4002 | |
| 4003 | if wd_key.s < last_key: |
| 4004 | return ( |
| 4005 | 'WATCHLISTS dict is not sorted lexicographically at line %d and %d' % |
| 4006 | (wd_key.lineno, w_key.lineno)) |
| 4007 | last_key = wd_key.s |
| 4008 | |
| 4009 | i = i + 1 |
| 4010 | |
| 4011 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 4012 | def _CheckWATCHLISTSSyntax(expression, input_api): |
| 4013 | ast = input_api.ast |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 4014 | if not isinstance(expression, ast.Expression): |
| 4015 | return 'WATCHLISTS file must contain a valid expression' |
| 4016 | dictionary = expression.body |
| 4017 | if not isinstance(dictionary, ast.Dict) or len(dictionary.keys) != 2: |
| 4018 | return 'WATCHLISTS file must have single dict with exactly two entries' |
| 4019 | |
| 4020 | first_key = dictionary.keys[0] |
| 4021 | first_value = dictionary.values[0] |
| 4022 | second_key = dictionary.keys[1] |
| 4023 | second_value = dictionary.values[1] |
| 4024 | |
| 4025 | if (not isinstance(first_key, ast.Str) or |
| 4026 | first_key.s != 'WATCHLIST_DEFINITIONS' or |
| 4027 | not isinstance(first_value, ast.Dict)): |
| 4028 | return ( |
| 4029 | 'The first entry of the dict in WATCHLISTS file must be ' |
| 4030 | 'WATCHLIST_DEFINITIONS dict') |
| 4031 | |
| 4032 | if (not isinstance(second_key, ast.Str) or |
| 4033 | second_key.s != 'WATCHLISTS' or |
| 4034 | not isinstance(second_value, ast.Dict)): |
| 4035 | return ( |
| 4036 | 'The second entry of the dict in WATCHLISTS file must be ' |
| 4037 | 'WATCHLISTS dict') |
| 4038 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 4039 | return _CheckWATCHLISTSEntries(first_value, second_value, input_api) |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 4040 | |
| 4041 | |
| 4042 | def _CheckWATCHLISTS(input_api, output_api): |
| 4043 | for f in input_api.AffectedFiles(include_deletes=False): |
| 4044 | if f.LocalPath() == 'WATCHLISTS': |
| 4045 | contents = input_api.ReadFile(f, 'r') |
| 4046 | |
| 4047 | try: |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 4048 | # First, make sure that it can be evaluated. |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 4049 | input_api.ast.literal_eval(contents) |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 4050 | # Get an AST tree for it and scan the tree for detailed style checking. |
| 4051 | expression = input_api.ast.parse( |
| 4052 | contents, filename='WATCHLISTS', mode='eval') |
| 4053 | except ValueError as e: |
| 4054 | return [output_api.PresubmitError( |
| 4055 | 'Cannot parse WATCHLISTS file', long_text=repr(e))] |
| 4056 | except SyntaxError as e: |
| 4057 | return [output_api.PresubmitError( |
| 4058 | 'Cannot parse WATCHLISTS file', long_text=repr(e))] |
| 4059 | except TypeError as e: |
| 4060 | return [output_api.PresubmitError( |
| 4061 | 'Cannot parse WATCHLISTS file', long_text=repr(e))] |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 4062 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 4063 | result = _CheckWATCHLISTSSyntax(expression, input_api) |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 4064 | if result is not None: |
| 4065 | return [output_api.PresubmitError(result)] |
| 4066 | break |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 4067 | |
| 4068 | return [] |
| 4069 | |
| 4070 | |
Wei-Yin Chen (陳威尹) | c0624d00 | 2018-07-30 18:22:19 | [diff] [blame] | 4071 | def _CheckNewHeaderWithoutGnChange(input_api, output_api): |
| 4072 | """Checks that newly added header files have corresponding GN changes. |
| 4073 | Note that this is only a heuristic. To be precise, run script: |
| 4074 | build/check_gn_headers.py. |
| 4075 | """ |
| 4076 | |
| 4077 | def headers(f): |
| 4078 | return input_api.FilterSourceFile( |
| 4079 | f, white_list=(r'.+%s' % _HEADER_EXTENSIONS, )) |
| 4080 | |
| 4081 | new_headers = [] |
| 4082 | for f in input_api.AffectedSourceFiles(headers): |
| 4083 | if f.Action() != 'A': |
| 4084 | continue |
| 4085 | new_headers.append(f.LocalPath()) |
| 4086 | |
| 4087 | def gn_files(f): |
| 4088 | return input_api.FilterSourceFile(f, white_list=(r'.+\.gn', )) |
| 4089 | |
| 4090 | all_gn_changed_contents = '' |
| 4091 | for f in input_api.AffectedSourceFiles(gn_files): |
| 4092 | for _, line in f.ChangedContents(): |
| 4093 | all_gn_changed_contents += line |
| 4094 | |
| 4095 | problems = [] |
| 4096 | for header in new_headers: |
| 4097 | basename = input_api.os_path.basename(header) |
| 4098 | if basename not in all_gn_changed_contents: |
| 4099 | problems.append(header) |
| 4100 | |
| 4101 | if problems: |
| 4102 | return [output_api.PresubmitPromptWarning( |
| 4103 | 'Missing GN changes for new header files', items=sorted(problems), |
| 4104 | long_text='Please double check whether newly added header files need ' |
| 4105 | 'corresponding changes in gn or gni files.\nThis checking is only a ' |
| 4106 | 'heuristic. Run build/check_gn_headers.py to be precise.\n' |
| 4107 | 'Read https://crbug.com/661774 for more info.')] |
| 4108 | return [] |
| 4109 | |
| 4110 | |
Michael Giuffrida | d3bc867 | 2018-10-25 22:48:02 | [diff] [blame] | 4111 | def _CheckCorrectProductNameInMessages(input_api, output_api): |
| 4112 | """Check that Chromium-branded strings don't include "Chrome" or vice versa. |
| 4113 | |
| 4114 | This assumes we won't intentionally reference one product from the other |
| 4115 | product. |
| 4116 | """ |
| 4117 | all_problems = [] |
| 4118 | test_cases = [{ |
| 4119 | "filename_postfix": "google_chrome_strings.grd", |
| 4120 | "correct_name": "Chrome", |
| 4121 | "incorrect_name": "Chromium", |
| 4122 | }, { |
| 4123 | "filename_postfix": "chromium_strings.grd", |
| 4124 | "correct_name": "Chromium", |
| 4125 | "incorrect_name": "Chrome", |
| 4126 | }] |
| 4127 | |
| 4128 | for test_case in test_cases: |
| 4129 | problems = [] |
| 4130 | filename_filter = lambda x: x.LocalPath().endswith( |
| 4131 | test_case["filename_postfix"]) |
| 4132 | |
| 4133 | # Check each new line. Can yield false positives in multiline comments, but |
| 4134 | # easier than trying to parse the XML because messages can have nested |
| 4135 | # children, and associating message elements with affected lines is hard. |
| 4136 | for f in input_api.AffectedSourceFiles(filename_filter): |
| 4137 | for line_num, line in f.ChangedContents(): |
| 4138 | if "<message" in line or "<!--" in line or "-->" in line: |
| 4139 | continue |
| 4140 | if test_case["incorrect_name"] in line: |
| 4141 | problems.append( |
| 4142 | "Incorrect product name in %s:%d" % (f.LocalPath(), line_num)) |
| 4143 | |
| 4144 | if problems: |
| 4145 | message = ( |
| 4146 | "Strings in %s-branded string files should reference \"%s\", not \"%s\"" |
| 4147 | % (test_case["correct_name"], test_case["correct_name"], |
| 4148 | test_case["incorrect_name"])) |
| 4149 | all_problems.append( |
| 4150 | output_api.PresubmitPromptWarning(message, items=problems)) |
| 4151 | |
| 4152 | return all_problems |
| 4153 | |
| 4154 | |
Dirk Pranke | 3c18a38 | 2019-03-15 01:07:51 | [diff] [blame] | 4155 | def _CheckBuildtoolsRevisionsAreInSync(input_api, output_api): |
| 4156 | # TODO(crbug.com/941824): We need to make sure the entries in |
| 4157 | # //buildtools/DEPS are kept in sync with the entries in //DEPS |
| 4158 | # so that users of //buildtools in other projects get the same tooling |
| 4159 | # Chromium gets. If we ever fix the referenced bug and add 'includedeps' |
| 4160 | # support to gclient, we can eliminate the duplication and delete |
| 4161 | # this presubmit check. |
| 4162 | |
| 4163 | # Update this regexp if new revisions are added to the files. |
| 4164 | rev_regexp = input_api.re.compile( |
Xiaohui Chen | 3fdc674 | 2020-02-29 02:13:26 | [diff] [blame] | 4165 | "'((clang_format|libcxx|libcxxabi|libunwind)_revision|gn_version)':") |
Dirk Pranke | 3c18a38 | 2019-03-15 01:07:51 | [diff] [blame] | 4166 | |
| 4167 | # If a user is changing one revision, they need to change the same |
| 4168 | # line in both files. This means that any given change should contain |
| 4169 | # exactly the same list of changed lines that match the regexps. The |
| 4170 | # replace(' ', '') call allows us to ignore whitespace changes to the |
| 4171 | # lines. The 'long_text' parameter to the error will contain the |
| 4172 | # list of changed lines in both files, which should make it easy enough |
| 4173 | # to spot the error without going overboard in this implementation. |
| 4174 | revs_changes = { |
| 4175 | 'DEPS': {}, |
| 4176 | 'buildtools/DEPS': {}, |
| 4177 | } |
| 4178 | long_text = '' |
| 4179 | |
| 4180 | for f in input_api.AffectedFiles( |
| 4181 | file_filter=lambda f: f.LocalPath() in ('DEPS', 'buildtools/DEPS')): |
| 4182 | for line_num, line in f.ChangedContents(): |
| 4183 | if rev_regexp.search(line): |
| 4184 | revs_changes[f.LocalPath()][line.replace(' ', '')] = line |
| 4185 | long_text += '%s:%d: %s\n' % (f.LocalPath(), line_num, line) |
| 4186 | |
| 4187 | if set(revs_changes['DEPS']) != set(revs_changes['buildtools/DEPS']): |
| 4188 | return [output_api.PresubmitError( |
| 4189 | 'Change buildtools revisions in sync in both //DEPS and ' |
| 4190 | '//buildtools/DEPS.', long_text=long_text + '\n')] |
| 4191 | else: |
| 4192 | return [] |
| 4193 | |
| 4194 | |
Daniel Bratell | 93eb6c6 | 2019-04-29 20:13:36 | [diff] [blame] | 4195 | def _CheckForTooLargeFiles(input_api, output_api): |
| 4196 | """Avoid large files, especially binary files, in the repository since |
| 4197 | git doesn't scale well for those. They will be in everyone's repo |
| 4198 | clones forever, forever making Chromium slower to clone and work |
| 4199 | with.""" |
| 4200 | |
| 4201 | # Uploading files to cloud storage is not trivial so we don't want |
| 4202 | # to set the limit too low, but the upper limit for "normal" large |
| 4203 | # files seems to be 1-2 MB, with a handful around 5-8 MB, so |
| 4204 | # anything over 20 MB is exceptional. |
| 4205 | TOO_LARGE_FILE_SIZE_LIMIT = 20 * 1024 * 1024 # 10 MB |
| 4206 | |
| 4207 | too_large_files = [] |
| 4208 | for f in input_api.AffectedFiles(): |
| 4209 | # Check both added and modified files (but not deleted files). |
| 4210 | if f.Action() in ('A', 'M'): |
Dirk Pranke | d6d45c3 | 2019-04-30 22:37:38 | [diff] [blame] | 4211 | size = input_api.os_path.getsize(f.AbsoluteLocalPath()) |
Daniel Bratell | 93eb6c6 | 2019-04-29 20:13:36 | [diff] [blame] | 4212 | if size > TOO_LARGE_FILE_SIZE_LIMIT: |
| 4213 | too_large_files.append("%s: %d bytes" % (f.LocalPath(), size)) |
| 4214 | |
| 4215 | if too_large_files: |
| 4216 | message = ( |
| 4217 | 'Do not commit large files to git since git scales badly for those.\n' + |
| 4218 | 'Instead put the large files in cloud storage and use DEPS to\n' + |
| 4219 | 'fetch them.\n' + '\n'.join(too_large_files) |
| 4220 | ) |
| 4221 | return [output_api.PresubmitError( |
| 4222 | 'Too large files found in commit', long_text=message + '\n')] |
| 4223 | else: |
| 4224 | return [] |
| 4225 | |
Max Moroz | b47503b | 2019-08-08 21:03:27 | [diff] [blame] | 4226 | |
| 4227 | def _CheckFuzzTargets(input_api, output_api): |
| 4228 | """Checks specific for fuzz target sources.""" |
| 4229 | EXPORTED_SYMBOLS = [ |
| 4230 | 'LLVMFuzzerInitialize', |
| 4231 | 'LLVMFuzzerCustomMutator', |
| 4232 | 'LLVMFuzzerCustomCrossOver', |
| 4233 | 'LLVMFuzzerMutate', |
| 4234 | ] |
| 4235 | |
| 4236 | REQUIRED_HEADER = '#include "testing/libfuzzer/libfuzzer_exports.h"' |
| 4237 | |
| 4238 | def FilterFile(affected_file): |
| 4239 | """Ignore libFuzzer source code.""" |
| 4240 | white_list = r'.*fuzz.*\.(h|hpp|hcc|cc|cpp|cxx)$' |
| 4241 | black_list = r"^third_party[\\/]libFuzzer" |
| 4242 | |
| 4243 | return input_api.FilterSourceFile( |
| 4244 | affected_file, |
| 4245 | white_list=[white_list], |
| 4246 | black_list=[black_list]) |
| 4247 | |
| 4248 | files_with_missing_header = [] |
| 4249 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 4250 | contents = input_api.ReadFile(f, 'r') |
| 4251 | if REQUIRED_HEADER in contents: |
| 4252 | continue |
| 4253 | |
| 4254 | if any(symbol in contents for symbol in EXPORTED_SYMBOLS): |
| 4255 | files_with_missing_header.append(f.LocalPath()) |
| 4256 | |
| 4257 | if not files_with_missing_header: |
| 4258 | return [] |
| 4259 | |
| 4260 | long_text = ( |
| 4261 | 'If you define any of the libFuzzer optional functions (%s), it is ' |
| 4262 | 'recommended to add \'%s\' directive. Otherwise, the fuzz target may ' |
| 4263 | 'work incorrectly on Mac (crbug.com/687076).\nNote that ' |
| 4264 | 'LLVMFuzzerInitialize should not be used, unless your fuzz target needs ' |
| 4265 | 'to access command line arguments passed to the fuzzer. Instead, prefer ' |
| 4266 | 'static initialization and shared resources as documented in ' |
| 4267 | 'https://chromium.googlesource.com/chromium/src/+/master/testing/' |
| 4268 | 'libfuzzer/efficient_fuzzing.md#simplifying-initialization_cleanup.\n' % ( |
| 4269 | ', '.join(EXPORTED_SYMBOLS), REQUIRED_HEADER) |
| 4270 | ) |
| 4271 | |
| 4272 | return [output_api.PresubmitPromptWarning( |
| 4273 | message="Missing '%s' in:" % REQUIRED_HEADER, |
| 4274 | items=files_with_missing_header, |
| 4275 | long_text=long_text)] |
| 4276 | |
| 4277 | |
Mohamed Heikal | d048240a | 2019-11-12 16:57:37 | [diff] [blame] | 4278 | def _CheckNewImagesWarning(input_api, output_api): |
| 4279 | """ |
| 4280 | Warns authors who add images into the repo to make sure their images are |
| 4281 | optimized before committing. |
| 4282 | """ |
| 4283 | images_added = False |
| 4284 | image_paths = [] |
| 4285 | errors = [] |
| 4286 | filter_lambda = lambda x: input_api.FilterSourceFile( |
| 4287 | x, |
| 4288 | black_list=(('(?i).*test', r'.*\/junit\/') |
| 4289 | + input_api.DEFAULT_BLACK_LIST), |
| 4290 | white_list=[r'.*\/(drawable|mipmap)' ] |
| 4291 | ) |
| 4292 | for f in input_api.AffectedFiles( |
| 4293 | include_deletes=False, file_filter=filter_lambda): |
| 4294 | local_path = f.LocalPath().lower() |
| 4295 | if any(local_path.endswith(extension) for extension in _IMAGE_EXTENSIONS): |
| 4296 | images_added = True |
| 4297 | image_paths.append(f) |
| 4298 | if images_added: |
| 4299 | errors.append(output_api.PresubmitPromptWarning( |
| 4300 | 'It looks like you are trying to commit some images. If these are ' |
| 4301 | 'non-test-only images, please make sure to read and apply the tips in ' |
| 4302 | 'https://chromium.googlesource.com/chromium/src/+/HEAD/docs/speed/' |
| 4303 | 'binary_size/optimization_advice.md#optimizing-images\nThis check is ' |
| 4304 | 'FYI only and will not block your CL on the CQ.', image_paths)) |
| 4305 | return errors |
| 4306 | |
| 4307 | |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 4308 | def _AndroidSpecificOnUploadChecks(input_api, output_api): |
Becky Zhou | 7c69b5099 | 2018-12-10 19:37:57 | [diff] [blame] | 4309 | """Groups upload checks that target android code.""" |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 4310 | results = [] |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 4311 | results.extend(_CheckAndroidCrLogUsage(input_api, output_api)) |
Jinsong Fan | 91ebbbd | 2019-04-16 14:57:17 | [diff] [blame] | 4312 | results.extend(_CheckAndroidDebuggableBuild(input_api, output_api)) |
agrieve | 7b6479d8 | 2015-10-07 14:24:22 | [diff] [blame] | 4313 | results.extend(_CheckAndroidNewMdpiAssetLocation(input_api, output_api)) |
dskiba | 88634f4e | 2015-08-14 23:03:29 | [diff] [blame] | 4314 | results.extend(_CheckAndroidToastUsage(input_api, output_api)) |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 4315 | results.extend(_CheckAndroidTestJUnitInheritance(input_api, output_api)) |
| 4316 | results.extend(_CheckAndroidTestJUnitFrameworkImport(input_api, output_api)) |
yolandyan | 4500147 | 2016-12-21 21:12:42 | [diff] [blame] | 4317 | results.extend(_CheckAndroidTestAnnotationUsage(input_api, output_api)) |
Nate Fischer | 535972b | 2017-09-16 01:06:18 | [diff] [blame] | 4318 | results.extend(_CheckAndroidWebkitImports(input_api, output_api)) |
Becky Zhou | 7c69b5099 | 2018-12-10 19:37:57 | [diff] [blame] | 4319 | results.extend(_CheckAndroidXmlStyle(input_api, output_api, True)) |
Mohamed Heikal | d048240a | 2019-11-12 16:57:37 | [diff] [blame] | 4320 | results.extend(_CheckNewImagesWarning(input_api, output_api)) |
Michael Thiessen | 4445764 | 2020-02-06 00:24:15 | [diff] [blame] | 4321 | results.extend(_CheckAndroidNoBannedImports(input_api, output_api)) |
Becky Zhou | 7c69b5099 | 2018-12-10 19:37:57 | [diff] [blame] | 4322 | return results |
| 4323 | |
| 4324 | def _AndroidSpecificOnCommitChecks(input_api, output_api): |
| 4325 | """Groups commit checks that target android code.""" |
| 4326 | results = [] |
| 4327 | results.extend(_CheckAndroidXmlStyle(input_api, output_api, False)) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 4328 | return results |
| 4329 | |
Chris Hall | 59f8d0c7 | 2020-05-01 07:31:19 | [diff] [blame] | 4330 | # TODO(chrishall): could we additionally match on any path owned by |
| 4331 | # ui/accessibility/OWNERS ? |
| 4332 | _ACCESSIBILITY_PATHS = ( |
| 4333 | r"^chrome[\\/]browser.*[\\/]accessibility[\\/]", |
| 4334 | r"^chrome[\\/]browser[\\/]extensions[\\/]api[\\/]automation.*[\\/]", |
| 4335 | r"^chrome[\\/]renderer[\\/]extensions[\\/]accessibility_.*", |
| 4336 | r"^chrome[\\/]tests[\\/]data[\\/]accessibility[\\/]", |
| 4337 | r"^content[\\/]browser[\\/]accessibility[\\/]", |
| 4338 | r"^content[\\/]renderer[\\/]accessibility[\\/]", |
| 4339 | r"^content[\\/]tests[\\/]data[\\/]accessibility[\\/]", |
| 4340 | r"^extensions[\\/]renderer[\\/]api[\\/]automation[\\/]", |
| 4341 | r"^ui[\\/]accessibility[\\/]", |
| 4342 | r"^ui[\\/]views[\\/]accessibility[\\/]", |
| 4343 | ) |
| 4344 | |
| 4345 | def _CheckAccessibilityRelnotesField(input_api, output_api): |
| 4346 | """Checks that commits to accessibility code contain an AX-Relnotes field in |
| 4347 | their commit message.""" |
| 4348 | def FileFilter(affected_file): |
| 4349 | paths = _ACCESSIBILITY_PATHS |
| 4350 | return input_api.FilterSourceFile(affected_file, white_list=paths) |
| 4351 | |
| 4352 | # Only consider changes affecting accessibility paths. |
| 4353 | if not any(input_api.AffectedFiles(file_filter=FileFilter)): |
| 4354 | return [] |
| 4355 | |
Akihiro Ota | 08108e54 | 2020-05-20 15:30:53 | [diff] [blame] | 4356 | # AX-Relnotes can appear in either the description or the footer. |
| 4357 | # When searching the description, require 'AX-Relnotes:' to appear at the |
| 4358 | # beginning of a line. |
| 4359 | ax_regex = input_api.re.compile('ax-relnotes[:=]') |
| 4360 | description_has_relnotes = any(ax_regex.match(line) |
| 4361 | for line in input_api.change.DescriptionText().lower().splitlines()) |
| 4362 | |
| 4363 | footer_relnotes = input_api.change.GitFootersFromDescription().get( |
| 4364 | 'AX-Relnotes', []) |
| 4365 | if description_has_relnotes or footer_relnotes: |
Chris Hall | 59f8d0c7 | 2020-05-01 07:31:19 | [diff] [blame] | 4366 | return [] |
| 4367 | |
| 4368 | # TODO(chrishall): link to Relnotes documentation in message. |
| 4369 | message = ("Missing 'AX-Relnotes:' field required for accessibility changes" |
| 4370 | "\n please add 'AX-Relnotes: [release notes].' to describe any " |
| 4371 | "user-facing changes" |
| 4372 | "\n otherwise add 'AX-Relnotes: n/a.' if this change has no " |
| 4373 | "user-facing effects" |
| 4374 | "\n if this is confusing or annoying then please contact members " |
| 4375 | "of ui/accessibility/OWNERS.") |
| 4376 | |
| 4377 | return [output_api.PresubmitNotifyResult(message)] |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 4378 | |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 4379 | def _CommonChecks(input_api, output_api): |
| 4380 | """Checks common to both upload and commit.""" |
| 4381 | results = [] |
| 4382 | results.extend(input_api.canned_checks.PanProjectChecks( |
[email protected] | 3de922f | 2013-12-20 13:27:38 | [diff] [blame] | 4383 | input_api, output_api, |
qyearsley | fa2cfcf8 | 2016-12-15 18:03:54 | [diff] [blame] | 4384 | excluded_paths=_EXCLUDED_PATHS)) |
Eric Boren | 6fd2b93 | 2018-01-25 15:05:08 | [diff] [blame] | 4385 | |
| 4386 | author = input_api.change.author_email |
| 4387 | if author and author not in _KNOWN_ROBOTS: |
| 4388 | results.extend( |
| 4389 | input_api.canned_checks.CheckAuthorizedAuthor(input_api, output_api)) |
| 4390 | |
Chris Hall | 59f8d0c7 | 2020-05-01 07:31:19 | [diff] [blame] | 4391 | results.extend(_CheckAccessibilityRelnotesField(input_api, output_api)) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 4392 | results.extend( |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 4393 | _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
Vaclav Brozek | 7dbc28c | 2018-03-27 08:35:23 | [diff] [blame] | 4394 | results.extend( |
| 4395 | _CheckNoProductionCodeUsingTestOnlyFunctionsJava(input_api, output_api)) |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 4396 | results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 4397 | results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) |
Dominic Battre | 03353105 | 2018-09-24 15:45:34 | [diff] [blame] | 4398 | results.extend(_CheckNoDISABLETypoInTests(input_api, output_api)) |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 4399 | results.extend(_CheckDCHECK_IS_ONHasBraces(input_api, output_api)) |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 4400 | results.extend(_CheckNoNewWStrings(input_api, output_api)) |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 4401 | results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 4402 | results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
Mario Sanchez Prada | 2472cab | 2019-09-18 10:58:31 | [diff] [blame] | 4403 | results.extend(_CheckNoDeprecatedMojoTypes(input_api, output_api)) |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 4404 | results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
[email protected] | e747905 | 2012-09-19 00:26:12 | [diff] [blame] | 4405 | results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 4406 | results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 4407 | results.extend(_CheckFilePermissions(input_api, output_api)) |
robertocn | 832f599 | 2017-01-04 19:01:30 | [diff] [blame] | 4408 | results.extend(_CheckTeamTags(input_api, output_api)) |
[email protected] | c8278b3 | 2012-10-30 20:35:49 | [diff] [blame] | 4409 | results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 4410 | results.extend(_CheckForVersionControlConflicts(input_api, output_api)) |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 4411 | results.extend(_CheckPatchFiles(input_api, output_api)) |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 4412 | results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) |
James Cook | 6b6597c | 2019-11-06 22:05:29 | [diff] [blame] | 4413 | results.extend(_CheckChromeOsSyncedPrefRegistration(input_api, output_api)) |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 4414 | results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) |
Kent Tamura | 5a8755d | 2017-06-29 23:37:07 | [diff] [blame] | 4415 | results.extend(_CheckBuildConfigMacrosWithoutInclude(input_api, output_api)) |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 4416 | results.extend(_CheckForInvalidOSMacros(input_api, output_api)) |
lliabraa | 35bab393 | 2014-10-01 12:16:44 | [diff] [blame] | 4417 | results.extend(_CheckForInvalidIfDefinedMacros(input_api, output_api)) |
yolandyan | daabc6d | 2016-04-18 18:29:39 | [diff] [blame] | 4418 | results.extend(_CheckFlakyTestUsage(input_api, output_api)) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 4419 | results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) |
[email protected] | 9f919cc | 2013-07-31 03:04:04 | [diff] [blame] | 4420 | results.extend( |
| 4421 | input_api.canned_checks.CheckChangeHasNoTabs( |
| 4422 | input_api, |
| 4423 | output_api, |
| 4424 | source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 4425 | results.extend(_CheckSpamLogging(input_api, output_api)) |
[email protected] | 49aa76a | 2013-12-04 06:59:16 | [diff] [blame] | 4426 | results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 4427 | results.extend(_CheckUserActionUpdate(input_api, output_api)) |
dbeam | 1ec68ac | 2016-12-15 05:22:24 | [diff] [blame] | 4428 | results.extend(_CheckNoDeprecatedCss(input_api, output_api)) |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 4429 | results.extend(_CheckParseErrors(input_api, output_api)) |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 4430 | results.extend(_CheckForIPCRules(input_api, output_api)) |
Stephen Martinis | 97a39414 | 2018-06-07 23:06:05 | [diff] [blame] | 4431 | results.extend(_CheckForLongPathnames(input_api, output_api)) |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4432 | results.extend(_CheckForIncludeGuards(input_api, output_api)) |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 4433 | results.extend(_CheckForWindowsLineEndings(input_api, output_api)) |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 4434 | results.extend(_CheckSingletonInHeaders(input_api, output_api)) |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 4435 | results.extend(_CheckPydepsNeedsUpdating(input_api, output_api)) |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 4436 | results.extend(_CheckJavaStyle(input_api, output_api)) |
Wez | 17c6696 | 2020-04-29 15:26:03 | [diff] [blame] | 4437 | results.extend(_CheckSecurityOwners(input_api, output_api)) |
Robert Sesek | 2c90533 | 2020-05-06 23:17:13 | [diff] [blame] | 4438 | results.extend(_CheckSecurityChanges(input_api, output_api)) |
Jochen Eisinger | f9fbe7b6c3 | 2019-11-18 09:37:26 | [diff] [blame] | 4439 | results.extend(_CheckSetNoParent(input_api, output_api)) |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 4440 | results.extend(_CheckUselessForwardDeclarations(input_api, output_api)) |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 4441 | results.extend(_CheckForRelativeIncludes(input_api, output_api)) |
Daniel Bratell | 65b03326 | 2019-04-23 08:17:06 | [diff] [blame] | 4442 | results.extend(_CheckForCcIncludes(input_api, output_api)) |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 4443 | results.extend(_CheckWATCHLISTS(input_api, output_api)) |
Sergiy Byelozyorov | 366b648 | 2017-11-06 18:20:43 | [diff] [blame] | 4444 | results.extend(input_api.RunTests( |
| 4445 | input_api.canned_checks.CheckVPythonSpec(input_api, output_api))) |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 4446 | results.extend(_CheckStrings(input_api, output_api)) |
Mustafa Emre Acer | 51f2f74 | 2020-03-09 19:41:12 | [diff] [blame] | 4447 | results.extend(_CheckTranslationExpectations(input_api, output_api)) |
Michael Giuffrida | d3bc867 | 2018-10-25 22:48:02 | [diff] [blame] | 4448 | results.extend(_CheckCorrectProductNameInMessages(input_api, output_api)) |
Dirk Pranke | 3c18a38 | 2019-03-15 01:07:51 | [diff] [blame] | 4449 | results.extend(_CheckBuildtoolsRevisionsAreInSync(input_api, output_api)) |
Daniel Bratell | 93eb6c6 | 2019-04-29 20:13:36 | [diff] [blame] | 4450 | results.extend(_CheckForTooLargeFiles(input_api, output_api)) |
Nate Fischer | dfd9812e | 2019-07-18 22:03:00 | [diff] [blame] | 4451 | results.extend(_CheckPythonDevilInit(input_api, output_api)) |
Ken Rockot | c31f483 | 2020-05-29 18:58:51 | [diff] [blame] | 4452 | results.extend(_CheckStableMojomChanges(input_api, output_api)) |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 4453 | |
Vaclav Brozek | cdc7defb | 2018-03-20 09:54:35 | [diff] [blame] | 4454 | for f in input_api.AffectedFiles(): |
| 4455 | path, name = input_api.os_path.split(f.LocalPath()) |
| 4456 | if name == 'PRESUBMIT.py': |
| 4457 | full_path = input_api.os_path.join(input_api.PresubmitLocalPath(), path) |
Caleb Rouleau | a6117be | 2018-05-11 20:10:00 | [diff] [blame] | 4458 | test_file = input_api.os_path.join(path, 'PRESUBMIT_test.py') |
| 4459 | if f.Action() != 'D' and input_api.os_path.exists(test_file): |
Dirk Pranke | 3855731 | 2018-04-18 00:53:07 | [diff] [blame] | 4460 | # The PRESUBMIT.py file (and the directory containing it) might |
| 4461 | # have been affected by being moved or removed, so only try to |
| 4462 | # run the tests if they still exist. |
| 4463 | results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 4464 | input_api, output_api, full_path, |
| 4465 | whitelist=[r'^PRESUBMIT_test\.py$'])) |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 4466 | return results |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 4467 | |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 4468 | |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 4469 | def _CheckPatchFiles(input_api, output_api): |
| 4470 | problems = [f.LocalPath() for f in input_api.AffectedFiles() |
| 4471 | if f.LocalPath().endswith(('.orig', '.rej'))] |
| 4472 | if problems: |
| 4473 | return [output_api.PresubmitError( |
| 4474 | "Don't commit .rej and .orig files.", problems)] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 4475 | else: |
| 4476 | return [] |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 4477 | |
| 4478 | |
Kent Tamura | 5a8755d | 2017-06-29 23:37:07 | [diff] [blame] | 4479 | def _CheckBuildConfigMacrosWithoutInclude(input_api, output_api): |
Kent Tamura | 79ef8f8 | 2017-07-18 00:00:21 | [diff] [blame] | 4480 | # Excludes OS_CHROMEOS, which is not defined in build_config.h. |
| 4481 | macro_re = input_api.re.compile(r'^\s*#(el)?if.*\bdefined\(((OS_(?!CHROMEOS)|' |
| 4482 | 'COMPILER_|ARCH_CPU_|WCHAR_T_IS_)[^)]*)') |
Kent Tamura | 5a8755d | 2017-06-29 23:37:07 | [diff] [blame] | 4483 | include_re = input_api.re.compile( |
| 4484 | r'^#include\s+"build/build_config.h"', input_api.re.MULTILINE) |
| 4485 | extension_re = input_api.re.compile(r'\.[a-z]+$') |
| 4486 | errors = [] |
| 4487 | for f in input_api.AffectedFiles(): |
| 4488 | if not f.LocalPath().endswith(('.h', '.c', '.cc', '.cpp', '.m', '.mm')): |
| 4489 | continue |
| 4490 | found_line_number = None |
| 4491 | found_macro = None |
| 4492 | for line_num, line in f.ChangedContents(): |
| 4493 | match = macro_re.search(line) |
| 4494 | if match: |
| 4495 | found_line_number = line_num |
| 4496 | found_macro = match.group(2) |
| 4497 | break |
| 4498 | if not found_line_number: |
| 4499 | continue |
| 4500 | |
| 4501 | found_include = False |
| 4502 | for line in f.NewContents(): |
| 4503 | if include_re.search(line): |
| 4504 | found_include = True |
| 4505 | break |
| 4506 | if found_include: |
| 4507 | continue |
| 4508 | |
| 4509 | if not f.LocalPath().endswith('.h'): |
| 4510 | primary_header_path = extension_re.sub('.h', f.AbsoluteLocalPath()) |
| 4511 | try: |
| 4512 | content = input_api.ReadFile(primary_header_path, 'r') |
| 4513 | if include_re.search(content): |
| 4514 | continue |
| 4515 | except IOError: |
| 4516 | pass |
| 4517 | errors.append('%s:%d %s macro is used without including build/' |
| 4518 | 'build_config.h.' |
| 4519 | % (f.LocalPath(), found_line_number, found_macro)) |
| 4520 | if errors: |
| 4521 | return [output_api.PresubmitPromptWarning('\n'.join(errors))] |
| 4522 | return [] |
| 4523 | |
| 4524 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 4525 | def _DidYouMeanOSMacro(bad_macro): |
| 4526 | try: |
| 4527 | return {'A': 'OS_ANDROID', |
| 4528 | 'B': 'OS_BSD', |
| 4529 | 'C': 'OS_CHROMEOS', |
| 4530 | 'F': 'OS_FREEBSD', |
| 4531 | 'L': 'OS_LINUX', |
| 4532 | 'M': 'OS_MACOSX', |
| 4533 | 'N': 'OS_NACL', |
| 4534 | 'O': 'OS_OPENBSD', |
| 4535 | 'P': 'OS_POSIX', |
| 4536 | 'S': 'OS_SOLARIS', |
| 4537 | 'W': 'OS_WIN'}[bad_macro[3].upper()] |
| 4538 | except KeyError: |
| 4539 | return '' |
| 4540 | |
| 4541 | |
| 4542 | def _CheckForInvalidOSMacrosInFile(input_api, f): |
| 4543 | """Check for sensible looking, totally invalid OS macros.""" |
| 4544 | preprocessor_statement = input_api.re.compile(r'^\s*#') |
| 4545 | os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)') |
| 4546 | results = [] |
| 4547 | for lnum, line in f.ChangedContents(): |
| 4548 | if preprocessor_statement.search(line): |
| 4549 | for match in os_macro.finditer(line): |
| 4550 | if not match.group(1) in _VALID_OS_MACROS: |
| 4551 | good = _DidYouMeanOSMacro(match.group(1)) |
| 4552 | did_you_mean = ' (did you mean %s?)' % good if good else '' |
| 4553 | results.append(' %s:%d %s%s' % (f.LocalPath(), |
| 4554 | lnum, |
| 4555 | match.group(1), |
| 4556 | did_you_mean)) |
| 4557 | return results |
| 4558 | |
| 4559 | |
| 4560 | def _CheckForInvalidOSMacros(input_api, output_api): |
| 4561 | """Check all affected files for invalid OS macros.""" |
| 4562 | bad_macros = [] |
tzik | 3f29599 | 2018-12-04 20:32:23 | [diff] [blame] | 4563 | for f in input_api.AffectedSourceFiles(None): |
ellyjones | 4765434 | 2016-05-06 15:50:47 | [diff] [blame] | 4564 | if not f.LocalPath().endswith(('.py', '.js', '.html', '.css', '.md')): |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 4565 | bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f)) |
| 4566 | |
| 4567 | if not bad_macros: |
| 4568 | return [] |
| 4569 | |
| 4570 | return [output_api.PresubmitError( |
| 4571 | 'Possibly invalid OS macro[s] found. Please fix your code\n' |
| 4572 | 'or add your macro to src/PRESUBMIT.py.', bad_macros)] |
| 4573 | |
lliabraa | 35bab393 | 2014-10-01 12:16:44 | [diff] [blame] | 4574 | |
| 4575 | def _CheckForInvalidIfDefinedMacrosInFile(input_api, f): |
| 4576 | """Check all affected files for invalid "if defined" macros.""" |
| 4577 | ALWAYS_DEFINED_MACROS = ( |
| 4578 | "TARGET_CPU_PPC", |
| 4579 | "TARGET_CPU_PPC64", |
| 4580 | "TARGET_CPU_68K", |
| 4581 | "TARGET_CPU_X86", |
| 4582 | "TARGET_CPU_ARM", |
| 4583 | "TARGET_CPU_MIPS", |
| 4584 | "TARGET_CPU_SPARC", |
| 4585 | "TARGET_CPU_ALPHA", |
| 4586 | "TARGET_IPHONE_SIMULATOR", |
| 4587 | "TARGET_OS_EMBEDDED", |
| 4588 | "TARGET_OS_IPHONE", |
| 4589 | "TARGET_OS_MAC", |
| 4590 | "TARGET_OS_UNIX", |
| 4591 | "TARGET_OS_WIN32", |
| 4592 | ) |
| 4593 | ifdef_macro = input_api.re.compile(r'^\s*#.*(?:ifdef\s|defined\()([^\s\)]+)') |
| 4594 | results = [] |
| 4595 | for lnum, line in f.ChangedContents(): |
| 4596 | for match in ifdef_macro.finditer(line): |
| 4597 | if match.group(1) in ALWAYS_DEFINED_MACROS: |
| 4598 | always_defined = ' %s is always defined. ' % match.group(1) |
| 4599 | did_you_mean = 'Did you mean \'#if %s\'?' % match.group(1) |
| 4600 | results.append(' %s:%d %s\n\t%s' % (f.LocalPath(), |
| 4601 | lnum, |
| 4602 | always_defined, |
| 4603 | did_you_mean)) |
| 4604 | return results |
| 4605 | |
| 4606 | |
| 4607 | def _CheckForInvalidIfDefinedMacros(input_api, output_api): |
| 4608 | """Check all affected files for invalid "if defined" macros.""" |
| 4609 | bad_macros = [] |
Mirko Bonadei | 28112c0 | 2019-05-17 20:25:05 | [diff] [blame] | 4610 | skipped_paths = ['third_party/sqlite/', 'third_party/abseil-cpp/'] |
lliabraa | 35bab393 | 2014-10-01 12:16:44 | [diff] [blame] | 4611 | for f in input_api.AffectedFiles(): |
Mirko Bonadei | 28112c0 | 2019-05-17 20:25:05 | [diff] [blame] | 4612 | if any([f.LocalPath().startswith(path) for path in skipped_paths]): |
sdefresne | 4e1eccb3 | 2017-05-24 08:45:21 | [diff] [blame] | 4613 | continue |
lliabraa | 35bab393 | 2014-10-01 12:16:44 | [diff] [blame] | 4614 | if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): |
| 4615 | bad_macros.extend(_CheckForInvalidIfDefinedMacrosInFile(input_api, f)) |
| 4616 | |
| 4617 | if not bad_macros: |
| 4618 | return [] |
| 4619 | |
| 4620 | return [output_api.PresubmitError( |
| 4621 | 'Found ifdef check on always-defined macro[s]. Please fix your code\n' |
| 4622 | 'or check the list of ALWAYS_DEFINED_MACROS in src/PRESUBMIT.py.', |
| 4623 | bad_macros)] |
| 4624 | |
| 4625 | |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 4626 | def _CheckForIPCRules(input_api, output_api): |
| 4627 | """Check for same IPC rules described in |
| 4628 | http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc |
| 4629 | """ |
| 4630 | base_pattern = r'IPC_ENUM_TRAITS\(' |
| 4631 | inclusion_pattern = input_api.re.compile(r'(%s)' % base_pattern) |
| 4632 | comment_pattern = input_api.re.compile(r'//.*(%s)' % base_pattern) |
| 4633 | |
| 4634 | problems = [] |
| 4635 | for f in input_api.AffectedSourceFiles(None): |
| 4636 | local_path = f.LocalPath() |
| 4637 | if not local_path.endswith('.h'): |
| 4638 | continue |
| 4639 | for line_number, line in f.ChangedContents(): |
| 4640 | if inclusion_pattern.search(line) and not comment_pattern.search(line): |
| 4641 | problems.append( |
| 4642 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
| 4643 | |
| 4644 | if problems: |
| 4645 | return [output_api.PresubmitPromptWarning( |
| 4646 | _IPC_ENUM_TRAITS_DEPRECATED, problems)] |
| 4647 | else: |
| 4648 | return [] |
| 4649 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 4650 | |
Stephen Martinis | 97a39414 | 2018-06-07 23:06:05 | [diff] [blame] | 4651 | def _CheckForLongPathnames(input_api, output_api): |
| 4652 | """Check to make sure no files being submitted have long paths. |
| 4653 | This causes issues on Windows. |
| 4654 | """ |
| 4655 | problems = [] |
Stephen Martinis | c4b246b | 2019-10-31 23:04:19 | [diff] [blame] | 4656 | for f in input_api.AffectedTestableFiles(): |
Stephen Martinis | 97a39414 | 2018-06-07 23:06:05 | [diff] [blame] | 4657 | local_path = f.LocalPath() |
| 4658 | # Windows has a path limit of 260 characters. Limit path length to 200 so |
| 4659 | # that we have some extra for the prefix on dev machines and the bots. |
| 4660 | if len(local_path) > 200: |
| 4661 | problems.append(local_path) |
| 4662 | |
| 4663 | if problems: |
| 4664 | return [output_api.PresubmitError(_LONG_PATH_ERROR, problems)] |
| 4665 | else: |
| 4666 | return [] |
| 4667 | |
| 4668 | |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4669 | def _CheckForIncludeGuards(input_api, output_api): |
| 4670 | """Check that header files have proper guards against multiple inclusion. |
| 4671 | If a file should not have such guards (and it probably should) then it |
| 4672 | should include the string "no-include-guard-because-multiply-included". |
| 4673 | """ |
Daniel Bratell | 6a75baef6 | 2018-06-04 10:04:45 | [diff] [blame] | 4674 | def is_chromium_header_file(f): |
| 4675 | # We only check header files under the control of the Chromium |
| 4676 | # project. That is, those outside third_party apart from |
| 4677 | # third_party/blink. |
Kinuko Yasuda | 0cdb3da | 2019-07-31 21:50:32 | [diff] [blame] | 4678 | # We also exclude *_message_generator.h headers as they use |
| 4679 | # include guards in a special, non-typical way. |
Daniel Bratell | 6a75baef6 | 2018-06-04 10:04:45 | [diff] [blame] | 4680 | file_with_path = input_api.os_path.normpath(f.LocalPath()) |
| 4681 | return (file_with_path.endswith('.h') and |
Kinuko Yasuda | 0cdb3da | 2019-07-31 21:50:32 | [diff] [blame] | 4682 | not file_with_path.endswith('_message_generator.h') and |
Daniel Bratell | 6a75baef6 | 2018-06-04 10:04:45 | [diff] [blame] | 4683 | (not file_with_path.startswith('third_party') or |
| 4684 | file_with_path.startswith( |
| 4685 | input_api.os_path.join('third_party', 'blink')))) |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4686 | |
| 4687 | def replace_special_with_underscore(string): |
Olivier Robin | bba13749 | 2018-07-30 11:31:34 | [diff] [blame] | 4688 | return input_api.re.sub(r'[+\\/.-]', '_', string) |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4689 | |
| 4690 | errors = [] |
| 4691 | |
Daniel Bratell | 6a75baef6 | 2018-06-04 10:04:45 | [diff] [blame] | 4692 | for f in input_api.AffectedSourceFiles(is_chromium_header_file): |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4693 | guard_name = None |
| 4694 | guard_line_number = None |
| 4695 | seen_guard_end = False |
| 4696 | |
| 4697 | file_with_path = input_api.os_path.normpath(f.LocalPath()) |
| 4698 | base_file_name = input_api.os_path.splitext( |
| 4699 | input_api.os_path.basename(file_with_path))[0] |
| 4700 | upper_base_file_name = base_file_name.upper() |
| 4701 | |
| 4702 | expected_guard = replace_special_with_underscore( |
| 4703 | file_with_path.upper() + '_') |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4704 | |
| 4705 | # For "path/elem/file_name.h" we should really only accept |
Daniel Bratell | 39b5b06 | 2018-05-16 18:09:57 | [diff] [blame] | 4706 | # PATH_ELEM_FILE_NAME_H_ per coding style. Unfortunately there |
| 4707 | # are too many (1000+) files with slight deviations from the |
| 4708 | # coding style. The most important part is that the include guard |
| 4709 | # is there, and that it's unique, not the name so this check is |
| 4710 | # forgiving for existing files. |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4711 | # |
| 4712 | # As code becomes more uniform, this could be made stricter. |
| 4713 | |
| 4714 | guard_name_pattern_list = [ |
| 4715 | # Anything with the right suffix (maybe with an extra _). |
| 4716 | r'\w+_H__?', |
| 4717 | |
Daniel Bratell | 39b5b06 | 2018-05-16 18:09:57 | [diff] [blame] | 4718 | # To cover include guards with old Blink style. |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4719 | r'\w+_h', |
| 4720 | |
| 4721 | # Anything including the uppercase name of the file. |
| 4722 | r'\w*' + input_api.re.escape(replace_special_with_underscore( |
| 4723 | upper_base_file_name)) + r'\w*', |
| 4724 | ] |
| 4725 | guard_name_pattern = '|'.join(guard_name_pattern_list) |
| 4726 | guard_pattern = input_api.re.compile( |
| 4727 | r'#ifndef\s+(' + guard_name_pattern + ')') |
| 4728 | |
| 4729 | for line_number, line in enumerate(f.NewContents()): |
| 4730 | if 'no-include-guard-because-multiply-included' in line: |
| 4731 | guard_name = 'DUMMY' # To not trigger check outside the loop. |
| 4732 | break |
| 4733 | |
| 4734 | if guard_name is None: |
| 4735 | match = guard_pattern.match(line) |
| 4736 | if match: |
| 4737 | guard_name = match.group(1) |
| 4738 | guard_line_number = line_number |
| 4739 | |
Daniel Bratell | 39b5b06 | 2018-05-16 18:09:57 | [diff] [blame] | 4740 | # We allow existing files to use include guards whose names |
Daniel Bratell | 6a75baef6 | 2018-06-04 10:04:45 | [diff] [blame] | 4741 | # don't match the chromium style guide, but new files should |
| 4742 | # get it right. |
| 4743 | if not f.OldContents(): |
Daniel Bratell | 39b5b06 | 2018-05-16 18:09:57 | [diff] [blame] | 4744 | if guard_name != expected_guard: |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4745 | errors.append(output_api.PresubmitPromptWarning( |
| 4746 | 'Header using the wrong include guard name %s' % guard_name, |
| 4747 | ['%s:%d' % (f.LocalPath(), line_number + 1)], |
Istiaque Ahmed | 9ad6cd2 | 2019-10-04 00:26:57 | [diff] [blame] | 4748 | 'Expected: %r\nFound: %r' % (expected_guard, guard_name))) |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 4749 | else: |
| 4750 | # The line after #ifndef should have a #define of the same name. |
| 4751 | if line_number == guard_line_number + 1: |
| 4752 | expected_line = '#define %s' % guard_name |
| 4753 | if line != expected_line: |
| 4754 | errors.append(output_api.PresubmitPromptWarning( |
| 4755 | 'Missing "%s" for include guard' % expected_line, |
| 4756 | ['%s:%d' % (f.LocalPath(), line_number + 1)], |
| 4757 | 'Expected: %r\nGot: %r' % (expected_line, line))) |
| 4758 | |
| 4759 | if not seen_guard_end and line == '#endif // %s' % guard_name: |
| 4760 | seen_guard_end = True |
| 4761 | elif seen_guard_end: |
| 4762 | if line.strip() != '': |
| 4763 | errors.append(output_api.PresubmitPromptWarning( |
| 4764 | 'Include guard %s not covering the whole file' % ( |
| 4765 | guard_name), [f.LocalPath()])) |
| 4766 | break # Nothing else to check and enough to warn once. |
| 4767 | |
| 4768 | if guard_name is None: |
| 4769 | errors.append(output_api.PresubmitPromptWarning( |
| 4770 | 'Missing include guard %s' % expected_guard, |
| 4771 | [f.LocalPath()], |
| 4772 | 'Missing include guard in %s\n' |
| 4773 | 'Recommended name: %s\n' |
| 4774 | 'This check can be disabled by having the string\n' |
| 4775 | 'no-include-guard-because-multiply-included in the header.' % |
| 4776 | (f.LocalPath(), expected_guard))) |
| 4777 | |
| 4778 | return errors |
| 4779 | |
| 4780 | |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 4781 | def _CheckForWindowsLineEndings(input_api, output_api): |
| 4782 | """Check source code and known ascii text files for Windows style line |
| 4783 | endings. |
| 4784 | """ |
earthdok | 1b5e0ee | 2015-03-10 15:19:10 | [diff] [blame] | 4785 | known_text_files = r'.*\.(txt|html|htm|mhtml|py|gyp|gypi|gn|isolate)$' |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 4786 | |
| 4787 | file_inclusion_pattern = ( |
| 4788 | known_text_files, |
| 4789 | r'.+%s' % _IMPLEMENTATION_EXTENSIONS |
| 4790 | ) |
| 4791 | |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 4792 | problems = [] |
Andrew Grieve | 933d12e | 2017-10-30 20:22:53 | [diff] [blame] | 4793 | source_file_filter = lambda f: input_api.FilterSourceFile( |
| 4794 | f, white_list=file_inclusion_pattern, black_list=None) |
| 4795 | for f in input_api.AffectedSourceFiles(source_file_filter): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 4796 | include_file = False |
| 4797 | for _, line in f.ChangedContents(): |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 4798 | if line.endswith('\r\n'): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 4799 | include_file = True |
| 4800 | if include_file: |
| 4801 | problems.append(f.LocalPath()) |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 4802 | |
| 4803 | if problems: |
| 4804 | return [output_api.PresubmitPromptWarning('Are you sure that you want ' |
| 4805 | 'these files to contain Windows style line endings?\n' + |
| 4806 | '\n'.join(problems))] |
| 4807 | |
| 4808 | return [] |
| 4809 | |
| 4810 | |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 4811 | def _CheckSyslogUseWarning(input_api, output_api, source_file_filter=None): |
pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 4812 | """Checks that all source files use SYSLOG properly.""" |
| 4813 | syslog_files = [] |
| 4814 | for f in input_api.AffectedSourceFiles(source_file_filter): |
pastarmovj | 032ba5bc | 2017-01-12 10:41:56 | [diff] [blame] | 4815 | for line_number, line in f.ChangedContents(): |
| 4816 | if 'SYSLOG' in line: |
| 4817 | syslog_files.append(f.LocalPath() + ':' + str(line_number)) |
| 4818 | |
pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 4819 | if syslog_files: |
| 4820 | return [output_api.PresubmitPromptWarning( |
| 4821 | 'Please make sure there are no privacy sensitive bits of data in SYSLOG' |
| 4822 | ' calls.\nFiles to check:\n', items=syslog_files)] |
| 4823 | return [] |
| 4824 | |
| 4825 | |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 4826 | def CheckChangeOnUpload(input_api, output_api): |
| 4827 | results = [] |
| 4828 | results.extend(_CommonChecks(input_api, output_api)) |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 4829 | results.extend(_CheckValidHostsInDEPS(input_api, output_api)) |
scottmg | 39b2995 | 2014-12-08 18:31:28 | [diff] [blame] | 4830 | results.extend( |
jam | 93a6ee79 | 2017-02-08 23:59:22 | [diff] [blame] | 4831 | input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 4832 | results.extend(_CheckUmaHistogramChanges(input_api, output_api)) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 4833 | results.extend(_AndroidSpecificOnUploadChecks(input_api, output_api)) |
pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 4834 | results.extend(_CheckSyslogUseWarning(input_api, output_api)) |
estade | e17314a0 | 2017-01-12 16:22:16 | [diff] [blame] | 4835 | results.extend(_CheckGoogleSupportAnswerUrl(input_api, output_api)) |
Vaclav Brozek | ea41ab2 | 2018-04-06 13:21:53 | [diff] [blame] | 4836 | results.extend(_CheckUniquePtr(input_api, output_api)) |
Wei-Yin Chen (陳威尹) | c0624d00 | 2018-07-30 18:22:19 | [diff] [blame] | 4837 | results.extend(_CheckNewHeaderWithoutGnChange(input_api, output_api)) |
Max Moroz | b47503b | 2019-08-08 21:03:27 | [diff] [blame] | 4838 | results.extend(_CheckFuzzTargets(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 4839 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 4840 | |
| 4841 | |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 4842 | def GetTryServerMasterForBot(bot): |
| 4843 | """Returns the Try Server master for the given bot. |
| 4844 | |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 4845 | It tries to guess the master from the bot name, but may still fail |
| 4846 | and return None. There is no longer a default master. |
| 4847 | """ |
| 4848 | # Potentially ambiguous bot names are listed explicitly. |
| 4849 | master_map = { |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 4850 | 'chromium_presubmit': 'master.tryserver.chromium.linux', |
| 4851 | 'tools_build_presubmit': 'master.tryserver.chromium.linux', |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 4852 | } |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 4853 | master = master_map.get(bot) |
| 4854 | if not master: |
wnwen | 4fbaab8 | 2016-05-25 12:54:36 | [diff] [blame] | 4855 | if 'android' in bot: |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 4856 | master = 'master.tryserver.chromium.android' |
wnwen | 4fbaab8 | 2016-05-25 12:54:36 | [diff] [blame] | 4857 | elif 'linux' in bot or 'presubmit' in bot: |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 4858 | master = 'master.tryserver.chromium.linux' |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 4859 | elif 'win' in bot: |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 4860 | master = 'master.tryserver.chromium.win' |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 4861 | elif 'mac' in bot or 'ios' in bot: |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 4862 | master = 'master.tryserver.chromium.mac' |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 4863 | return master |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 4864 | |
| 4865 | |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 4866 | def CheckChangeOnCommit(input_api, output_api): |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 4867 | results = [] |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 4868 | results.extend(_CommonChecks(input_api, output_api)) |
Becky Zhou | 7c69b5099 | 2018-12-10 19:37:57 | [diff] [blame] | 4869 | results.extend(_AndroidSpecificOnCommitChecks(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 4870 | # Make sure the tree is 'open'. |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 4871 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
[email protected] | 7f23815 | 2009-08-12 19:00:34 | [diff] [blame] | 4872 | input_api, |
| 4873 | output_api, |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 4874 | json_url='http://chromium-status.appspot.com/current?format=json')) |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 4875 | |
jam | 93a6ee79 | 2017-02-08 23:59:22 | [diff] [blame] | 4876 | results.extend( |
| 4877 | input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 4878 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 4879 | input_api, output_api)) |
Dan Beam | 39f28cb | 2019-10-04 01:01:38 | [diff] [blame] | 4880 | results.extend(input_api.canned_checks.CheckChangeHasNoUnwantedTags( |
| 4881 | input_api, output_api)) |
[email protected] | c4b4756 | 2011-12-05 23:39:41 | [diff] [blame] | 4882 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 4883 | input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 4884 | return results |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 4885 | |
| 4886 | |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 4887 | def _CheckStrings(input_api, output_api): |
| 4888 | """Check string ICU syntax validity and if translation screenshots exist.""" |
Edward Lesmes | f7c5c6d | 2020-05-14 23:30:02 | [diff] [blame] | 4889 | # Skip translation screenshots check if a SkipTranslationScreenshotsCheck |
| 4890 | # footer is set to true. |
| 4891 | git_footers = input_api.change.GitFootersFromDescription() |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 4892 | skip_screenshot_check_footer = [ |
Edward Lesmes | f7c5c6d | 2020-05-14 23:30:02 | [diff] [blame] | 4893 | footer.lower() |
| 4894 | for footer in git_footers.get(u'Skip-Translation-Screenshots-Check', [])] |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 4895 | run_screenshot_check = u'true' not in skip_screenshot_check_footer |
Edward Lesmes | f7c5c6d | 2020-05-14 23:30:02 | [diff] [blame] | 4896 | |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 4897 | import os |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 4898 | import re |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 4899 | import sys |
| 4900 | from io import StringIO |
| 4901 | |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 4902 | new_or_added_paths = set(f.LocalPath() |
| 4903 | for f in input_api.AffectedFiles() |
| 4904 | if (f.Action() == 'A' or f.Action() == 'M')) |
| 4905 | removed_paths = set(f.LocalPath() |
| 4906 | for f in input_api.AffectedFiles(include_deletes=True) |
| 4907 | if f.Action() == 'D') |
| 4908 | |
| 4909 | affected_grds = [f for f in input_api.AffectedFiles() |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 4910 | if (f.LocalPath().endswith(('.grd', '.grdp')))] |
meacer | 8c0d383 | 2019-12-26 21:46:16 | [diff] [blame] | 4911 | if not affected_grds: |
| 4912 | return [] |
| 4913 | |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 4914 | affected_png_paths = [f.AbsoluteLocalPath() |
| 4915 | for f in input_api.AffectedFiles() |
| 4916 | if (f.LocalPath().endswith('.png'))] |
| 4917 | |
| 4918 | # Check for screenshots. Developers can upload screenshots using |
| 4919 | # tools/translation/upload_screenshots.py which finds and uploads |
| 4920 | # images associated with .grd files (e.g. test_grd/IDS_STRING.png for the |
| 4921 | # message named IDS_STRING in test.grd) and produces a .sha1 file (e.g. |
| 4922 | # test_grd/IDS_STRING.png.sha1) for each png when the upload is successful. |
| 4923 | # |
| 4924 | # The logic here is as follows: |
| 4925 | # |
| 4926 | # - If the CL has a .png file under the screenshots directory for a grd |
| 4927 | # file, warn the developer. Actual images should never be checked into the |
| 4928 | # Chrome repo. |
| 4929 | # |
| 4930 | # - If the CL contains modified or new messages in grd files and doesn't |
| 4931 | # contain the corresponding .sha1 files, warn the developer to add images |
| 4932 | # and upload them via tools/translation/upload_screenshots.py. |
| 4933 | # |
| 4934 | # - If the CL contains modified or new messages in grd files and the |
| 4935 | # corresponding .sha1 files, everything looks good. |
| 4936 | # |
| 4937 | # - If the CL contains removed messages in grd files but the corresponding |
| 4938 | # .sha1 files aren't removed, warn the developer to remove them. |
| 4939 | unnecessary_screenshots = [] |
| 4940 | missing_sha1 = [] |
| 4941 | unnecessary_sha1_files = [] |
| 4942 | |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 4943 | # This checks verifies that the ICU syntax of messages this CL touched is |
| 4944 | # valid, and reports any found syntax errors. |
| 4945 | # Without this presubmit check, ICU syntax errors in Chromium strings can land |
| 4946 | # without developers being aware of them. Later on, such ICU syntax errors |
| 4947 | # break message extraction for translation, hence would block Chromium |
| 4948 | # translations until they are fixed. |
| 4949 | icu_syntax_errors = [] |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 4950 | |
| 4951 | def _CheckScreenshotAdded(screenshots_dir, message_id): |
| 4952 | sha1_path = input_api.os_path.join( |
| 4953 | screenshots_dir, message_id + '.png.sha1') |
| 4954 | if sha1_path not in new_or_added_paths: |
| 4955 | missing_sha1.append(sha1_path) |
| 4956 | |
| 4957 | |
| 4958 | def _CheckScreenshotRemoved(screenshots_dir, message_id): |
| 4959 | sha1_path = input_api.os_path.join( |
| 4960 | screenshots_dir, message_id + '.png.sha1') |
meacer | e7be753 | 2019-10-02 17:41:03 | [diff] [blame] | 4961 | if input_api.os_path.exists(sha1_path) and sha1_path not in removed_paths: |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 4962 | unnecessary_sha1_files.append(sha1_path) |
| 4963 | |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 4964 | |
| 4965 | def _ValidateIcuSyntax(text, level, signatures): |
| 4966 | """Validates ICU syntax of a text string. |
| 4967 | |
| 4968 | Check if text looks similar to ICU and checks for ICU syntax correctness |
| 4969 | in this case. Reports various issues with ICU syntax and values of |
| 4970 | variants. Supports checking of nested messages. Accumulate information of |
| 4971 | each ICU messages found in the text for further checking. |
| 4972 | |
| 4973 | Args: |
| 4974 | text: a string to check. |
| 4975 | level: a number of current nesting level. |
| 4976 | signatures: an accumulator, a list of tuple of (level, variable, |
| 4977 | kind, variants). |
| 4978 | |
| 4979 | Returns: |
| 4980 | None if a string is not ICU or no issue detected. |
| 4981 | A tuple of (message, start index, end index) if an issue detected. |
| 4982 | """ |
| 4983 | valid_types = { |
| 4984 | 'plural': (frozenset( |
| 4985 | ['=0', '=1', 'zero', 'one', 'two', 'few', 'many', 'other']), |
| 4986 | frozenset(['=1', 'other'])), |
| 4987 | 'selectordinal': (frozenset( |
| 4988 | ['=0', '=1', 'zero', 'one', 'two', 'few', 'many', 'other']), |
| 4989 | frozenset(['one', 'other'])), |
| 4990 | 'select': (frozenset(), frozenset(['other'])), |
| 4991 | } |
| 4992 | |
| 4993 | # Check if the message looks like an attempt to use ICU |
| 4994 | # plural. If yes - check if its syntax strictly matches ICU format. |
| 4995 | like = re.match(r'^[^{]*\{[^{]*\b(plural|selectordinal|select)\b', text) |
| 4996 | if not like: |
| 4997 | signatures.append((level, None, None, None)) |
| 4998 | return |
| 4999 | |
| 5000 | # Check for valid prefix and suffix |
| 5001 | m = re.match( |
| 5002 | r'^([^{]*\{)([a-zA-Z0-9_]+),\s*' |
| 5003 | r'(plural|selectordinal|select),\s*' |
| 5004 | r'(?:offset:\d+)?\s*(.*)', text, re.DOTALL) |
| 5005 | if not m: |
| 5006 | return (('This message looks like an ICU plural, ' |
| 5007 | 'but does not follow ICU syntax.'), like.start(), like.end()) |
| 5008 | starting, variable, kind, variant_pairs = m.groups() |
| 5009 | variants, depth, last_pos = _ParseIcuVariants(variant_pairs, m.start(4)) |
| 5010 | if depth: |
| 5011 | return ('Invalid ICU format. Unbalanced opening bracket', last_pos, |
| 5012 | len(text)) |
| 5013 | first = text[0] |
| 5014 | ending = text[last_pos:] |
| 5015 | if not starting: |
| 5016 | return ('Invalid ICU format. No initial opening bracket', last_pos - 1, |
| 5017 | last_pos) |
| 5018 | if not ending or '}' not in ending: |
| 5019 | return ('Invalid ICU format. No final closing bracket', last_pos - 1, |
| 5020 | last_pos) |
| 5021 | elif first != '{': |
| 5022 | return ( |
| 5023 | ('Invalid ICU format. Extra characters at the start of a complex ' |
| 5024 | 'message (go/icu-message-migration): "%s"') % |
| 5025 | starting, 0, len(starting)) |
| 5026 | elif ending != '}': |
| 5027 | return (('Invalid ICU format. Extra characters at the end of a complex ' |
| 5028 | 'message (go/icu-message-migration): "%s"') |
| 5029 | % ending, last_pos - 1, len(text) - 1) |
| 5030 | if kind not in valid_types: |
| 5031 | return (('Unknown ICU message type %s. ' |
| 5032 | 'Valid types are: plural, select, selectordinal') % kind, 0, 0) |
| 5033 | known, required = valid_types[kind] |
| 5034 | defined_variants = set() |
| 5035 | for variant, variant_range, value, value_range in variants: |
| 5036 | start, end = variant_range |
| 5037 | if variant in defined_variants: |
| 5038 | return ('Variant "%s" is defined more than once' % variant, |
| 5039 | start, end) |
| 5040 | elif known and variant not in known: |
| 5041 | return ('Variant "%s" is not valid for %s message' % (variant, kind), |
| 5042 | start, end) |
| 5043 | defined_variants.add(variant) |
| 5044 | # Check for nested structure |
| 5045 | res = _ValidateIcuSyntax(value[1:-1], level + 1, signatures) |
| 5046 | if res: |
| 5047 | return (res[0], res[1] + value_range[0] + 1, |
| 5048 | res[2] + value_range[0] + 1) |
| 5049 | missing = required - defined_variants |
| 5050 | if missing: |
| 5051 | return ('Required variants missing: %s' % ', '.join(missing), 0, |
| 5052 | len(text)) |
| 5053 | signatures.append((level, variable, kind, defined_variants)) |
| 5054 | |
| 5055 | |
| 5056 | def _ParseIcuVariants(text, offset=0): |
| 5057 | """Parse variants part of ICU complex message. |
| 5058 | |
| 5059 | Builds a tuple of variant names and values, as well as |
| 5060 | their offsets in the input string. |
| 5061 | |
| 5062 | Args: |
| 5063 | text: a string to parse |
| 5064 | offset: additional offset to add to positions in the text to get correct |
| 5065 | position in the complete ICU string. |
| 5066 | |
| 5067 | Returns: |
| 5068 | List of tuples, each tuple consist of four fields: variant name, |
| 5069 | variant name span (tuple of two integers), variant value, value |
| 5070 | span (tuple of two integers). |
| 5071 | """ |
| 5072 | depth, start, end = 0, -1, -1 |
| 5073 | variants = [] |
| 5074 | key = None |
| 5075 | for idx, char in enumerate(text): |
| 5076 | if char == '{': |
| 5077 | if not depth: |
| 5078 | start = idx |
| 5079 | chunk = text[end + 1:start] |
| 5080 | key = chunk.strip() |
| 5081 | pos = offset + end + 1 + chunk.find(key) |
| 5082 | span = (pos, pos + len(key)) |
| 5083 | depth += 1 |
| 5084 | elif char == '}': |
| 5085 | if not depth: |
| 5086 | return variants, depth, offset + idx |
| 5087 | depth -= 1 |
| 5088 | if not depth: |
| 5089 | end = idx |
| 5090 | variants.append((key, span, text[start:end + 1], (offset + start, |
| 5091 | offset + end + 1))) |
| 5092 | return variants, depth, offset + end + 1 |
| 5093 | |
meacer | 8c0d383 | 2019-12-26 21:46:16 | [diff] [blame] | 5094 | try: |
| 5095 | old_sys_path = sys.path |
| 5096 | sys.path = sys.path + [input_api.os_path.join( |
| 5097 | input_api.PresubmitLocalPath(), 'tools', 'translation')] |
| 5098 | from helper import grd_helper |
| 5099 | finally: |
| 5100 | sys.path = old_sys_path |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5101 | |
| 5102 | for f in affected_grds: |
| 5103 | file_path = f.LocalPath() |
| 5104 | old_id_to_msg_map = {} |
| 5105 | new_id_to_msg_map = {} |
Mustafa Emre Acer | d697ac9 | 2020-02-06 19:03:38 | [diff] [blame] | 5106 | # Note that this code doesn't check if the file has been deleted. This is |
| 5107 | # OK because it only uses the old and new file contents and doesn't load |
| 5108 | # the file via its path. |
| 5109 | # It's also possible that a file's content refers to a renamed or deleted |
| 5110 | # file via a <part> tag, such as <part file="now-deleted-file.grdp">. This |
| 5111 | # is OK as well, because grd_helper ignores <part> tags when loading .grd or |
| 5112 | # .grdp files. |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5113 | if file_path.endswith('.grdp'): |
| 5114 | if f.OldContents(): |
meacer | ff8a9b6 | 2019-12-10 19:43:58 | [diff] [blame] | 5115 | old_id_to_msg_map = grd_helper.GetGrdpMessagesFromString( |
Mustafa Emre Acer | c8a012d | 2018-07-31 00:00:39 | [diff] [blame] | 5116 | unicode('\n'.join(f.OldContents()))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5117 | if f.NewContents(): |
meacer | ff8a9b6 | 2019-12-10 19:43:58 | [diff] [blame] | 5118 | new_id_to_msg_map = grd_helper.GetGrdpMessagesFromString( |
Mustafa Emre Acer | c8a012d | 2018-07-31 00:00:39 | [diff] [blame] | 5119 | unicode('\n'.join(f.NewContents()))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5120 | else: |
meacer | ff8a9b6 | 2019-12-10 19:43:58 | [diff] [blame] | 5121 | file_dir = input_api.os_path.dirname(file_path) or '.' |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5122 | if f.OldContents(): |
meacer | ff8a9b6 | 2019-12-10 19:43:58 | [diff] [blame] | 5123 | old_id_to_msg_map = grd_helper.GetGrdMessages( |
| 5124 | StringIO(unicode('\n'.join(f.OldContents()))), file_dir) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5125 | if f.NewContents(): |
meacer | ff8a9b6 | 2019-12-10 19:43:58 | [diff] [blame] | 5126 | new_id_to_msg_map = grd_helper.GetGrdMessages( |
| 5127 | StringIO(unicode('\n'.join(f.NewContents()))), file_dir) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5128 | |
| 5129 | # Compute added, removed and modified message IDs. |
| 5130 | old_ids = set(old_id_to_msg_map) |
| 5131 | new_ids = set(new_id_to_msg_map) |
| 5132 | added_ids = new_ids - old_ids |
| 5133 | removed_ids = old_ids - new_ids |
| 5134 | modified_ids = set([]) |
| 5135 | for key in old_ids.intersection(new_ids): |
| 5136 | if (old_id_to_msg_map[key].FormatXml() |
| 5137 | != new_id_to_msg_map[key].FormatXml()): |
| 5138 | modified_ids.add(key) |
| 5139 | |
| 5140 | grd_name, ext = input_api.os_path.splitext( |
| 5141 | input_api.os_path.basename(file_path)) |
| 5142 | screenshots_dir = input_api.os_path.join( |
| 5143 | input_api.os_path.dirname(file_path), grd_name + ext.replace('.', '_')) |
| 5144 | |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5145 | if run_screenshot_check: |
| 5146 | # Check the screenshot directory for .png files. Warn if there is any. |
| 5147 | for png_path in affected_png_paths: |
| 5148 | if png_path.startswith(screenshots_dir): |
| 5149 | unnecessary_screenshots.append(png_path) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5150 | |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5151 | for added_id in added_ids: |
| 5152 | _CheckScreenshotAdded(screenshots_dir, added_id) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5153 | |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5154 | for modified_id in modified_ids: |
| 5155 | _CheckScreenshotAdded(screenshots_dir, modified_id) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5156 | |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5157 | for removed_id in removed_ids: |
| 5158 | _CheckScreenshotRemoved(screenshots_dir, removed_id) |
| 5159 | |
| 5160 | # Check new and changed strings for ICU syntax errors. |
| 5161 | for key in added_ids.union(modified_ids): |
| 5162 | msg = new_id_to_msg_map[key].ContentsAsXml('', True) |
| 5163 | err = _ValidateIcuSyntax(msg, 0, []) |
| 5164 | if err is not None: |
| 5165 | icu_syntax_errors.append(str(key) + ': ' + str(err[0])) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5166 | |
| 5167 | results = [] |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5168 | if run_screenshot_check: |
| 5169 | if unnecessary_screenshots: |
Mustafa Emre Acer | c6ed268 | 2020-07-07 07:24:00 | [diff] [blame] | 5170 | results.append(output_api.PresubmitError( |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5171 | 'Do not include actual screenshots in the changelist. Run ' |
| 5172 | 'tools/translate/upload_screenshots.py to upload them instead:', |
| 5173 | sorted(unnecessary_screenshots))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5174 | |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5175 | if missing_sha1: |
Mustafa Emre Acer | c6ed268 | 2020-07-07 07:24:00 | [diff] [blame] | 5176 | results.append(output_api.PresubmitError( |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5177 | 'You are adding or modifying UI strings.\n' |
| 5178 | 'To ensure the best translations, take screenshots of the relevant UI ' |
| 5179 | '(https://g.co/chrome/translation) and add these files to your ' |
| 5180 | 'changelist:', sorted(missing_sha1))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5181 | |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5182 | if unnecessary_sha1_files: |
Mustafa Emre Acer | c6ed268 | 2020-07-07 07:24:00 | [diff] [blame] | 5183 | results.append(output_api.PresubmitError( |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5184 | 'You removed strings associated with these files. Remove:', |
| 5185 | sorted(unnecessary_sha1_files))) |
| 5186 | else: |
| 5187 | results.append(output_api.PresubmitPromptOrNotify('Skipping translation ' |
| 5188 | 'screenshots check.')) |
| 5189 | |
| 5190 | if icu_syntax_errors: |
Rainhard Findling | 0e8d74c1 | 2020-06-26 13:48:07 | [diff] [blame] | 5191 | results.append(output_api.PresubmitPromptWarning( |
Rainhard Findling | fc31844c5 | 2020-05-15 09:58:26 | [diff] [blame] | 5192 | 'ICU syntax errors were found in the following strings (problems or ' |
| 5193 | 'feedback? Contact [email protected]):', items=icu_syntax_errors)) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 5194 | |
| 5195 | return results |
Mustafa Emre Acer | 51f2f74 | 2020-03-09 19:41:12 | [diff] [blame] | 5196 | |
| 5197 | |
| 5198 | def _CheckTranslationExpectations(input_api, output_api, |
| 5199 | repo_root=None, |
| 5200 | translation_expectations_path=None, |
| 5201 | grd_files=None): |
| 5202 | import sys |
| 5203 | affected_grds = [f for f in input_api.AffectedFiles() |
| 5204 | if (f.LocalPath().endswith('.grd') or |
| 5205 | f.LocalPath().endswith('.grdp'))] |
| 5206 | if not affected_grds: |
| 5207 | return [] |
| 5208 | |
| 5209 | try: |
| 5210 | old_sys_path = sys.path |
| 5211 | sys.path = sys.path + [ |
| 5212 | input_api.os_path.join( |
| 5213 | input_api.PresubmitLocalPath(), 'tools', 'translation')] |
| 5214 | from helper import git_helper |
| 5215 | from helper import translation_helper |
| 5216 | finally: |
| 5217 | sys.path = old_sys_path |
| 5218 | |
| 5219 | # Check that translation expectations can be parsed and we can get a list of |
| 5220 | # translatable grd files. |repo_root| and |translation_expectations_path| are |
| 5221 | # only passed by tests. |
| 5222 | if not repo_root: |
| 5223 | repo_root = input_api.PresubmitLocalPath() |
| 5224 | if not translation_expectations_path: |
| 5225 | translation_expectations_path = input_api.os_path.join( |
| 5226 | repo_root, 'tools', 'gritsettings', |
| 5227 | 'translation_expectations.pyl') |
| 5228 | if not grd_files: |
| 5229 | grd_files = git_helper.list_grds_in_repository(repo_root) |
| 5230 | |
| 5231 | try: |
| 5232 | translation_helper.get_translatable_grds(repo_root, grd_files, |
| 5233 | translation_expectations_path) |
| 5234 | except Exception as e: |
| 5235 | return [output_api.PresubmitNotifyResult( |
| 5236 | 'Failed to get a list of translatable grd files. This happens when:\n' |
| 5237 | ' - One of the modified grd or grdp files cannot be parsed or\n' |
| 5238 | ' - %s is not updated.\n' |
| 5239 | 'Stack:\n%s' % (translation_expectations_path, str(e)))] |
| 5240 | return [] |
Ken Rockot | c31f483 | 2020-05-29 18:58:51 | [diff] [blame] | 5241 | |
| 5242 | |
| 5243 | def _CheckStableMojomChanges(input_api, output_api): |
| 5244 | """Changes to [Stable] mojom types must preserve backward-compatibility.""" |
Ken Rockot | ad7901f94 | 2020-06-04 20:17:09 | [diff] [blame] | 5245 | changed_mojoms = input_api.AffectedFiles( |
| 5246 | include_deletes=True, |
| 5247 | file_filter=lambda f: f.LocalPath().endswith(('.mojom'))) |
Ken Rockot | c31f483 | 2020-05-29 18:58:51 | [diff] [blame] | 5248 | delta = [] |
| 5249 | for mojom in changed_mojoms: |
| 5250 | old_contents = ''.join(mojom.OldContents()) or None |
| 5251 | new_contents = ''.join(mojom.NewContents()) or None |
| 5252 | delta.append({ |
| 5253 | 'filename': mojom.LocalPath(), |
| 5254 | 'old': '\n'.join(mojom.OldContents()) or None, |
| 5255 | 'new': '\n'.join(mojom.NewContents()) or None, |
| 5256 | }) |
| 5257 | |
| 5258 | process = input_api.subprocess.Popen( |
| 5259 | [input_api.python_executable, |
| 5260 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'mojo', |
| 5261 | 'public', 'tools', 'mojom', |
| 5262 | 'check_stable_mojom_compatibility.py'), |
| 5263 | '--src-root', input_api.PresubmitLocalPath()], |
| 5264 | stdin=input_api.subprocess.PIPE, |
| 5265 | stdout=input_api.subprocess.PIPE, |
| 5266 | stderr=input_api.subprocess.PIPE, |
| 5267 | universal_newlines=True) |
| 5268 | (x, error) = process.communicate(input=input_api.json.dumps(delta)) |
| 5269 | if process.returncode: |
| 5270 | return [output_api.PresubmitError( |
| 5271 | 'One or more [Stable] mojom definitions appears to have been changed ' |
| 5272 | 'in a way that is not backward-compatible.', |
| 5273 | long_text=error)] |
| 5274 | return [] |