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