[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[\\/].*", |
| 20 | r"^v8[\\/].*", |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 21 | r".*MakeFile$", |
[email protected] | 1084ccc | 2012-03-14 03:22:53 | [diff] [blame] | 22 | r".+_autogen\.h$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 23 | r".+[\\/]pnacl_shim\.c$", |
| 24 | r"^gpu[\\/]config[\\/].*_list_json\.cc$", |
| 25 | r"^chrome[\\/]browser[\\/]resources[\\/]pdf[\\/]index.js", |
| 26 | r"tools[\\/]md_browser[\\/].*\.css$", |
Kenneth Russell | 077c8d9 | 2017-12-16 02:52:14 | [diff] [blame] | 27 | # Test pages for Maps telemetry tests. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 28 | r"tools[\\/]perf[\\/]page_sets[\\/]maps_perf_test.*", |
ehmaldonado | 78eee2ed | 2017-03-28 13:16:54 | [diff] [blame] | 29 | # Test pages for WebRTC telemetry tests. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 30 | r"tools[\\/]perf[\\/]page_sets[\\/]webrtc_cases.*", |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 31 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 32 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 33 | |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 34 | # Fragment of a regular expression that matches C++ and Objective-C++ |
| 35 | # implementation files. |
| 36 | _IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$' |
| 37 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 38 | |
Wei-Yin Chen (陳威尹) | c0624d00 | 2018-07-30 18:22:19 | [diff] [blame] | 39 | # Fragment of a regular expression that matches C++ and Objective-C++ |
| 40 | # header files. |
| 41 | _HEADER_EXTENSIONS = r'\.(h|hpp|hxx)$' |
| 42 | |
| 43 | |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 44 | # Regular expression that matches code only used for test binaries |
| 45 | # (best effort). |
| 46 | _TEST_CODE_EXCLUDED_PATHS = ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 47 | r'.*[\\/](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS, |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 48 | r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS, |
Steven Holte | 27008b742 | 2018-01-29 20:55:44 | [diff] [blame] | 49 | r'.+_(api|browser|eg|int|perf|pixel|unit|ui)?test(_[a-z]+)?%s' % |
[email protected] | e2d7e6f | 2013-04-23 12:57:12 | [diff] [blame] | 50 | _IMPLEMENTATION_EXTENSIONS, |
Matthew Denton | 63ea1e6 | 2019-03-25 20:39:18 | [diff] [blame] | 51 | r'.+_(fuzz|fuzzer)(_[a-z]+)?%s' % _IMPLEMENTATION_EXTENSIONS, |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 52 | r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS, |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 53 | r'.*[\\/](test|tool(s)?)[\\/].*', |
[email protected] | ef070cc | 2013-05-03 11:53:05 | [diff] [blame] | 54 | # content_shell is used for running layout tests. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 55 | r'content[\\/]shell[\\/].*', |
[email protected] | 7b05498 | 2013-11-27 00:44:47 | [diff] [blame] | 56 | # Non-production example code. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 57 | r'mojo[\\/]examples[\\/].*', |
[email protected] | 8176de1 | 2014-06-20 19:07:08 | [diff] [blame] | 58 | # Launcher for running iOS tests on the simulator. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 59 | r'testing[\\/]iossim[\\/]iossim\.mm$', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 60 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 61 | |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 62 | _THIRD_PARTY_EXCEPT_BLINK = 'third_party/(?!blink/)' |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 63 | |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 64 | _TEST_ONLY_WARNING = ( |
| 65 | 'You might be calling functions intended only for testing from\n' |
| 66 | 'production code. It is OK to ignore this warning if you know what\n' |
| 67 | 'you are doing, as the heuristics used to detect the situation are\n' |
[email protected] | b014977 | 2014-03-27 16:47:58 | [diff] [blame] | 68 | 'not perfect. The commit queue will not block on this warning.') |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 69 | |
| 70 | |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 71 | _INCLUDE_ORDER_WARNING = ( |
marja | a017dc48 | 2015-03-09 17:13:40 | [diff] [blame] | 72 | 'Your #include order seems to be broken. Remember to use the right ' |
avi | ce9a898 | 2015-11-24 20:36:21 | [diff] [blame] | 73 | 'collation (LC_COLLATE=C) and check\nhttps://google.github.io/styleguide/' |
| 74 | 'cppguide.html#Names_and_Order_of_Includes') |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 75 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 76 | |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 77 | # Format: Sequence of tuples containing: |
| 78 | # * String pattern or, if starting with a slash, a regular expression. |
| 79 | # * Sequence of strings to show when the pattern matches. |
| 80 | # * 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] | 81 | _BANNED_JAVA_FUNCTIONS = ( |
| 82 | ( |
| 83 | 'StrictMode.allowThreadDiskReads()', |
| 84 | ( |
| 85 | 'Prefer using StrictModeContext.allowDiskReads() to using StrictMode ' |
| 86 | 'directly.', |
| 87 | ), |
| 88 | False, |
| 89 | ), |
| 90 | ( |
| 91 | 'StrictMode.allowThreadDiskWrites()', |
| 92 | ( |
| 93 | 'Prefer using StrictModeContext.allowDiskWrites() to using StrictMode ' |
| 94 | 'directly.', |
| 95 | ), |
| 96 | False, |
| 97 | ), |
| 98 | ) |
| 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. |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 104 | _BANNED_OBJC_FUNCTIONS = ( |
| 105 | ( |
| 106 | 'addTrackingRect:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 107 | ( |
| 108 | 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 109 | 'prohibited. Please use CrTrackingArea instead.', |
| 110 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 111 | ), |
| 112 | False, |
| 113 | ), |
| 114 | ( |
[email protected] | eaae197 | 2014-04-16 04:17:26 | [diff] [blame] | 115 | r'/NSTrackingArea\W', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 116 | ( |
| 117 | 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 118 | 'instead.', |
| 119 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 120 | ), |
| 121 | False, |
| 122 | ), |
| 123 | ( |
| 124 | 'convertPointFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 125 | ( |
| 126 | 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 127 | 'Please use |convertPoint:(point) fromView:nil| instead.', |
| 128 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 129 | ), |
| 130 | True, |
| 131 | ), |
| 132 | ( |
| 133 | 'convertPointToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 134 | ( |
| 135 | 'The use of -[NSView convertPointToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 136 | 'Please use |convertPoint:(point) toView:nil| instead.', |
| 137 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 138 | ), |
| 139 | True, |
| 140 | ), |
| 141 | ( |
| 142 | 'convertRectFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 143 | ( |
| 144 | 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 145 | 'Please use |convertRect:(point) fromView:nil| instead.', |
| 146 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 147 | ), |
| 148 | True, |
| 149 | ), |
| 150 | ( |
| 151 | 'convertRectToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 152 | ( |
| 153 | 'The use of -[NSView convertRectToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 154 | 'Please use |convertRect:(point) toView:nil| instead.', |
| 155 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 156 | ), |
| 157 | True, |
| 158 | ), |
| 159 | ( |
| 160 | 'convertSizeFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 161 | ( |
| 162 | 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 163 | 'Please use |convertSize:(point) fromView:nil| instead.', |
| 164 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 165 | ), |
| 166 | True, |
| 167 | ), |
| 168 | ( |
| 169 | 'convertSizeToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 170 | ( |
| 171 | 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 172 | 'Please use |convertSize:(point) toView:nil| instead.', |
| 173 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 174 | ), |
| 175 | True, |
| 176 | ), |
jif | 6539870 | 2016-10-27 10:19:48 | [diff] [blame] | 177 | ( |
| 178 | r"/\s+UTF8String\s*]", |
| 179 | ( |
| 180 | 'The use of -[NSString UTF8String] is dangerous as it can return null', |
| 181 | 'even if |canBeConvertedToEncoding:NSUTF8StringEncoding| returns YES.', |
| 182 | 'Please use |SysNSStringToUTF8| instead.', |
| 183 | ), |
| 184 | True, |
| 185 | ), |
Sylvain Defresne | 4cf1d18 | 2017-09-18 14:16:34 | [diff] [blame] | 186 | ( |
| 187 | r'__unsafe_unretained', |
| 188 | ( |
| 189 | 'The use of __unsafe_unretained is almost certainly wrong, unless', |
| 190 | 'when interacting with NSFastEnumeration or NSInvocation.', |
| 191 | 'Please use __weak in files build with ARC, nothing otherwise.', |
| 192 | ), |
| 193 | False, |
| 194 | ), |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 195 | ) |
| 196 | |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 197 | # Format: Sequence of tuples containing: |
| 198 | # * String pattern or, if starting with a slash, a regular expression. |
| 199 | # * Sequence of strings to show when the pattern matches. |
| 200 | # * 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] | 201 | _BANNED_IOS_OBJC_FUNCTIONS = ( |
| 202 | ( |
| 203 | r'/\bTEST[(]', |
| 204 | ( |
| 205 | 'TEST() macro should not be used in Objective-C++ code as it does not ', |
| 206 | 'drain the autorelease pool at the end of the test. Use TEST_F() ', |
| 207 | 'macro instead with a fixture inheriting from PlatformTest (or a ', |
| 208 | 'typedef).' |
| 209 | ), |
| 210 | True, |
| 211 | ), |
| 212 | ( |
| 213 | r'/\btesting::Test\b', |
| 214 | ( |
| 215 | 'testing::Test should not be used in Objective-C++ code as it does ', |
| 216 | 'not drain the autorelease pool at the end of the test. Use ', |
| 217 | 'PlatformTest instead.' |
| 218 | ), |
| 219 | True, |
| 220 | ), |
| 221 | ) |
| 222 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 223 | |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 224 | # Format: Sequence of tuples containing: |
| 225 | # * String pattern or, if starting with a slash, a regular expression. |
| 226 | # * Sequence of strings to show when the pattern matches. |
| 227 | # * Error flag. True if a match is a presubmit error, otherwise it's a warning. |
| 228 | # * Sequence of paths to *not* check (regexps). |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 229 | _BANNED_CPP_FUNCTIONS = ( |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 230 | ( |
thomasanderson | e7caaa9b | 2017-03-29 19:22:53 | [diff] [blame] | 231 | r'\bNULL\b', |
| 232 | ( |
| 233 | 'New code should not use NULL. Use nullptr instead.', |
| 234 | ), |
| 235 | True, |
| 236 | (), |
| 237 | ), |
Antonio Gomes | 07300d0 | 2019-03-13 20:59:57 | [diff] [blame] | 238 | # Make sure that gtest's FRIEND_TEST() macro is not used; the |
| 239 | # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be |
| 240 | # used instead since that allows for FLAKY_ and DISABLED_ prefixes. |
thomasanderson | e7caaa9b | 2017-03-29 19:22:53 | [diff] [blame] | 241 | ( |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 242 | 'FRIEND_TEST(', |
| 243 | ( |
[email protected] | e3c94550 | 2012-06-26 20:01:49 | [diff] [blame] | 244 | 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 245 | 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.', |
| 246 | ), |
| 247 | False, |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 248 | (), |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 249 | ), |
| 250 | ( |
thomasanderson | 4b56905 | 2016-09-14 20:15:53 | [diff] [blame] | 251 | r'XSelectInput|CWEventMask|XCB_CW_EVENT_MASK', |
| 252 | ( |
| 253 | 'Chrome clients wishing to select events on X windows should use', |
| 254 | 'ui::XScopedEventSelector. It is safe to ignore this warning only if', |
| 255 | 'you are selecting events from the GPU process, or if you are using', |
| 256 | 'an XDisplay other than gfx::GetXDisplay().', |
| 257 | ), |
| 258 | True, |
| 259 | ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 260 | r"^ui[\\/]gl[\\/].*\.cc$", |
| 261 | r"^media[\\/]gpu[\\/].*\.cc$", |
| 262 | r"^gpu[\\/].*\.cc$", |
thomasanderson | 4b56905 | 2016-09-14 20:15:53 | [diff] [blame] | 263 | ), |
| 264 | ), |
| 265 | ( |
thomasanderson | e043e3ce | 2017-06-08 00:43:20 | [diff] [blame] | 266 | r'XInternAtom|xcb_intern_atom', |
| 267 | ( |
thomasanderson | 11aa41d | 2017-06-08 22:22:38 | [diff] [blame] | 268 | 'Use gfx::GetAtom() instead of interning atoms directly.', |
thomasanderson | e043e3ce | 2017-06-08 00:43:20 | [diff] [blame] | 269 | ), |
| 270 | True, |
| 271 | ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 272 | r"^gpu[\\/]ipc[\\/]service[\\/]gpu_watchdog_thread\.cc$", |
| 273 | r"^remoting[\\/]host[\\/]linux[\\/]x_server_clipboard\.cc$", |
| 274 | r"^ui[\\/]gfx[\\/]x[\\/]x11_atom_cache\.cc$", |
thomasanderson | e043e3ce | 2017-06-08 00:43:20 | [diff] [blame] | 275 | ), |
| 276 | ), |
| 277 | ( |
tomhudson | e2c14d55 | 2016-05-26 17:07:46 | [diff] [blame] | 278 | 'setMatrixClip', |
| 279 | ( |
| 280 | 'Overriding setMatrixClip() is prohibited; ', |
| 281 | 'the base function is deprecated. ', |
| 282 | ), |
| 283 | True, |
| 284 | (), |
| 285 | ), |
| 286 | ( |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 287 | 'SkRefPtr', |
| 288 | ( |
| 289 | 'The use of SkRefPtr is prohibited. ', |
tomhudson | 7e6e051 | 2016-04-19 19:27:22 | [diff] [blame] | 290 | 'Please use sk_sp<> instead.' |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 291 | ), |
| 292 | True, |
| 293 | (), |
| 294 | ), |
| 295 | ( |
| 296 | 'SkAutoRef', |
| 297 | ( |
| 298 | 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ', |
tomhudson | 7e6e051 | 2016-04-19 19:27:22 | [diff] [blame] | 299 | 'Please use sk_sp<> instead.' |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 300 | ), |
| 301 | True, |
| 302 | (), |
| 303 | ), |
| 304 | ( |
| 305 | 'SkAutoTUnref', |
| 306 | ( |
| 307 | 'The use of SkAutoTUnref is dangerous because it implicitly ', |
tomhudson | 7e6e051 | 2016-04-19 19:27:22 | [diff] [blame] | 308 | 'converts to a raw pointer. Please use sk_sp<> instead.' |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 309 | ), |
| 310 | True, |
| 311 | (), |
| 312 | ), |
| 313 | ( |
| 314 | 'SkAutoUnref', |
| 315 | ( |
| 316 | 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ', |
| 317 | 'because it implicitly converts to a raw pointer. ', |
tomhudson | 7e6e051 | 2016-04-19 19:27:22 | [diff] [blame] | 318 | 'Please use sk_sp<> instead.' |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 319 | ), |
| 320 | True, |
| 321 | (), |
| 322 | ), |
[email protected] | d89eec8 | 2013-12-03 14:10:59 | [diff] [blame] | 323 | ( |
| 324 | r'/HANDLE_EINTR\(.*close', |
| 325 | ( |
| 326 | 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file', |
| 327 | 'descriptor will be closed, and it is incorrect to retry the close.', |
| 328 | 'Either call close directly and ignore its return value, or wrap close', |
| 329 | 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623' |
| 330 | ), |
| 331 | True, |
| 332 | (), |
| 333 | ), |
| 334 | ( |
| 335 | r'/IGNORE_EINTR\((?!.*close)', |
| 336 | ( |
| 337 | 'IGNORE_EINTR is only valid when wrapping close. To wrap other system', |
| 338 | 'calls, use HANDLE_EINTR. See http://crbug.com/269623', |
| 339 | ), |
| 340 | True, |
| 341 | ( |
| 342 | # Files that #define IGNORE_EINTR. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 343 | r'^base[\\/]posix[\\/]eintr_wrapper\.h$', |
| 344 | r'^ppapi[\\/]tests[\\/]test_broker\.cc$', |
[email protected] | d89eec8 | 2013-12-03 14:10:59 | [diff] [blame] | 345 | ), |
| 346 | ), |
[email protected] | ec5b3f0 | 2014-04-04 18:43:43 | [diff] [blame] | 347 | ( |
| 348 | r'/v8::Extension\(', |
| 349 | ( |
| 350 | 'Do not introduce new v8::Extensions into the code base, use', |
| 351 | 'gin::Wrappable instead. See http://crbug.com/334679', |
| 352 | ), |
| 353 | True, |
[email protected] | f55c90ee6 | 2014-04-12 00:50:03 | [diff] [blame] | 354 | ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 355 | r'extensions[\\/]renderer[\\/]safe_builtins\.*', |
[email protected] | f55c90ee6 | 2014-04-12 00:50:03 | [diff] [blame] | 356 | ), |
[email protected] | ec5b3f0 | 2014-04-04 18:43:43 | [diff] [blame] | 357 | ), |
skyostil | f9469f7 | 2015-04-20 10:38:52 | [diff] [blame] | 358 | ( |
jam | e2d1a95 | 2016-04-02 00:27:10 | [diff] [blame] | 359 | '#pragma comment(lib,', |
| 360 | ( |
| 361 | 'Specify libraries to link with in build files and not in the source.', |
| 362 | ), |
| 363 | True, |
Mirko Bonadei | f4f0f0e | 2018-04-12 09:29:41 | [diff] [blame] | 364 | ( |
tzik | 3f29599 | 2018-12-04 20:32:23 | [diff] [blame] | 365 | r'^base[\\/]third_party[\\/]symbolize[\\/].*', |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 366 | r'^third_party[\\/]abseil-cpp[\\/].*', |
Mirko Bonadei | f4f0f0e | 2018-04-12 09:29:41 | [diff] [blame] | 367 | ), |
jam | e2d1a95 | 2016-04-02 00:27:10 | [diff] [blame] | 368 | ), |
fdoray | c4ac18d | 2017-05-01 21:39:59 | [diff] [blame] | 369 | ( |
Gabriel Charette | 7cc6c43 | 2018-04-25 20:52:02 | [diff] [blame] | 370 | r'/base::SequenceChecker\b', |
gab | d52c912a | 2017-05-11 04:15:59 | [diff] [blame] | 371 | ( |
| 372 | 'Consider using SEQUENCE_CHECKER macros instead of the class directly.', |
| 373 | ), |
| 374 | False, |
| 375 | (), |
| 376 | ), |
| 377 | ( |
Gabriel Charette | 7cc6c43 | 2018-04-25 20:52:02 | [diff] [blame] | 378 | r'/base::ThreadChecker\b', |
gab | d52c912a | 2017-05-11 04:15:59 | [diff] [blame] | 379 | ( |
| 380 | 'Consider using THREAD_CHECKER macros instead of the class directly.', |
| 381 | ), |
| 382 | False, |
| 383 | (), |
| 384 | ), |
dbeam | b6f4fde | 2017-06-15 04:03:06 | [diff] [blame] | 385 | ( |
Yuri Wiitala | 2f8de5c | 2017-07-21 00:11:06 | [diff] [blame] | 386 | r'/(Time(|Delta|Ticks)|ThreadTicks)::FromInternalValue|ToInternalValue', |
| 387 | ( |
| 388 | 'base::TimeXXX::FromInternalValue() and ToInternalValue() are', |
| 389 | 'deprecated (http://crbug.com/634507). Please avoid converting away', |
| 390 | 'from the Time types in Chromium code, especially if any math is', |
| 391 | 'being done on time values. For interfacing with platform/library', |
| 392 | 'APIs, use FromMicroseconds() or InMicroseconds(), or one of the other', |
| 393 | 'type converter methods instead. For faking TimeXXX values (for unit', |
| 394 | 'testing only), use TimeXXX() + TimeDelta::FromMicroseconds(N). For', |
| 395 | 'other use cases, please contact base/time/OWNERS.', |
| 396 | ), |
| 397 | False, |
| 398 | (), |
| 399 | ), |
| 400 | ( |
dbeam | b6f4fde | 2017-06-15 04:03:06 | [diff] [blame] | 401 | 'CallJavascriptFunctionUnsafe', |
| 402 | ( |
| 403 | "Don't use CallJavascriptFunctionUnsafe() in new code. Instead, use", |
| 404 | 'AllowJavascript(), OnJavascriptAllowed()/OnJavascriptDisallowed(),', |
| 405 | 'and CallJavascriptFunction(). See https://goo.gl/qivavq.', |
| 406 | ), |
| 407 | False, |
| 408 | ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 409 | r'^content[\\/]browser[\\/]webui[\\/]web_ui_impl\.(cc|h)$', |
| 410 | r'^content[\\/]public[\\/]browser[\\/]web_ui\.h$', |
| 411 | r'^content[\\/]public[\\/]test[\\/]test_web_ui\.(cc|h)$', |
dbeam | b6f4fde | 2017-06-15 04:03:06 | [diff] [blame] | 412 | ), |
| 413 | ), |
dskiba | 1474c2bfd6 | 2017-07-20 02:19:24 | [diff] [blame] | 414 | ( |
| 415 | 'leveldb::DB::Open', |
| 416 | ( |
| 417 | 'Instead of leveldb::DB::Open() use leveldb_env::OpenDB() from', |
| 418 | 'third_party/leveldatabase/env_chromium.h. It exposes databases to', |
| 419 | "Chrome's tracing, making their memory usage visible.", |
| 420 | ), |
| 421 | True, |
| 422 | ( |
| 423 | r'^third_party/leveldatabase/.*\.(cc|h)$', |
| 424 | ), |
Gabriel Charette | 0592c3a | 2017-07-26 12:02:04 | [diff] [blame] | 425 | ), |
| 426 | ( |
Chris Mumford | c38afb6 | 2017-10-09 17:55:08 | [diff] [blame] | 427 | 'leveldb::NewMemEnv', |
| 428 | ( |
| 429 | 'Instead of leveldb::NewMemEnv() use leveldb_chrome::NewMemEnv() from', |
Chris Mumford | 8d26d10a | 2018-04-20 17:07:58 | [diff] [blame] | 430 | 'third_party/leveldatabase/leveldb_chrome.h. It exposes environments', |
| 431 | "to Chrome's tracing, making their memory usage visible.", |
Chris Mumford | c38afb6 | 2017-10-09 17:55:08 | [diff] [blame] | 432 | ), |
| 433 | True, |
| 434 | ( |
| 435 | r'^third_party/leveldatabase/.*\.(cc|h)$', |
| 436 | ), |
| 437 | ), |
| 438 | ( |
Gabriel Charette | d9839bc | 2017-07-29 14:17:47 | [diff] [blame] | 439 | 'RunLoop::QuitCurrent', |
| 440 | ( |
Robert Liao | 64b7ab2 | 2017-08-04 23:03:43 | [diff] [blame] | 441 | 'Please migrate away from RunLoop::QuitCurrent*() methods. Use member', |
| 442 | 'methods of a specific RunLoop instance instead.', |
Gabriel Charette | d9839bc | 2017-07-29 14:17:47 | [diff] [blame] | 443 | ), |
Gabriel Charette | c0a8f3ee | 2018-04-25 20:49:41 | [diff] [blame] | 444 | False, |
Gabriel Charette | d9839bc | 2017-07-29 14:17:47 | [diff] [blame] | 445 | (), |
Gabriel Charette | a4497505 | 2017-08-21 23:14:04 | [diff] [blame] | 446 | ), |
| 447 | ( |
| 448 | 'base::ScopedMockTimeMessageLoopTaskRunner', |
| 449 | ( |
Gabriel Charette | 87cc1af | 2018-04-25 20:52:51 | [diff] [blame] | 450 | 'ScopedMockTimeMessageLoopTaskRunner is deprecated. Prefer', |
| 451 | 'ScopedTaskEnvironment::MainThreadType::MOCK_TIME. There are still a', |
| 452 | 'few cases that may require a ScopedMockTimeMessageLoopTaskRunner', |
| 453 | '(i.e. mocking the main MessageLoopForUI in browser_tests), but check', |
| 454 | 'with gab@ first if you think you need it)', |
Gabriel Charette | a4497505 | 2017-08-21 23:14:04 | [diff] [blame] | 455 | ), |
Gabriel Charette | 87cc1af | 2018-04-25 20:52:51 | [diff] [blame] | 456 | False, |
Gabriel Charette | a4497505 | 2017-08-21 23:14:04 | [diff] [blame] | 457 | (), |
Eric Stevenson | 6b47b44c | 2017-08-30 20:41:57 | [diff] [blame] | 458 | ), |
| 459 | ( |
| 460 | r'std::regex', |
| 461 | ( |
| 462 | 'Using std::regex adds unnecessary binary size to Chrome. Please use', |
Mostyn Bramley-Moore | 6b42732 | 2017-12-21 22:11:02 | [diff] [blame] | 463 | 're2::RE2 instead (crbug.com/755321)', |
Eric Stevenson | 6b47b44c | 2017-08-30 20:41:57 | [diff] [blame] | 464 | ), |
| 465 | True, |
| 466 | (), |
Francois Doray | 43670e3 | 2017-09-27 12:40:38 | [diff] [blame] | 467 | ), |
| 468 | ( |
Daniel Bratell | 69334cc | 2019-03-26 11:07:45 | [diff] [blame] | 469 | r'/\bstd::to_string\b', |
| 470 | ( |
| 471 | 'std::to_string is locale dependent and slower than alternatives.', |
| 472 | 'For locale-independent strings, e.g. writing numbers to and from', |
| 473 | 'disk profiles, use base::NumberToString().', |
| 474 | 'For user-visible strings, use base::FormatNumber() and', |
| 475 | 'the related functions in base/i18n/number_formatting.h.', |
| 476 | ), |
| 477 | False, # Only a warning for now since it is already used, |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 478 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
Daniel Bratell | 69334cc | 2019-03-26 11:07:45 | [diff] [blame] | 479 | ), |
| 480 | ( |
| 481 | r'/\bstd::shared_ptr\b', |
| 482 | ( |
| 483 | 'std::shared_ptr should not be used. Use scoped_refptr instead.', |
| 484 | ), |
| 485 | True, |
Daniel Bratell | 609102be | 2019-03-27 20:53:21 | [diff] [blame] | 486 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 487 | ), |
| 488 | ( |
| 489 | r'/\blong long\b', |
| 490 | ( |
| 491 | 'long long is banned. Use stdint.h if you need a 64 bit number.', |
| 492 | ), |
| 493 | False, # Only a warning since it is already used. |
| 494 | [_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders. |
| 495 | ), |
| 496 | ( |
| 497 | r'/\bstd::bind\b', |
| 498 | ( |
| 499 | 'std::bind is banned because of lifetime risks.', |
| 500 | 'Use base::BindOnce or base::BindRepeating instead.', |
| 501 | ), |
| 502 | True, |
| 503 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 504 | ), |
| 505 | ( |
| 506 | r'/\b#include <chrono>\b', |
| 507 | ( |
| 508 | '<chrono> overlaps with Time APIs in base. Keep using', |
| 509 | 'base classes.', |
| 510 | ), |
| 511 | True, |
| 512 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 513 | ), |
| 514 | ( |
| 515 | r'/\b#include <exception>\b', |
| 516 | ( |
| 517 | 'Exceptions are banned and disabled in Chromium.', |
| 518 | ), |
| 519 | True, |
| 520 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 521 | ), |
| 522 | ( |
| 523 | r'/\bstd::function\b', |
| 524 | ( |
| 525 | 'std::function is banned. Instead use base::Callback which directly', |
| 526 | 'supports Chromium\'s weak pointers, ref counting and more.', |
| 527 | ), |
| 528 | False, # Only a warning since there are dozens of uses already. |
| 529 | [_THIRD_PARTY_EXCEPT_BLINK], # Do not warn in third_party folders. |
| 530 | ), |
| 531 | ( |
| 532 | r'/\b#include <random>\b', |
| 533 | ( |
| 534 | 'Do not use any random number engines from <random>. Instead', |
| 535 | 'use base::RandomBitGenerator.', |
| 536 | ), |
| 537 | True, |
| 538 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
| 539 | ), |
| 540 | ( |
| 541 | r'/\bstd::ratio\b', |
| 542 | ( |
| 543 | 'std::ratio is banned by the Google Style Guide.', |
| 544 | ), |
| 545 | True, |
| 546 | [_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders. |
Daniel Bratell | 69334cc | 2019-03-26 11:07:45 | [diff] [blame] | 547 | ), |
| 548 | ( |
Francois Doray | 43670e3 | 2017-09-27 12:40:38 | [diff] [blame] | 549 | (r'/base::ThreadRestrictions::(ScopedAllowIO|AssertIOAllowed|' |
| 550 | r'DisallowWaiting|AssertWaitAllowed|SetWaitAllowed|ScopedAllowWait)'), |
| 551 | ( |
| 552 | 'Use the new API in base/threading/thread_restrictions.h.', |
| 553 | ), |
Gabriel Charette | 04b138f | 2018-08-06 00:03:22 | [diff] [blame] | 554 | False, |
Francois Doray | 43670e3 | 2017-09-27 12:40:38 | [diff] [blame] | 555 | (), |
| 556 | ), |
Luis Hector Chavez | 9bbaed53 | 2017-11-30 18:25:38 | [diff] [blame] | 557 | ( |
| 558 | r'/\bbase::Bind\(', |
| 559 | ( |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 560 | 'Please consider using base::Bind{Once,Repeating} instead', |
Mostyn Bramley-Moore | 6b42732 | 2017-12-21 22:11:02 | [diff] [blame] | 561 | 'of base::Bind. (crbug.com/714018)', |
Luis Hector Chavez | 9bbaed53 | 2017-11-30 18:25:38 | [diff] [blame] | 562 | ), |
| 563 | False, |
| 564 | (), |
| 565 | ), |
| 566 | ( |
| 567 | r'/\bbase::Callback<', |
| 568 | ( |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 569 | 'Please consider using base::{Once,Repeating}Callback instead', |
Mostyn Bramley-Moore | 6b42732 | 2017-12-21 22:11:02 | [diff] [blame] | 570 | 'of base::Callback. (crbug.com/714018)', |
Luis Hector Chavez | 9bbaed53 | 2017-11-30 18:25:38 | [diff] [blame] | 571 | ), |
| 572 | False, |
| 573 | (), |
| 574 | ), |
| 575 | ( |
| 576 | r'/\bbase::Closure\b', |
| 577 | ( |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 578 | 'Please consider using base::{Once,Repeating}Closure instead', |
Mostyn Bramley-Moore | 6b42732 | 2017-12-21 22:11:02 | [diff] [blame] | 579 | 'of base::Closure. (crbug.com/714018)', |
Luis Hector Chavez | 9bbaed53 | 2017-11-30 18:25:38 | [diff] [blame] | 580 | ), |
| 581 | False, |
| 582 | (), |
| 583 | ), |
Victor Costan | 3653df6 | 2018-02-08 21:38:16 | [diff] [blame] | 584 | ( |
Alex Ilin | 5929abe3 | 2019-04-03 17:09:34 | [diff] [blame] | 585 | r'/base::SharedMemory(|Handle)', |
Alex Ilin | 63058f6 | 2019-03-28 19:29:45 | [diff] [blame] | 586 | ( |
| 587 | 'base::SharedMemory is deprecated. Please use', |
| 588 | '{Writable,ReadOnly}SharedMemoryRegion instead.', |
| 589 | ), |
| 590 | False, |
| 591 | (), |
| 592 | ), |
| 593 | ( |
Gabriel Charette | 147335ea | 2018-03-22 15:59:19 | [diff] [blame] | 594 | r'RunMessageLoop', |
| 595 | ( |
| 596 | 'RunMessageLoop is deprecated, use RunLoop instead.', |
| 597 | ), |
| 598 | False, |
| 599 | (), |
| 600 | ), |
| 601 | ( |
| 602 | r'RunThisRunLoop', |
| 603 | ( |
| 604 | 'RunThisRunLoop is deprecated, use RunLoop directly instead.', |
| 605 | ), |
| 606 | False, |
| 607 | (), |
| 608 | ), |
| 609 | ( |
| 610 | r'RunAllPendingInMessageLoop()', |
| 611 | ( |
| 612 | "Prefer RunLoop over RunAllPendingInMessageLoop, please contact gab@", |
| 613 | "if you're convinced you need this.", |
| 614 | ), |
| 615 | False, |
| 616 | (), |
| 617 | ), |
| 618 | ( |
| 619 | r'RunAllPendingInMessageLoop(BrowserThread', |
| 620 | ( |
| 621 | 'RunAllPendingInMessageLoop is deprecated. Use RunLoop for', |
| 622 | 'BrowserThread::UI, TestBrowserThreadBundle::RunIOThreadUntilIdle', |
| 623 | 'for BrowserThread::IO, and prefer RunLoop::QuitClosure to observe', |
| 624 | 'async events instead of flushing threads.', |
| 625 | ), |
| 626 | False, |
| 627 | (), |
| 628 | ), |
| 629 | ( |
| 630 | r'MessageLoopRunner', |
| 631 | ( |
| 632 | 'MessageLoopRunner is deprecated, use RunLoop instead.', |
| 633 | ), |
| 634 | False, |
| 635 | (), |
| 636 | ), |
| 637 | ( |
| 638 | r'GetDeferredQuitTaskForRunLoop', |
| 639 | ( |
| 640 | "GetDeferredQuitTaskForRunLoop shouldn't be needed, please contact", |
| 641 | "gab@ if you found a use case where this is the only solution.", |
| 642 | ), |
| 643 | False, |
| 644 | (), |
| 645 | ), |
| 646 | ( |
Victor Costan | e48a2e8 | 2019-03-15 22:02:34 | [diff] [blame] | 647 | 'sqlite3_initialize(', |
Victor Costan | 3653df6 | 2018-02-08 21:38:16 | [diff] [blame] | 648 | ( |
Victor Costan | e48a2e8 | 2019-03-15 22:02:34 | [diff] [blame] | 649 | 'Instead of calling sqlite3_initialize(), depend on //sql, ', |
Victor Costan | 3653df6 | 2018-02-08 21:38:16 | [diff] [blame] | 650 | '#include "sql/initialize.h" and use sql::EnsureSqliteInitialized().', |
| 651 | ), |
| 652 | True, |
| 653 | ( |
| 654 | r'^sql/initialization\.(cc|h)$', |
| 655 | r'^third_party/sqlite/.*\.(c|cc|h)$', |
| 656 | ), |
| 657 | ), |
Matt Menke | 7f520a8 | 2018-03-28 21:38:37 | [diff] [blame] | 658 | ( |
| 659 | 'net::URLFetcher', |
| 660 | ( |
| 661 | 'net::URLFetcher should no longer be used in content embedders. ', |
| 662 | 'Instead, use network::SimpleURLLoader instead, which supports ', |
| 663 | 'an out-of-process network stack. ', |
| 664 | 'net::URLFetcher may still be used in binaries that do not embed', |
| 665 | 'content.', |
| 666 | ), |
Matt Menke | 59716d0 | 2018-04-05 12:45:53 | [diff] [blame] | 667 | False, |
Matt Menke | 7f520a8 | 2018-03-28 21:38:37 | [diff] [blame] | 668 | ( |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 669 | r'^ios[\\/].*\.(cc|h)$', |
| 670 | r'.*[\\/]ios[\\/].*\.(cc|h)$', |
Matt Menke | 7f520a8 | 2018-03-28 21:38:37 | [diff] [blame] | 671 | r'.*_ios\.(cc|h)$', |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 672 | r'^net[\\/].*\.(cc|h)$', |
| 673 | r'.*[\\/]tools[\\/].*\.(cc|h)$', |
Matt Menke | 7f520a8 | 2018-03-28 21:38:37 | [diff] [blame] | 674 | ), |
| 675 | ), |
jdoerrie | d7d10ab | 2018-04-27 10:46:13 | [diff] [blame] | 676 | ( |
tzik | 5de2157f | 2018-05-08 03:42:47 | [diff] [blame] | 677 | r'std::random_shuffle', |
| 678 | ( |
| 679 | 'std::random_shuffle is deprecated in C++14, and removed in C++17. Use', |
| 680 | 'base::RandomShuffle instead.' |
| 681 | ), |
| 682 | True, |
| 683 | (), |
| 684 | ), |
Javier Ernesto Flores Robles | 749e6c2 | 2018-10-08 09:36:24 | [diff] [blame] | 685 | ( |
| 686 | 'ios/web/public/test/http_server', |
| 687 | ( |
| 688 | 'web::HTTPserver is deprecated use net::EmbeddedTestServer instead.', |
| 689 | ), |
| 690 | False, |
| 691 | (), |
| 692 | ), |
Robert Liao | 764c949 | 2019-01-24 18:46:28 | [diff] [blame] | 693 | ( |
| 694 | 'GetAddressOf', |
| 695 | ( |
| 696 | 'Improper use of Microsoft::WRL::ComPtr<T>::GetAddressOf() has been ', |
| 697 | 'implicated in a few leaks. Use operator& instead.' |
| 698 | ), |
| 699 | True, |
| 700 | (), |
| 701 | ), |
Antonio Gomes | 07300d0 | 2019-03-13 20:59:57 | [diff] [blame] | 702 | ( |
| 703 | 'DEFINE_TYPE_CASTS', |
| 704 | ( |
| 705 | 'DEFINE_TYPE_CASTS is deprecated. Instead, use downcast helpers from ', |
| 706 | '//third_party/blink/renderer/platform/casting.h.' |
| 707 | ), |
| 708 | True, |
| 709 | ( |
| 710 | r'^third_party/blink/renderer/.*\.(cc|h)$', |
| 711 | ), |
| 712 | ), |
Carlos Knippschild | ab192b8c | 2019-04-08 20:02:38 | [diff] [blame] | 713 | ( |
| 714 | 'mojo::DataPipe', |
| 715 | ( |
| 716 | 'mojo::DataPipe is deprecated. Use mojo::CreateDataPipe instead.', |
| 717 | ), |
| 718 | True, |
| 719 | (), |
| 720 | ), |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 721 | ) |
| 722 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 723 | |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 724 | _IPC_ENUM_TRAITS_DEPRECATED = ( |
| 725 | '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] | 726 | 'See http://www.chromium.org/Home/chromium-security/education/' |
| 727 | 'security-tips-for-ipc') |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 728 | |
Stephen Martinis | 97a39414 | 2018-06-07 23:06:05 | [diff] [blame] | 729 | _LONG_PATH_ERROR = ( |
| 730 | 'Some files included in this CL have file names that are too long (> 200' |
| 731 | ' characters). If committed, these files will cause issues on Windows. See' |
| 732 | ' https://crbug.com/612667 for more details.' |
| 733 | ) |
| 734 | |
Shenghua Zhang | bfaa38b8 | 2017-11-16 21:58:02 | [diff] [blame] | 735 | _JAVA_MULTIPLE_DEFINITION_EXCLUDED_PATHS = [ |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 736 | r".*[\\/]BuildHooksAndroidImpl\.java", |
| 737 | r".*[\\/]LicenseContentProvider\.java", |
| 738 | r".*[\\/]PlatformServiceBridgeImpl.java", |
Patrick Noland | 5475bc0d | 2018-10-01 20:04:28 | [diff] [blame] | 739 | r".*chrome[\\\/]android[\\\/]feed[\\\/]dummy[\\\/].*\.java", |
Shenghua Zhang | bfaa38b8 | 2017-11-16 21:58:02 | [diff] [blame] | 740 | ] |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 741 | |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 742 | # These paths contain test data and other known invalid JSON files. |
| 743 | _KNOWN_INVALID_JSON_FILE_PATTERNS = [ |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 744 | r'test[\\/]data[\\/]', |
| 745 | r'^components[\\/]policy[\\/]resources[\\/]policy_templates\.json$', |
| 746 | r'^third_party[\\/]protobuf[\\/]', |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 747 | r'^third_party[\\/]blink[\\/]renderer[\\/]devtools[\\/]protocol\.json$', |
Kent Tamura | 77578cc | 2018-11-25 22:33:43 | [diff] [blame] | 748 | r'^third_party[\\/]blink[\\/]web_tests[\\/]external[\\/]wpt[\\/]', |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 749 | ] |
| 750 | |
| 751 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 752 | _VALID_OS_MACROS = ( |
| 753 | # Please keep sorted. |
rayb | 0088ee5 | 2017-04-26 22:35:08 | [diff] [blame] | 754 | 'OS_AIX', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 755 | 'OS_ANDROID', |
Henrique Nakashima | afff050 | 2018-01-24 17:14:12 | [diff] [blame] | 756 | 'OS_ASMJS', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 757 | 'OS_BSD', |
| 758 | 'OS_CAT', # For testing. |
| 759 | 'OS_CHROMEOS', |
Eugene Kliuchnikov | b99125c | 2018-11-26 17:33:04 | [diff] [blame] | 760 | 'OS_CYGWIN', # third_party code. |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 761 | 'OS_FREEBSD', |
scottmg | 2f97ee12 | 2017-05-12 17:50:37 | [diff] [blame] | 762 | 'OS_FUCHSIA', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 763 | 'OS_IOS', |
| 764 | 'OS_LINUX', |
| 765 | 'OS_MACOSX', |
| 766 | 'OS_NACL', |
hidehiko | f7295f2 | 2014-10-28 11:57:21 | [diff] [blame] | 767 | 'OS_NACL_NONSFI', |
| 768 | 'OS_NACL_SFI', |
krytarowski | 969759f | 2016-07-31 23:55:12 | [diff] [blame] | 769 | 'OS_NETBSD', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 770 | 'OS_OPENBSD', |
| 771 | 'OS_POSIX', |
[email protected] | eda7afa1 | 2014-02-06 12:27:37 | [diff] [blame] | 772 | 'OS_QNX', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 773 | 'OS_SOLARIS', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 774 | 'OS_WIN', |
| 775 | ) |
| 776 | |
| 777 | |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 778 | _ANDROID_SPECIFIC_PYDEPS_FILES = [ |
Andrew Luo | b2e4b34 | 2018-09-20 19:32:39 | [diff] [blame] | 779 | 'android_webview/tools/run_cts.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 780 | 'base/android/jni_generator/jni_generator.pydeps', |
| 781 | 'base/android/jni_generator/jni_registration_generator.pydeps', |
Egor Pasko | 56273b5 | 2019-03-14 14:45:22 | [diff] [blame] | 782 | 'build/android/devil_chromium.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 783 | 'build/android/gyp/aar.pydeps', |
| 784 | 'build/android/gyp/aidl.pydeps', |
| 785 | 'build/android/gyp/apkbuilder.pydeps', |
Andrew Grieve | a417ad30 | 2019-02-06 19:54:38 | [diff] [blame] | 786 | 'build/android/gyp/assert_static_initializers.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 787 | 'build/android/gyp/bytecode_processor.pydeps', |
| 788 | 'build/android/gyp/compile_resources.pydeps', |
Andrew Grieve | f89e926c | 2019-02-07 18:36:57 | [diff] [blame] | 789 | 'build/android/gyp/create_app_bundle_minimal_apks.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 790 | 'build/android/gyp/create_bundle_wrapper_script.pydeps', |
| 791 | 'build/android/gyp/copy_ex.pydeps', |
| 792 | 'build/android/gyp/create_app_bundle.pydeps', |
| 793 | 'build/android/gyp/create_apk_operations_script.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 794 | 'build/android/gyp/create_java_binary_script.pydeps', |
Andrew Grieve | b838d83 | 2019-02-11 16:55:22 | [diff] [blame] | 795 | 'build/android/gyp/create_size_info_files.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 796 | 'build/android/gyp/create_stack_script.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 797 | 'build/android/gyp/create_tool_wrapper.pydeps', |
| 798 | 'build/android/gyp/desugar.pydeps', |
Sam Maier | 3599daa | 2018-11-26 18:02:59 | [diff] [blame] | 799 | 'build/android/gyp/dexsplitter.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 800 | 'build/android/gyp/dex.pydeps', |
| 801 | 'build/android/gyp/dist_aar.pydeps', |
| 802 | 'build/android/gyp/emma_instr.pydeps', |
| 803 | 'build/android/gyp/filter_zip.pydeps', |
| 804 | 'build/android/gyp/gcc_preprocess.pydeps', |
Christopher Grant | 99e0e2006 | 2018-11-21 21:22:36 | [diff] [blame] | 805 | 'build/android/gyp/generate_linker_version_script.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 806 | 'build/android/gyp/ijar.pydeps', |
| 807 | 'build/android/gyp/java_cpp_enum.pydeps', |
Ian Vollick | b99472e | 2019-03-07 21:35:26 | [diff] [blame] | 808 | 'build/android/gyp/java_cpp_strings.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 809 | 'build/android/gyp/javac.pydeps', |
| 810 | 'build/android/gyp/jinja_template.pydeps', |
| 811 | 'build/android/gyp/lint.pydeps', |
| 812 | 'build/android/gyp/main_dex_list.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 813 | 'build/android/gyp/merge_manifest.pydeps', |
| 814 | 'build/android/gyp/prepare_resources.pydeps', |
| 815 | 'build/android/gyp/proguard.pydeps', |
| 816 | 'build/android/gyp/write_build_config.pydeps', |
| 817 | 'build/android/gyp/write_ordered_libraries.pydeps', |
Andrew Grieve | 9ff1779 | 2018-11-30 04:55:56 | [diff] [blame] | 818 | 'build/android/gyp/zip.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 819 | 'build/android/incremental_install/generate_android_manifest.pydeps', |
| 820 | 'build/android/incremental_install/write_installer_json.pydeps', |
Andrew Grieve | a7f1ee90 | 2018-05-18 16:17:22 | [diff] [blame] | 821 | 'build/android/resource_sizes.pydeps', |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 822 | 'build/android/test_runner.pydeps', |
hzl | 9b15df5 | 2017-03-23 23:43:04 | [diff] [blame] | 823 | 'build/android/test_wrapper/logdog_wrapper.pydeps', |
David 'Digit' Turner | 0006f473 | 2018-08-07 07:12:36 | [diff] [blame] | 824 | 'build/protoc_java.pydeps', |
agrieve | 732db3a | 2016-04-26 19:18:19 | [diff] [blame] | 825 | 'net/tools/testserver/testserver.pydeps', |
Peter Wen | 22bc3ec | 2019-03-28 22:18:02 | [diff] [blame] | 826 | 'third_party/android_platform/development/scripts/stack.pydeps', |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 827 | ] |
| 828 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 829 | |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 830 | _GENERIC_PYDEPS_FILES = [ |
John Chen | cde8919 | 2018-01-27 21:18:40 | [diff] [blame] | 831 | 'chrome/test/chromedriver/test/run_py_tests.pydeps', |
Cole Winstanley | 7045a1b | 2018-08-27 23:37:29 | [diff] [blame] | 832 | 'chrome/test/chromedriver/log_replay/client_replay_unittest.pydeps', |
Andrew Grieve | a7f1ee90 | 2018-05-18 16:17:22 | [diff] [blame] | 833 | 'tools/binary_size/supersize.pydeps', |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 834 | ] |
| 835 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 836 | |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 837 | _ALL_PYDEPS_FILES = _ANDROID_SPECIFIC_PYDEPS_FILES + _GENERIC_PYDEPS_FILES |
| 838 | |
| 839 | |
Eric Boren | 6fd2b93 | 2018-01-25 15:05:08 | [diff] [blame] | 840 | # Bypass the AUTHORS check for these accounts. |
| 841 | _KNOWN_ROBOTS = set( |
Chan | 52654f5 | 2018-03-21 21:02:29 | [diff] [blame] | 842 | '%s-chromium-autoroll@skia-buildbots.google.com.iam.gserviceaccount.com' % s |
| 843 | for s in ('afdo', 'angle', 'catapult', 'chromite', 'depot-tools', |
Eric Boren | 36af476a | 2018-06-08 16:21:08 | [diff] [blame] | 844 | 'fuchsia-sdk', 'nacl', 'pdfium', 'perfetto', 'skia', |
Eric Boren | 57cc805b | 2018-08-20 17:28:32 | [diff] [blame] | 845 | 'spirv', 'src-internal', 'webrtc') |
Sergiy Byelozyorov | 47158a5 | 2018-06-13 22:38:59 | [diff] [blame] | 846 | ) | set('%[email protected]' % s for s in ('findit-for-me',) |
Achuith Bhandarkar | 3590556 | 2018-07-25 19:28:45 | [diff] [blame] | 847 | ) | set('%[email protected]' % s for s in ('3su6n15k.default',) |
Sergiy Byelozyorov | 47158a5 | 2018-06-13 22:38:59 | [diff] [blame] | 848 | ) | set('%[email protected]' % s |
Robert Ma | 7f02417 | 2018-11-01 20:59:22 | [diff] [blame] | 849 | for s in ('v8-ci-autoroll-builder', 'wpt-autoroller',) |
Eric Boren | 835d71f | 2018-09-07 21:09:04 | [diff] [blame] | 850 | ) | set('%[email protected]' % s |
| 851 | for s in ('chromium-autoroll',) |
| 852 | ) | set('%[email protected]' % s |
Eric Boren | 2b7e3c3c | 2018-09-13 18:14:30 | [diff] [blame] | 853 | for s in ('chromium-internal-autoroll',)) |
Eric Boren | 6fd2b93 | 2018-01-25 15:05:08 | [diff] [blame] | 854 | |
| 855 | |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 856 | def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): |
| 857 | """Attempts to prevent use of functions intended only for testing in |
| 858 | non-testing code. For now this is just a best-effort implementation |
| 859 | that ignores header files and may have some false positives. A |
| 860 | better implementation would probably need a proper C++ parser. |
| 861 | """ |
| 862 | # We only scan .cc files and the like, as the declaration of |
| 863 | # for-testing functions in header files are hard to distinguish from |
| 864 | # calls to such functions without a proper C++ parser. |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 865 | file_inclusion_pattern = [r'.+%s' % _IMPLEMENTATION_EXTENSIONS] |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 866 | |
jochen | c0d4808c | 2015-07-27 09:25:42 | [diff] [blame] | 867 | base_function_pattern = r'[ :]test::[^\s]+|ForTest(s|ing)?|for_test(s|ing)?' |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 868 | inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern) |
[email protected] | 2350182 | 2014-05-14 02:06:09 | [diff] [blame] | 869 | comment_pattern = input_api.re.compile(r'//.*(%s)' % base_function_pattern) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 870 | exclusion_pattern = input_api.re.compile( |
| 871 | r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % ( |
| 872 | base_function_pattern, base_function_pattern)) |
| 873 | |
| 874 | def FilterFile(affected_file): |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 875 | black_list = (_EXCLUDED_PATHS + |
| 876 | _TEST_CODE_EXCLUDED_PATHS + |
| 877 | input_api.DEFAULT_BLACK_LIST) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 878 | return input_api.FilterSourceFile( |
| 879 | affected_file, |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 880 | white_list=file_inclusion_pattern, |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 881 | black_list=black_list) |
| 882 | |
| 883 | problems = [] |
| 884 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 885 | local_path = f.LocalPath() |
[email protected] | 825d2718 | 2014-01-02 21:24:24 | [diff] [blame] | 886 | for line_number, line in f.ChangedContents(): |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 887 | if (inclusion_pattern.search(line) and |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 888 | not comment_pattern.search(line) and |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 889 | not exclusion_pattern.search(line)): |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 890 | problems.append( |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 891 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 892 | |
| 893 | if problems: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 894 | return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 895 | else: |
| 896 | return [] |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 897 | |
| 898 | |
Vaclav Brozek | 7dbc28c | 2018-03-27 08:35:23 | [diff] [blame] | 899 | def _CheckNoProductionCodeUsingTestOnlyFunctionsJava(input_api, output_api): |
| 900 | """This is a simplified version of |
| 901 | _CheckNoProductionCodeUsingTestOnlyFunctions for Java files. |
| 902 | """ |
| 903 | javadoc_start_re = input_api.re.compile(r'^\s*/\*\*') |
| 904 | javadoc_end_re = input_api.re.compile(r'^\s*\*/') |
| 905 | name_pattern = r'ForTest(s|ing)?' |
| 906 | # Describes an occurrence of "ForTest*" inside a // comment. |
| 907 | comment_re = input_api.re.compile(r'//.*%s' % name_pattern) |
| 908 | # Catch calls. |
| 909 | inclusion_re = input_api.re.compile(r'(%s)\s*\(' % name_pattern) |
| 910 | # Ignore definitions. (Comments are ignored separately.) |
| 911 | exclusion_re = input_api.re.compile(r'(%s)[^;]+\{' % name_pattern) |
| 912 | |
| 913 | problems = [] |
| 914 | sources = lambda x: input_api.FilterSourceFile( |
| 915 | x, |
| 916 | black_list=(('(?i).*test', r'.*\/junit\/') |
| 917 | + input_api.DEFAULT_BLACK_LIST), |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 918 | white_list=[r'.*\.java$'] |
Vaclav Brozek | 7dbc28c | 2018-03-27 08:35:23 | [diff] [blame] | 919 | ) |
| 920 | for f in input_api.AffectedFiles(include_deletes=False, file_filter=sources): |
| 921 | local_path = f.LocalPath() |
| 922 | is_inside_javadoc = False |
| 923 | for line_number, line in f.ChangedContents(): |
| 924 | if is_inside_javadoc and javadoc_end_re.search(line): |
| 925 | is_inside_javadoc = False |
| 926 | if not is_inside_javadoc and javadoc_start_re.search(line): |
| 927 | is_inside_javadoc = True |
| 928 | if is_inside_javadoc: |
| 929 | continue |
| 930 | if (inclusion_re.search(line) and |
| 931 | not comment_re.search(line) and |
| 932 | not exclusion_re.search(line)): |
| 933 | problems.append( |
| 934 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
| 935 | |
| 936 | if problems: |
| 937 | return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)] |
| 938 | else: |
| 939 | return [] |
| 940 | |
| 941 | |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 942 | def _CheckNoIOStreamInHeaders(input_api, output_api): |
| 943 | """Checks to make sure no .h files include <iostream>.""" |
| 944 | files = [] |
| 945 | pattern = input_api.re.compile(r'^#include\s*<iostream>', |
| 946 | input_api.re.MULTILINE) |
| 947 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 948 | if not f.LocalPath().endswith('.h'): |
| 949 | continue |
| 950 | contents = input_api.ReadFile(f) |
| 951 | if pattern.search(contents): |
| 952 | files.append(f) |
| 953 | |
| 954 | if len(files): |
yolandyan | daabc6d | 2016-04-18 18:29:39 | [diff] [blame] | 955 | return [output_api.PresubmitError( |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 956 | 'Do not #include <iostream> in header files, since it inserts static ' |
| 957 | 'initialization into every file including the header. Instead, ' |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 958 | '#include <ostream>. See http://crbug.com/94794', |
| 959 | files) ] |
| 960 | return [] |
| 961 | |
Danil Chapovalov | 3518f36 | 2018-08-11 16:13:43 | [diff] [blame] | 962 | def _CheckNoStrCatRedefines(input_api, output_api): |
| 963 | """Checks no windows headers with StrCat redefined are included directly.""" |
| 964 | files = [] |
| 965 | pattern_deny = input_api.re.compile( |
| 966 | r'^#include\s*[<"](shlwapi|atlbase|propvarutil|sphelper).h[">]', |
| 967 | input_api.re.MULTILINE) |
| 968 | pattern_allow = input_api.re.compile( |
| 969 | r'^#include\s"base/win/windows_defines.inc"', |
| 970 | input_api.re.MULTILINE) |
| 971 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 972 | contents = input_api.ReadFile(f) |
| 973 | if pattern_deny.search(contents) and not pattern_allow.search(contents): |
| 974 | files.append(f.LocalPath()) |
| 975 | |
| 976 | if len(files): |
| 977 | return [output_api.PresubmitError( |
| 978 | 'Do not #include shlwapi.h, atlbase.h, propvarutil.h or sphelper.h ' |
| 979 | 'directly since they pollute code with StrCat macro. Instead, ' |
| 980 | 'include matching header from base/win. See http://crbug.com/856536', |
| 981 | files) ] |
| 982 | return [] |
| 983 | |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 984 | |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 985 | def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api): |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 986 | """Checks to make sure no source files use UNIT_TEST.""" |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 987 | problems = [] |
| 988 | for f in input_api.AffectedFiles(): |
| 989 | if (not f.LocalPath().endswith(('.cc', '.mm'))): |
| 990 | continue |
| 991 | |
| 992 | for line_num, line in f.ChangedContents(): |
[email protected] | 549f86a | 2013-11-19 13:00:04 | [diff] [blame] | 993 | if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 994 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 995 | |
| 996 | if not problems: |
| 997 | return [] |
| 998 | return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + |
| 999 | '\n'.join(problems))] |
| 1000 | |
Dominic Battre | 03353105 | 2018-09-24 15:45:34 | [diff] [blame] | 1001 | def _CheckNoDISABLETypoInTests(input_api, output_api): |
| 1002 | """Checks to prevent attempts to disable tests with DISABLE_ prefix. |
| 1003 | |
| 1004 | This test warns if somebody tries to disable a test with the DISABLE_ prefix |
| 1005 | instead of DISABLED_. To filter false positives, reports are only generated |
| 1006 | if a corresponding MAYBE_ line exists. |
| 1007 | """ |
| 1008 | problems = [] |
| 1009 | |
| 1010 | # The following two patterns are looked for in tandem - is a test labeled |
| 1011 | # as MAYBE_ followed by a DISABLE_ (instead of the correct DISABLED) |
| 1012 | maybe_pattern = input_api.re.compile(r'MAYBE_([a-zA-Z0-9_]+)') |
| 1013 | disable_pattern = input_api.re.compile(r'DISABLE_([a-zA-Z0-9_]+)') |
| 1014 | |
| 1015 | # This is for the case that a test is disabled on all platforms. |
| 1016 | full_disable_pattern = input_api.re.compile( |
| 1017 | r'^\s*TEST[^(]*\([a-zA-Z0-9_]+,\s*DISABLE_[a-zA-Z0-9_]+\)', |
| 1018 | input_api.re.MULTILINE) |
| 1019 | |
Katie D | f13948e | 2018-09-25 07:33:44 | [diff] [blame] | 1020 | for f in input_api.AffectedFiles(False): |
Dominic Battre | 03353105 | 2018-09-24 15:45:34 | [diff] [blame] | 1021 | if not 'test' in f.LocalPath() or not f.LocalPath().endswith('.cc'): |
| 1022 | continue |
| 1023 | |
| 1024 | # Search for MABYE_, DISABLE_ pairs. |
| 1025 | disable_lines = {} # Maps of test name to line number. |
| 1026 | maybe_lines = {} |
| 1027 | for line_num, line in f.ChangedContents(): |
| 1028 | disable_match = disable_pattern.search(line) |
| 1029 | if disable_match: |
| 1030 | disable_lines[disable_match.group(1)] = line_num |
| 1031 | maybe_match = maybe_pattern.search(line) |
| 1032 | if maybe_match: |
| 1033 | maybe_lines[maybe_match.group(1)] = line_num |
| 1034 | |
| 1035 | # Search for DISABLE_ occurrences within a TEST() macro. |
| 1036 | disable_tests = set(disable_lines.keys()) |
| 1037 | maybe_tests = set(maybe_lines.keys()) |
| 1038 | for test in disable_tests.intersection(maybe_tests): |
| 1039 | problems.append(' %s:%d' % (f.LocalPath(), disable_lines[test])) |
| 1040 | |
| 1041 | contents = input_api.ReadFile(f) |
| 1042 | full_disable_match = full_disable_pattern.search(contents) |
| 1043 | if full_disable_match: |
| 1044 | problems.append(' %s' % f.LocalPath()) |
| 1045 | |
| 1046 | if not problems: |
| 1047 | return [] |
| 1048 | return [ |
| 1049 | output_api.PresubmitPromptWarning( |
| 1050 | 'Attempt to disable a test with DISABLE_ instead of DISABLED_?\n' + |
| 1051 | '\n'.join(problems)) |
| 1052 | ] |
| 1053 | |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 1054 | |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 1055 | def _CheckDCHECK_IS_ONHasBraces(input_api, output_api): |
kjellander | aee30663 | 2017-02-22 19:26:57 | [diff] [blame] | 1056 | """Checks to make sure DCHECK_IS_ON() does not skip the parentheses.""" |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 1057 | errors = [] |
| 1058 | pattern = input_api.re.compile(r'DCHECK_IS_ON(?!\(\))', |
| 1059 | input_api.re.MULTILINE) |
| 1060 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 1061 | if (not f.LocalPath().endswith(('.cc', '.mm', '.h'))): |
| 1062 | continue |
| 1063 | for lnum, line in f.ChangedContents(): |
| 1064 | if input_api.re.search(pattern, line): |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 1065 | errors.append(output_api.PresubmitError( |
| 1066 | ('%s:%d: Use of DCHECK_IS_ON() must be written as "#if ' + |
kjellander | aee30663 | 2017-02-22 19:26:57 | [diff] [blame] | 1067 | 'DCHECK_IS_ON()", not forgetting the parentheses.') |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 1068 | % (f.LocalPath(), lnum))) |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 1069 | return errors |
| 1070 | |
| 1071 | |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1072 | def _FindHistogramNameInLine(histogram_name, line): |
| 1073 | """Tries to find a histogram name or prefix in a line.""" |
| 1074 | if not "affected-histogram" in line: |
| 1075 | return histogram_name in line |
| 1076 | # A histogram_suffixes tag type has an affected-histogram name as a prefix of |
| 1077 | # the histogram_name. |
| 1078 | if not '"' in line: |
| 1079 | return False |
| 1080 | histogram_prefix = line.split('\"')[1] |
| 1081 | return histogram_prefix in histogram_name |
| 1082 | |
| 1083 | |
| 1084 | def _CheckUmaHistogramChanges(input_api, output_api): |
| 1085 | """Check that UMA histogram names in touched lines can still be found in other |
| 1086 | lines of the patch or in histograms.xml. Note that this check would not catch |
| 1087 | the reverse: changes in histograms.xml not matched in the code itself.""" |
| 1088 | touched_histograms = [] |
| 1089 | histograms_xml_modifications = [] |
Vaclav Brozek | bdac817c | 2018-03-24 06:30:47 | [diff] [blame] | 1090 | call_pattern_c = r'\bUMA_HISTOGRAM.*\(' |
| 1091 | call_pattern_java = r'\bRecordHistogram\.record[a-zA-Z]+Histogram\(' |
| 1092 | name_pattern = r'"(.*?)"' |
| 1093 | single_line_c_re = input_api.re.compile(call_pattern_c + name_pattern) |
| 1094 | single_line_java_re = input_api.re.compile(call_pattern_java + name_pattern) |
| 1095 | split_line_c_prefix_re = input_api.re.compile(call_pattern_c) |
| 1096 | split_line_java_prefix_re = input_api.re.compile(call_pattern_java) |
| 1097 | split_line_suffix_re = input_api.re.compile(r'^\s*' + name_pattern) |
Vaclav Brozek | 0e730cbd | 2018-03-24 06:18:17 | [diff] [blame] | 1098 | last_line_matched_prefix = False |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1099 | for f in input_api.AffectedFiles(): |
| 1100 | # If histograms.xml itself is modified, keep the modified lines for later. |
| 1101 | if f.LocalPath().endswith(('histograms.xml')): |
| 1102 | histograms_xml_modifications = f.ChangedContents() |
| 1103 | continue |
Vaclav Brozek | bdac817c | 2018-03-24 06:30:47 | [diff] [blame] | 1104 | if f.LocalPath().endswith(('cc', 'mm', 'cpp')): |
| 1105 | single_line_re = single_line_c_re |
| 1106 | split_line_prefix_re = split_line_c_prefix_re |
| 1107 | elif f.LocalPath().endswith(('java')): |
| 1108 | single_line_re = single_line_java_re |
| 1109 | split_line_prefix_re = split_line_java_prefix_re |
| 1110 | else: |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1111 | continue |
| 1112 | for line_num, line in f.ChangedContents(): |
Vaclav Brozek | 0e730cbd | 2018-03-24 06:18:17 | [diff] [blame] | 1113 | if last_line_matched_prefix: |
| 1114 | suffix_found = split_line_suffix_re.search(line) |
| 1115 | if suffix_found : |
| 1116 | touched_histograms.append([suffix_found.group(1), f, line_num]) |
| 1117 | last_line_matched_prefix = False |
| 1118 | continue |
Vaclav Brozek | 8a8e2e20 | 2018-03-23 22:01:06 | [diff] [blame] | 1119 | found = single_line_re.search(line) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1120 | if found: |
| 1121 | touched_histograms.append([found.group(1), f, line_num]) |
Vaclav Brozek | 0e730cbd | 2018-03-24 06:18:17 | [diff] [blame] | 1122 | continue |
| 1123 | last_line_matched_prefix = split_line_prefix_re.search(line) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1124 | |
| 1125 | # Search for the touched histogram names in the local modifications to |
| 1126 | # histograms.xml, and, if not found, on the base histograms.xml file. |
| 1127 | unmatched_histograms = [] |
| 1128 | for histogram_info in touched_histograms: |
| 1129 | histogram_name_found = False |
| 1130 | for line_num, line in histograms_xml_modifications: |
| 1131 | histogram_name_found = _FindHistogramNameInLine(histogram_info[0], line) |
| 1132 | if histogram_name_found: |
| 1133 | break |
| 1134 | if not histogram_name_found: |
| 1135 | unmatched_histograms.append(histogram_info) |
| 1136 | |
eroman | b90c82e7e3 | 2015-04-01 15:13:49 | [diff] [blame] | 1137 | histograms_xml_path = 'tools/metrics/histograms/histograms.xml' |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1138 | problems = [] |
| 1139 | if unmatched_histograms: |
eroman | b90c82e7e3 | 2015-04-01 15:13:49 | [diff] [blame] | 1140 | with open(histograms_xml_path) as histograms_xml: |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1141 | for histogram_name, f, line_num in unmatched_histograms: |
mcasas | 39c1b8b | 2015-02-25 15:33:45 | [diff] [blame] | 1142 | histograms_xml.seek(0) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1143 | histogram_name_found = False |
| 1144 | for line in histograms_xml: |
| 1145 | histogram_name_found = _FindHistogramNameInLine(histogram_name, line) |
| 1146 | if histogram_name_found: |
| 1147 | break |
| 1148 | if not histogram_name_found: |
| 1149 | problems.append(' [%s:%d] %s' % |
| 1150 | (f.LocalPath(), line_num, histogram_name)) |
| 1151 | |
| 1152 | if not problems: |
| 1153 | return [] |
| 1154 | return [output_api.PresubmitPromptWarning('Some UMA_HISTOGRAM lines have ' |
| 1155 | 'been modified and the associated histogram name has no match in either ' |
eroman | b90c82e7e3 | 2015-04-01 15:13:49 | [diff] [blame] | 1156 | '%s or the modifications of it:' % (histograms_xml_path), problems)] |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1157 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1158 | |
yolandyan | daabc6d | 2016-04-18 18:29:39 | [diff] [blame] | 1159 | def _CheckFlakyTestUsage(input_api, output_api): |
| 1160 | """Check that FlakyTest annotation is our own instead of the android one""" |
| 1161 | pattern = input_api.re.compile(r'import android.test.FlakyTest;') |
| 1162 | files = [] |
| 1163 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 1164 | if f.LocalPath().endswith('Test.java'): |
| 1165 | if pattern.search(input_api.ReadFile(f)): |
| 1166 | files.append(f) |
| 1167 | if len(files): |
| 1168 | return [output_api.PresubmitError( |
| 1169 | 'Use org.chromium.base.test.util.FlakyTest instead of ' |
| 1170 | 'android.test.FlakyTest', |
| 1171 | files)] |
| 1172 | return [] |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1173 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1174 | |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1175 | def _CheckNoNewWStrings(input_api, output_api): |
| 1176 | """Checks to make sure we don't introduce use of wstrings.""" |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 1177 | problems = [] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1178 | for f in input_api.AffectedFiles(): |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 1179 | if (not f.LocalPath().endswith(('.cc', '.h')) or |
scottmg | e6f0440 | 2014-11-05 01:59:57 | [diff] [blame] | 1180 | f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or |
pennymac | 84fd669 | 2016-07-13 22:35:34 | [diff] [blame] | 1181 | '/win/' in f.LocalPath() or |
| 1182 | 'chrome_elf' in f.LocalPath() or |
| 1183 | 'install_static' in f.LocalPath()): |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 1184 | continue |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1185 | |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 1186 | allowWString = False |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 1187 | for line_num, line in f.ChangedContents(): |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 1188 | if 'presubmit: allow wstring' in line: |
| 1189 | allowWString = True |
| 1190 | elif not allowWString and 'wstring' in line: |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 1191 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 1192 | allowWString = False |
| 1193 | else: |
| 1194 | allowWString = False |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1195 | |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 1196 | if not problems: |
| 1197 | return [] |
| 1198 | return [output_api.PresubmitPromptWarning('New code should not use wstrings.' |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 1199 | ' If you are calling a cross-platform API that accepts a wstring, ' |
| 1200 | 'fix the API.\n' + |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 1201 | '\n'.join(problems))] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1202 | |
| 1203 | |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 1204 | def _CheckNoDEPSGIT(input_api, output_api): |
| 1205 | """Make sure .DEPS.git is never modified manually.""" |
| 1206 | if any(f.LocalPath().endswith('.DEPS.git') for f in |
| 1207 | input_api.AffectedFiles()): |
| 1208 | return [output_api.PresubmitError( |
| 1209 | 'Never commit changes to .DEPS.git. This file is maintained by an\n' |
| 1210 | 'automated system based on what\'s in DEPS and your changes will be\n' |
| 1211 | 'overwritten.\n' |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 1212 | 'See https://sites.google.com/a/chromium.org/dev/developers/how-tos/' |
| 1213 | 'get-the-code#Rolling_DEPS\n' |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 1214 | 'for more information')] |
| 1215 | return [] |
| 1216 | |
| 1217 | |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 1218 | def _CheckValidHostsInDEPS(input_api, output_api): |
| 1219 | """Checks that DEPS file deps are from allowed_hosts.""" |
| 1220 | # Run only if DEPS file has been modified to annoy fewer bystanders. |
| 1221 | if all(f.LocalPath() != 'DEPS' for f in input_api.AffectedFiles()): |
| 1222 | return [] |
| 1223 | # Outsource work to gclient verify |
| 1224 | try: |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 1225 | input_api.subprocess.check_output(['gclient', 'verify'], |
| 1226 | stderr=input_api.subprocess.STDOUT) |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 1227 | return [] |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 1228 | except input_api.subprocess.CalledProcessError as error: |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 1229 | return [output_api.PresubmitError( |
| 1230 | 'DEPS file must have only git dependencies.', |
| 1231 | long_text=error.output)] |
| 1232 | |
| 1233 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1234 | def _CheckNoBannedFunctions(input_api, output_api): |
| 1235 | """Make sure that banned functions are not used.""" |
| 1236 | warnings = [] |
| 1237 | errors = [] |
| 1238 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1239 | def IsBlacklisted(affected_file, blacklist): |
| 1240 | local_path = affected_file.LocalPath() |
| 1241 | for item in blacklist: |
| 1242 | if input_api.re.match(item, local_path): |
| 1243 | return True |
| 1244 | return False |
| 1245 | |
Sylvain Defresne | a8b73d25 | 2018-02-28 15:45:54 | [diff] [blame] | 1246 | def IsIosObcjFile(affected_file): |
| 1247 | local_path = affected_file.LocalPath() |
| 1248 | if input_api.os_path.splitext(local_path)[-1] not in ('.mm', '.m', '.h'): |
| 1249 | return False |
| 1250 | basename = input_api.os_path.basename(local_path) |
| 1251 | if 'ios' in basename.split('_'): |
| 1252 | return True |
| 1253 | for sep in (input_api.os_path.sep, input_api.os_path.altsep): |
| 1254 | if sep and 'ios' in local_path.split(sep): |
| 1255 | return True |
| 1256 | return False |
| 1257 | |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1258 | def CheckForMatch(affected_file, line_num, line, func_name, message, error): |
| 1259 | matched = False |
| 1260 | if func_name[0:1] == '/': |
| 1261 | regex = func_name[1:] |
| 1262 | if input_api.re.search(regex, line): |
| 1263 | matched = True |
| 1264 | elif func_name in line: |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 1265 | matched = True |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1266 | if matched: |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 1267 | problems = warnings |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1268 | if error: |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 1269 | problems = errors |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1270 | problems.append(' %s:%d:' % (affected_file.LocalPath(), line_num)) |
| 1271 | for message_line in message: |
| 1272 | problems.append(' %s' % message_line) |
| 1273 | |
Eric Stevenson | a9a98097 | 2017-09-23 00:04:41 | [diff] [blame] | 1274 | file_filter = lambda f: f.LocalPath().endswith(('.java')) |
| 1275 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1276 | for line_num, line in f.ChangedContents(): |
| 1277 | for func_name, message, error in _BANNED_JAVA_FUNCTIONS: |
| 1278 | CheckForMatch(f, line_num, line, func_name, message, error) |
| 1279 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1280 | file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) |
| 1281 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1282 | for line_num, line in f.ChangedContents(): |
| 1283 | for func_name, message, error in _BANNED_OBJC_FUNCTIONS: |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1284 | CheckForMatch(f, line_num, line, func_name, message, error) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1285 | |
Sylvain Defresne | a8b73d25 | 2018-02-28 15:45:54 | [diff] [blame] | 1286 | for f in input_api.AffectedFiles(file_filter=IsIosObcjFile): |
| 1287 | for line_num, line in f.ChangedContents(): |
| 1288 | for func_name, message, error in _BANNED_IOS_OBJC_FUNCTIONS: |
| 1289 | CheckForMatch(f, line_num, line, func_name, message, error) |
| 1290 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1291 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h')) |
| 1292 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1293 | for line_num, line in f.ChangedContents(): |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 1294 | for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS: |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 1295 | if IsBlacklisted(f, excluded_paths): |
| 1296 | continue |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 1297 | CheckForMatch(f, line_num, line, func_name, message, error) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1298 | |
| 1299 | result = [] |
| 1300 | if (warnings): |
| 1301 | result.append(output_api.PresubmitPromptWarning( |
| 1302 | 'Banned functions were used.\n' + '\n'.join(warnings))) |
| 1303 | if (errors): |
| 1304 | result.append(output_api.PresubmitError( |
| 1305 | 'Banned functions were used.\n' + '\n'.join(errors))) |
| 1306 | return result |
| 1307 | |
| 1308 | |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 1309 | def _CheckNoPragmaOnce(input_api, output_api): |
| 1310 | """Make sure that banned functions are not used.""" |
| 1311 | files = [] |
| 1312 | pattern = input_api.re.compile(r'^#pragma\s+once', |
| 1313 | input_api.re.MULTILINE) |
| 1314 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 1315 | if not f.LocalPath().endswith('.h'): |
| 1316 | continue |
| 1317 | contents = input_api.ReadFile(f) |
| 1318 | if pattern.search(contents): |
| 1319 | files.append(f) |
| 1320 | |
| 1321 | if files: |
| 1322 | return [output_api.PresubmitError( |
| 1323 | 'Do not use #pragma once in header files.\n' |
| 1324 | 'See http://www.chromium.org/developers/coding-style#TOC-File-headers', |
| 1325 | files)] |
| 1326 | return [] |
| 1327 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1328 | |
[email protected] | e747905 | 2012-09-19 00:26:12 | [diff] [blame] | 1329 | def _CheckNoTrinaryTrueFalse(input_api, output_api): |
| 1330 | """Checks to make sure we don't introduce use of foo ? true : false.""" |
| 1331 | problems = [] |
| 1332 | pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)') |
| 1333 | for f in input_api.AffectedFiles(): |
| 1334 | if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')): |
| 1335 | continue |
| 1336 | |
| 1337 | for line_num, line in f.ChangedContents(): |
| 1338 | if pattern.match(line): |
| 1339 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 1340 | |
| 1341 | if not problems: |
| 1342 | return [] |
| 1343 | return [output_api.PresubmitPromptWarning( |
| 1344 | 'Please consider avoiding the "? true : false" pattern if possible.\n' + |
| 1345 | '\n'.join(problems))] |
| 1346 | |
| 1347 | |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1348 | def _CheckUnwantedDependencies(input_api, output_api): |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1349 | """Runs checkdeps on #include and import statements added in this |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1350 | change. Breaking - rules is an error, breaking ! rules is a |
| 1351 | warning. |
| 1352 | """ |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1353 | import sys |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1354 | # We need to wait until we have an input_api object and use this |
| 1355 | # roundabout construct to import checkdeps because this file is |
| 1356 | # eval-ed and thus doesn't have __file__. |
| 1357 | original_sys_path = sys.path |
| 1358 | try: |
| 1359 | sys.path = sys.path + [input_api.os_path.join( |
[email protected] | 5298cc98 | 2014-05-29 20:53:47 | [diff] [blame] | 1360 | input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1361 | import checkdeps |
| 1362 | from cpp_checker import CppChecker |
Jinsuk Kim | 5a09267 | 2017-10-24 22:42:24 | [diff] [blame] | 1363 | from java_checker import JavaChecker |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1364 | from proto_checker import ProtoChecker |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1365 | from rules import Rule |
| 1366 | finally: |
| 1367 | # Restore sys.path to what it was before. |
| 1368 | sys.path = original_sys_path |
| 1369 | |
| 1370 | added_includes = [] |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1371 | added_imports = [] |
Jinsuk Kim | 5a09267 | 2017-10-24 22:42:24 | [diff] [blame] | 1372 | added_java_imports = [] |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1373 | for f in input_api.AffectedFiles(): |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1374 | if CppChecker.IsCppFile(f.LocalPath()): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 1375 | changed_lines = [line for _, line in f.ChangedContents()] |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 1376 | added_includes.append([f.AbsoluteLocalPath(), changed_lines]) |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1377 | elif ProtoChecker.IsProtoFile(f.LocalPath()): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 1378 | changed_lines = [line for _, line in f.ChangedContents()] |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 1379 | added_imports.append([f.AbsoluteLocalPath(), changed_lines]) |
Jinsuk Kim | 5a09267 | 2017-10-24 22:42:24 | [diff] [blame] | 1380 | elif JavaChecker.IsJavaFile(f.LocalPath()): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 1381 | changed_lines = [line for _, line in f.ChangedContents()] |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 1382 | added_java_imports.append([f.AbsoluteLocalPath(), changed_lines]) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1383 | |
[email protected] | 2638517 | 2013-05-09 23:11:35 | [diff] [blame] | 1384 | deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1385 | |
| 1386 | error_descriptions = [] |
| 1387 | warning_descriptions = [] |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1388 | error_subjects = set() |
| 1389 | warning_subjects = set() |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1390 | for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( |
| 1391 | added_includes): |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 1392 | path = input_api.os_path.relpath(path, input_api.PresubmitLocalPath()) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1393 | description_with_path = '%s\n %s' % (path, rule_description) |
| 1394 | if rule_type == Rule.DISALLOW: |
| 1395 | error_descriptions.append(description_with_path) |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1396 | error_subjects.add("#includes") |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1397 | else: |
| 1398 | warning_descriptions.append(description_with_path) |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1399 | warning_subjects.add("#includes") |
| 1400 | |
| 1401 | for path, rule_type, rule_description in deps_checker.CheckAddedProtoImports( |
| 1402 | added_imports): |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 1403 | path = input_api.os_path.relpath(path, input_api.PresubmitLocalPath()) |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1404 | description_with_path = '%s\n %s' % (path, rule_description) |
| 1405 | if rule_type == Rule.DISALLOW: |
| 1406 | error_descriptions.append(description_with_path) |
| 1407 | error_subjects.add("imports") |
| 1408 | else: |
| 1409 | warning_descriptions.append(description_with_path) |
| 1410 | warning_subjects.add("imports") |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1411 | |
Jinsuk Kim | 5a09267 | 2017-10-24 22:42:24 | [diff] [blame] | 1412 | for path, rule_type, rule_description in deps_checker.CheckAddedJavaImports( |
Shenghua Zhang | bfaa38b8 | 2017-11-16 21:58:02 | [diff] [blame] | 1413 | added_java_imports, _JAVA_MULTIPLE_DEFINITION_EXCLUDED_PATHS): |
Andrew Grieve | 085f29f | 2017-11-02 09:14:08 | [diff] [blame] | 1414 | path = input_api.os_path.relpath(path, input_api.PresubmitLocalPath()) |
Jinsuk Kim | 5a09267 | 2017-10-24 22:42:24 | [diff] [blame] | 1415 | description_with_path = '%s\n %s' % (path, rule_description) |
| 1416 | if rule_type == Rule.DISALLOW: |
| 1417 | error_descriptions.append(description_with_path) |
| 1418 | error_subjects.add("imports") |
| 1419 | else: |
| 1420 | warning_descriptions.append(description_with_path) |
| 1421 | warning_subjects.add("imports") |
| 1422 | |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1423 | results = [] |
| 1424 | if error_descriptions: |
| 1425 | results.append(output_api.PresubmitError( |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1426 | 'You added one or more %s that violate checkdeps rules.' |
| 1427 | % " and ".join(error_subjects), |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1428 | error_descriptions)) |
| 1429 | if warning_descriptions: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 1430 | results.append(output_api.PresubmitPromptOrNotify( |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1431 | 'You added one or more %s of files that are temporarily\n' |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1432 | 'allowed but being removed. Can you avoid introducing the\n' |
rhalavati | 08acd23 | 2017-04-03 07:23:28 | [diff] [blame] | 1433 | '%s? See relevant DEPS file(s) for details and contacts.' % |
| 1434 | (" and ".join(warning_subjects), "/".join(warning_subjects)), |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1435 | warning_descriptions)) |
| 1436 | return results |
| 1437 | |
| 1438 | |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 1439 | def _CheckFilePermissions(input_api, output_api): |
| 1440 | """Check that all files have their permissions properly set.""" |
[email protected] | 79150720 | 2014-02-03 23:19:15 | [diff] [blame] | 1441 | if input_api.platform == 'win32': |
| 1442 | return [] |
raphael.kubo.da.costa | c1d13e60b | 2016-04-01 11:49:29 | [diff] [blame] | 1443 | checkperms_tool = input_api.os_path.join( |
| 1444 | input_api.PresubmitLocalPath(), |
| 1445 | 'tools', 'checkperms', 'checkperms.py') |
| 1446 | args = [input_api.python_executable, checkperms_tool, |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1447 | '--root', input_api.change.RepositoryRoot()] |
Raphael Kubo da Costa | 6ff391d | 2017-11-13 16:43:39 | [diff] [blame] | 1448 | with input_api.CreateTemporaryFile() as file_list: |
| 1449 | for f in input_api.AffectedFiles(): |
| 1450 | # checkperms.py file/directory arguments must be relative to the |
| 1451 | # repository. |
| 1452 | file_list.write(f.LocalPath() + '\n') |
| 1453 | file_list.close() |
| 1454 | args += ['--file-list', file_list.name] |
| 1455 | try: |
| 1456 | input_api.subprocess.check_output(args) |
| 1457 | return [] |
| 1458 | except input_api.subprocess.CalledProcessError as error: |
| 1459 | return [output_api.PresubmitError( |
| 1460 | 'checkperms.py failed:', |
| 1461 | long_text=error.output)] |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 1462 | |
| 1463 | |
robertocn | 832f599 | 2017-01-04 19:01:30 | [diff] [blame] | 1464 | def _CheckTeamTags(input_api, output_api): |
| 1465 | """Checks that OWNERS files have consistent TEAM and COMPONENT tags.""" |
| 1466 | checkteamtags_tool = input_api.os_path.join( |
| 1467 | input_api.PresubmitLocalPath(), |
| 1468 | 'tools', 'checkteamtags', 'checkteamtags.py') |
| 1469 | args = [input_api.python_executable, checkteamtags_tool, |
| 1470 | '--root', input_api.change.RepositoryRoot()] |
robertocn | 5eb8231 | 2017-01-09 20:27:22 | [diff] [blame] | 1471 | files = [f.LocalPath() for f in input_api.AffectedFiles(include_deletes=False) |
robertocn | 832f599 | 2017-01-04 19:01:30 | [diff] [blame] | 1472 | if input_api.os_path.basename(f.AbsoluteLocalPath()).upper() == |
| 1473 | 'OWNERS'] |
| 1474 | try: |
| 1475 | if files: |
| 1476 | input_api.subprocess.check_output(args + files) |
| 1477 | return [] |
| 1478 | except input_api.subprocess.CalledProcessError as error: |
| 1479 | return [output_api.PresubmitError( |
| 1480 | 'checkteamtags.py failed:', |
| 1481 | long_text=error.output)] |
| 1482 | |
| 1483 | |
[email protected] | c8278b3 | 2012-10-30 20:35:49 | [diff] [blame] | 1484 | def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api): |
| 1485 | """Makes sure we don't include ui/aura/window_property.h |
| 1486 | in header files. |
| 1487 | """ |
| 1488 | pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"') |
| 1489 | errors = [] |
| 1490 | for f in input_api.AffectedFiles(): |
| 1491 | if not f.LocalPath().endswith('.h'): |
| 1492 | continue |
| 1493 | for line_num, line in f.ChangedContents(): |
| 1494 | if pattern.match(line): |
| 1495 | errors.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 1496 | |
| 1497 | results = [] |
| 1498 | if errors: |
| 1499 | results.append(output_api.PresubmitError( |
| 1500 | 'Header files should not include ui/aura/window_property.h', errors)) |
| 1501 | return results |
| 1502 | |
| 1503 | |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 1504 | def _CheckForVersionControlConflictsInFile(input_api, f): |
| 1505 | pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$') |
| 1506 | errors = [] |
| 1507 | for line_num, line in f.ChangedContents(): |
Luke Zielinski | 9bc14ac7 | 2019-03-04 19:02:16 | [diff] [blame] | 1508 | if f.LocalPath().endswith(('.md', '.rst', '.txt')): |
dbeam | 95c35a2f | 2015-06-02 01:40:23 | [diff] [blame] | 1509 | # First-level headers in markdown look a lot like version control |
| 1510 | # conflict markers. http://daringfireball.net/projects/markdown/basics |
| 1511 | continue |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 1512 | if pattern.match(line): |
| 1513 | errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) |
| 1514 | return errors |
| 1515 | |
| 1516 | |
| 1517 | def _CheckForVersionControlConflicts(input_api, output_api): |
| 1518 | """Usually this is not intentional and will cause a compile failure.""" |
| 1519 | errors = [] |
| 1520 | for f in input_api.AffectedFiles(): |
| 1521 | errors.extend(_CheckForVersionControlConflictsInFile(input_api, f)) |
| 1522 | |
| 1523 | results = [] |
| 1524 | if errors: |
| 1525 | results.append(output_api.PresubmitError( |
| 1526 | 'Version control conflict markers found, please resolve.', errors)) |
| 1527 | return results |
| 1528 | |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 1529 | |
estade | e17314a0 | 2017-01-12 16:22:16 | [diff] [blame] | 1530 | def _CheckGoogleSupportAnswerUrl(input_api, output_api): |
| 1531 | pattern = input_api.re.compile('support\.google\.com\/chrome.*/answer') |
| 1532 | errors = [] |
| 1533 | for f in input_api.AffectedFiles(): |
| 1534 | for line_num, line in f.ChangedContents(): |
| 1535 | if pattern.search(line): |
| 1536 | errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) |
| 1537 | |
| 1538 | results = [] |
| 1539 | if errors: |
| 1540 | results.append(output_api.PresubmitPromptWarning( |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 1541 | 'Found Google support URL addressed by answer number. Please replace ' |
| 1542 | 'with a p= identifier instead. See crbug.com/679462\n', errors)) |
estade | e17314a0 | 2017-01-12 16:22:16 | [diff] [blame] | 1543 | return results |
| 1544 | |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 1545 | |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1546 | def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api): |
| 1547 | def FilterFile(affected_file): |
| 1548 | """Filter function for use with input_api.AffectedSourceFiles, |
| 1549 | below. This filters out everything except non-test files from |
| 1550 | top-level directories that generally speaking should not hard-code |
| 1551 | service URLs (e.g. src/android_webview/, src/content/ and others). |
| 1552 | """ |
| 1553 | return input_api.FilterSourceFile( |
| 1554 | affected_file, |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1555 | white_list=[r'^(android_webview|base|content|net)[\\/].*'], |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1556 | black_list=(_EXCLUDED_PATHS + |
| 1557 | _TEST_CODE_EXCLUDED_PATHS + |
| 1558 | input_api.DEFAULT_BLACK_LIST)) |
| 1559 | |
reillyi | 3896573 | 2015-11-16 18:27:33 | [diff] [blame] | 1560 | base_pattern = ('"[^"]*(google|googleapis|googlezip|googledrive|appspot)' |
| 1561 | '\.(com|net)[^"]*"') |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 1562 | comment_pattern = input_api.re.compile('//.*%s' % base_pattern) |
| 1563 | pattern = input_api.re.compile(base_pattern) |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1564 | problems = [] # items are (filename, line_number, line) |
| 1565 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 1566 | for line_num, line in f.ChangedContents(): |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 1567 | if not comment_pattern.search(line) and pattern.search(line): |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1568 | problems.append((f.LocalPath(), line_num, line)) |
| 1569 | |
| 1570 | if problems: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 1571 | return [output_api.PresubmitPromptOrNotify( |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1572 | 'Most layers below src/chrome/ should not hardcode service URLs.\n' |
[email protected] | b014977 | 2014-03-27 16:47:58 | [diff] [blame] | 1573 | 'Are you sure this is correct?', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1574 | [' %s:%d: %s' % ( |
| 1575 | problem[0], problem[1], problem[2]) for problem in problems])] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 1576 | else: |
| 1577 | return [] |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1578 | |
| 1579 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1580 | # TODO: add unit tests. |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 1581 | def _CheckNoAbbreviationInPngFileName(input_api, output_api): |
| 1582 | """Makes sure there are no abbreviations in the name of PNG files. |
binji | 0dcdf34 | 2014-12-12 18:32:31 | [diff] [blame] | 1583 | The native_client_sdk directory is excluded because it has auto-generated PNG |
| 1584 | files for documentation. |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 1585 | """ |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 1586 | errors = [] |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1587 | white_list = [r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$'] |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1588 | black_list = [r'^native_client_sdk[\\/]'] |
binji | 0dcdf34 | 2014-12-12 18:32:31 | [diff] [blame] | 1589 | file_filter = lambda f: input_api.FilterSourceFile( |
| 1590 | f, white_list=white_list, black_list=black_list) |
| 1591 | for f in input_api.AffectedFiles(include_deletes=False, |
| 1592 | file_filter=file_filter): |
| 1593 | errors.append(' %s' % f.LocalPath()) |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 1594 | |
| 1595 | results = [] |
| 1596 | if errors: |
| 1597 | results.append(output_api.PresubmitError( |
| 1598 | 'The name of PNG files should not have abbreviations. \n' |
| 1599 | 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n' |
| 1600 | 'Contact [email protected] if you have questions.', errors)) |
| 1601 | return results |
| 1602 | |
| 1603 | |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 1604 | def _ExtractAddRulesFromParsedDeps(parsed_deps): |
| 1605 | """Extract the rules that add dependencies from a parsed DEPS file. |
| 1606 | |
| 1607 | Args: |
| 1608 | parsed_deps: the locals dictionary from evaluating the DEPS file.""" |
| 1609 | add_rules = set() |
| 1610 | add_rules.update([ |
| 1611 | rule[1:] for rule in parsed_deps.get('include_rules', []) |
| 1612 | if rule.startswith('+') or rule.startswith('!') |
| 1613 | ]) |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 1614 | for _, rules in parsed_deps.get('specific_include_rules', |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 1615 | {}).iteritems(): |
| 1616 | add_rules.update([ |
| 1617 | rule[1:] for rule in rules |
| 1618 | if rule.startswith('+') or rule.startswith('!') |
| 1619 | ]) |
| 1620 | return add_rules |
| 1621 | |
| 1622 | |
| 1623 | def _ParseDeps(contents): |
| 1624 | """Simple helper for parsing DEPS files.""" |
| 1625 | # Stubs for handling special syntax in the root DEPS file. |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 1626 | class _VarImpl: |
| 1627 | |
| 1628 | def __init__(self, local_scope): |
| 1629 | self._local_scope = local_scope |
| 1630 | |
| 1631 | def Lookup(self, var_name): |
| 1632 | """Implements the Var syntax.""" |
| 1633 | try: |
| 1634 | return self._local_scope['vars'][var_name] |
| 1635 | except KeyError: |
| 1636 | raise Exception('Var is not defined: %s' % var_name) |
| 1637 | |
| 1638 | local_scope = {} |
| 1639 | global_scope = { |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 1640 | 'Var': _VarImpl(local_scope).Lookup, |
| 1641 | } |
| 1642 | exec contents in global_scope, local_scope |
| 1643 | return local_scope |
| 1644 | |
| 1645 | |
| 1646 | def _CalculateAddedDeps(os_path, old_contents, new_contents): |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 1647 | """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 1648 | a set of DEPS entries that we should look up. |
| 1649 | |
| 1650 | For a directory (rather than a specific filename) we fake a path to |
| 1651 | a specific filename by adding /DEPS. This is chosen as a file that |
| 1652 | will seldom or never be subject to per-file include_rules. |
| 1653 | """ |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 1654 | # We ignore deps entries on auto-generated directories. |
| 1655 | AUTO_GENERATED_DIRS = ['grit', 'jni'] |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 1656 | |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 1657 | old_deps = _ExtractAddRulesFromParsedDeps(_ParseDeps(old_contents)) |
| 1658 | new_deps = _ExtractAddRulesFromParsedDeps(_ParseDeps(new_contents)) |
| 1659 | |
| 1660 | added_deps = new_deps.difference(old_deps) |
| 1661 | |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 1662 | results = set() |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 1663 | for added_dep in added_deps: |
| 1664 | if added_dep.split('/')[0] in AUTO_GENERATED_DIRS: |
| 1665 | continue |
| 1666 | # Assume that a rule that ends in .h is a rule for a specific file. |
| 1667 | if added_dep.endswith('.h'): |
| 1668 | results.add(added_dep) |
| 1669 | else: |
| 1670 | results.add(os_path.join(added_dep, 'DEPS')) |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 1671 | return results |
| 1672 | |
| 1673 | |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1674 | def _CheckAddedDepsHaveTargetApprovals(input_api, output_api): |
| 1675 | """When a dependency prefixed with + is added to a DEPS file, we |
| 1676 | want to make sure that the change is reviewed by an OWNER of the |
| 1677 | target file or directory, to avoid layering violations from being |
| 1678 | introduced. This check verifies that this happens. |
| 1679 | """ |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 1680 | virtual_depended_on_files = set() |
jochen | 53efcdd | 2016-01-29 05:09:24 | [diff] [blame] | 1681 | |
| 1682 | file_filter = lambda f: not input_api.re.match( |
Kent Tamura | 32dbbcb | 2018-11-30 12:28:49 | [diff] [blame] | 1683 | r"^third_party[\\/]blink[\\/].*", f.LocalPath()) |
jochen | 53efcdd | 2016-01-29 05:09:24 | [diff] [blame] | 1684 | for f in input_api.AffectedFiles(include_deletes=False, |
| 1685 | file_filter=file_filter): |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1686 | filename = input_api.os_path.basename(f.LocalPath()) |
| 1687 | if filename == 'DEPS': |
Daniel Cheng | 4dcdb6b | 2017-04-13 08:30:17 | [diff] [blame] | 1688 | virtual_depended_on_files.update(_CalculateAddedDeps( |
| 1689 | input_api.os_path, |
| 1690 | '\n'.join(f.OldContents()), |
| 1691 | '\n'.join(f.NewContents()))) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1692 | |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1693 | if not virtual_depended_on_files: |
| 1694 | return [] |
| 1695 | |
| 1696 | if input_api.is_committing: |
| 1697 | if input_api.tbr: |
| 1698 | return [output_api.PresubmitNotifyResult( |
| 1699 | '--tbr was specified, skipping OWNERS check for DEPS additions')] |
Paweł Hajdan, Jr | be6739ea | 2016-04-28 15:07:27 | [diff] [blame] | 1700 | if input_api.dry_run: |
| 1701 | return [output_api.PresubmitNotifyResult( |
| 1702 | 'This is a dry run, skipping OWNERS check for DEPS additions')] |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1703 | if not input_api.change.issue: |
| 1704 | return [output_api.PresubmitError( |
| 1705 | "DEPS approval by OWNERS check failed: this change has " |
Aaron Gable | 65a99d9 | 2017-10-09 19:17:40 | [diff] [blame] | 1706 | "no change number, so we can't check it for approvals.")] |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1707 | output = output_api.PresubmitError |
| 1708 | else: |
| 1709 | output = output_api.PresubmitNotifyResult |
| 1710 | |
| 1711 | owners_db = input_api.owners_db |
tandrii | ed3b7e1 | 2016-05-12 14:38:50 | [diff] [blame] | 1712 | owner_email, reviewers = ( |
| 1713 | input_api.canned_checks.GetCodereviewOwnerAndReviewers( |
| 1714 | input_api, |
| 1715 | owners_db.email_regexp, |
| 1716 | approval_needed=input_api.is_committing)) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1717 | |
| 1718 | owner_email = owner_email or input_api.change.author_email |
| 1719 | |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 1720 | reviewers_plus_owner = set(reviewers) |
[email protected] | e71c608 | 2013-05-22 02:28:51 | [diff] [blame] | 1721 | if owner_email: |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 1722 | reviewers_plus_owner.add(owner_email) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1723 | missing_files = owners_db.files_not_covered_by(virtual_depended_on_files, |
| 1724 | reviewers_plus_owner) |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 1725 | |
| 1726 | # We strip the /DEPS part that was added by |
| 1727 | # _FilesToCheckForIncomingDeps to fake a path to a file in a |
| 1728 | # directory. |
| 1729 | def StripDeps(path): |
| 1730 | start_deps = path.rfind('/DEPS') |
| 1731 | if start_deps != -1: |
| 1732 | return path[:start_deps] |
| 1733 | else: |
| 1734 | return path |
| 1735 | unapproved_dependencies = ["'+%s'," % StripDeps(path) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1736 | for path in missing_files] |
| 1737 | |
| 1738 | if unapproved_dependencies: |
| 1739 | output_list = [ |
Paweł Hajdan, Jr | ec17f88 | 2016-07-04 14:16:15 | [diff] [blame] | 1740 | output('You need LGTM from owners of depends-on paths in DEPS that were ' |
| 1741 | 'modified in this CL:\n %s' % |
| 1742 | '\n '.join(sorted(unapproved_dependencies)))] |
| 1743 | suggested_owners = owners_db.reviewers_for(missing_files, owner_email) |
| 1744 | output_list.append(output( |
| 1745 | 'Suggested missing target path OWNERS:\n %s' % |
| 1746 | '\n '.join(suggested_owners or []))) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1747 | return output_list |
| 1748 | |
| 1749 | return [] |
| 1750 | |
| 1751 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1752 | # TODO: add unit tests. |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1753 | def _CheckSpamLogging(input_api, output_api): |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1754 | file_inclusion_pattern = [r'.+%s' % _IMPLEMENTATION_EXTENSIONS] |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1755 | black_list = (_EXCLUDED_PATHS + |
| 1756 | _TEST_CODE_EXCLUDED_PATHS + |
| 1757 | input_api.DEFAULT_BLACK_LIST + |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1758 | (r"^base[\\/]logging\.h$", |
| 1759 | r"^base[\\/]logging\.cc$", |
| 1760 | r"^chrome[\\/]app[\\/]chrome_main_delegate\.cc$", |
| 1761 | r"^chrome[\\/]browser[\\/]chrome_browser_main\.cc$", |
| 1762 | r"^chrome[\\/]browser[\\/]ui[\\/]startup[\\/]" |
[email protected] | 4de7526 | 2013-12-18 23:16:12 | [diff] [blame] | 1763 | r"startup_browser_creator\.cc$", |
Nicolas Ouellet-Payeur | 16730ab | 2019-04-09 15:39:18 | [diff] [blame] | 1764 | r"^chrome[\\/]browser[\\/]browser_switcher[\\/]bho[\\/].*", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1765 | r"^chrome[\\/]installer[\\/]setup[\\/].*", |
| 1766 | r"^chrome[\\/]chrome_cleaner[\\/].*", |
| 1767 | r"chrome[\\/]browser[\\/]diagnostics[\\/]" + |
[email protected] | f5b9a3f34 | 2014-08-08 22:06:03 | [diff] [blame] | 1768 | r"diagnostics_writer\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1769 | r"^chrome_elf[\\/]dll_hash[\\/]dll_hash_main\.cc$", |
| 1770 | r"^chromecast[\\/]", |
| 1771 | r"^cloud_print[\\/]", |
| 1772 | r"^components[\\/]browser_watcher[\\/]" |
manzagop | 85e629e | 2017-05-09 22:11:48 | [diff] [blame] | 1773 | r"dump_stability_report_main_win.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1774 | r"^components[\\/]html_viewer[\\/]" |
jochen | 34415e5 | 2015-07-10 08:34:31 | [diff] [blame] | 1775 | r"web_test_delegate_impl\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1776 | r"^components[\\/]zucchini[\\/].*", |
peter | 80739bb | 2015-10-20 11:17:46 | [diff] [blame] | 1777 | # TODO(peter): Remove this exception. https://crbug.com/534537 |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1778 | r"^content[\\/]browser[\\/]notifications[\\/]" |
peter | 80739bb | 2015-10-20 11:17:46 | [diff] [blame] | 1779 | r"notification_event_dispatcher_impl\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1780 | r"^content[\\/]common[\\/]gpu[\\/]client[\\/]" |
[email protected] | 9056e73 | 2014-01-08 06:25:25 | [diff] [blame] | 1781 | r"gl_helper_benchmark\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1782 | r"^courgette[\\/]courgette_minimal_tool\.cc$", |
| 1783 | r"^courgette[\\/]courgette_tool\.cc$", |
| 1784 | r"^extensions[\\/]renderer[\\/]logging_native_handler\.cc$", |
Fabrice de Gans-Riberi | 3fa1c0fa | 2019-02-08 18:55:27 | [diff] [blame] | 1785 | r"^fuchsia[\\/]engine[\\/]browser[\\/]frame_impl.cc$", |
Fabrice de Gans-Riberi | 570201a2 | 2019-01-17 23:32:33 | [diff] [blame] | 1786 | r"^headless[\\/]app[\\/]headless_shell\.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1787 | r"^ipc[\\/]ipc_logging\.cc$", |
| 1788 | r"^native_client_sdk[\\/]", |
| 1789 | r"^remoting[\\/]base[\\/]logging\.h$", |
| 1790 | r"^remoting[\\/]host[\\/].*", |
| 1791 | r"^sandbox[\\/]linux[\\/].*", |
Fabrice de Gans-Riberi | 570201a2 | 2019-01-17 23:32:33 | [diff] [blame] | 1792 | r"^storage[\\/]browser[\\/]fileapi[\\/]" + |
| 1793 | r"dump_file_system.cc$", |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 1794 | r"^tools[\\/]", |
| 1795 | r"^ui[\\/]base[\\/]resource[\\/]data_pack.cc$", |
| 1796 | r"^ui[\\/]aura[\\/]bench[\\/]bench_main\.cc$", |
Fabrice de Gans-Riberi | 570201a2 | 2019-01-17 23:32:33 | [diff] [blame] | 1797 | r"^ui[\\/]ozone[\\/]platform[\\/]cast[\\/]")) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1798 | source_file_filter = lambda x: input_api.FilterSourceFile( |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1799 | x, white_list=file_inclusion_pattern, black_list=black_list) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1800 | |
thomasanderson | 625d393 | 2017-03-29 07:16:58 | [diff] [blame] | 1801 | log_info = set([]) |
| 1802 | printf = set([]) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1803 | |
| 1804 | for f in input_api.AffectedSourceFiles(source_file_filter): |
thomasanderson | 625d393 | 2017-03-29 07:16:58 | [diff] [blame] | 1805 | for _, line in f.ChangedContents(): |
| 1806 | if input_api.re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", line): |
| 1807 | log_info.add(f.LocalPath()) |
| 1808 | elif input_api.re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", line): |
| 1809 | log_info.add(f.LocalPath()) |
[email protected] | 18b466b | 2013-12-02 22:01:37 | [diff] [blame] | 1810 | |
thomasanderson | 625d393 | 2017-03-29 07:16:58 | [diff] [blame] | 1811 | if input_api.re.search(r"\bprintf\(", line): |
| 1812 | printf.add(f.LocalPath()) |
| 1813 | elif input_api.re.search(r"\bfprintf\((stdout|stderr)", line): |
| 1814 | printf.add(f.LocalPath()) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1815 | |
| 1816 | if log_info: |
| 1817 | return [output_api.PresubmitError( |
| 1818 | 'These files spam the console log with LOG(INFO):', |
| 1819 | items=log_info)] |
| 1820 | if printf: |
| 1821 | return [output_api.PresubmitError( |
| 1822 | 'These files spam the console log with printf/fprintf:', |
| 1823 | items=printf)] |
| 1824 | return [] |
| 1825 | |
| 1826 | |
[email protected] | 49aa76a | 2013-12-04 06:59:16 | [diff] [blame] | 1827 | def _CheckForAnonymousVariables(input_api, output_api): |
| 1828 | """These types are all expected to hold locks while in scope and |
| 1829 | so should never be anonymous (which causes them to be immediately |
| 1830 | destroyed).""" |
| 1831 | they_who_must_be_named = [ |
| 1832 | 'base::AutoLock', |
| 1833 | 'base::AutoReset', |
| 1834 | 'base::AutoUnlock', |
| 1835 | 'SkAutoAlphaRestore', |
| 1836 | 'SkAutoBitmapShaderInstall', |
| 1837 | 'SkAutoBlitterChoose', |
| 1838 | 'SkAutoBounderCommit', |
| 1839 | 'SkAutoCallProc', |
| 1840 | 'SkAutoCanvasRestore', |
| 1841 | 'SkAutoCommentBlock', |
| 1842 | 'SkAutoDescriptor', |
| 1843 | 'SkAutoDisableDirectionCheck', |
| 1844 | 'SkAutoDisableOvalCheck', |
| 1845 | 'SkAutoFree', |
| 1846 | 'SkAutoGlyphCache', |
| 1847 | 'SkAutoHDC', |
| 1848 | 'SkAutoLockColors', |
| 1849 | 'SkAutoLockPixels', |
| 1850 | 'SkAutoMalloc', |
| 1851 | 'SkAutoMaskFreeImage', |
| 1852 | 'SkAutoMutexAcquire', |
| 1853 | 'SkAutoPathBoundsUpdate', |
| 1854 | 'SkAutoPDFRelease', |
| 1855 | 'SkAutoRasterClipValidate', |
| 1856 | 'SkAutoRef', |
| 1857 | 'SkAutoTime', |
| 1858 | 'SkAutoTrace', |
| 1859 | 'SkAutoUnref', |
| 1860 | ] |
| 1861 | anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named) |
| 1862 | # bad: base::AutoLock(lock.get()); |
| 1863 | # not bad: base::AutoLock lock(lock.get()); |
| 1864 | bad_pattern = input_api.re.compile(anonymous) |
| 1865 | # good: new base::AutoLock(lock.get()) |
| 1866 | good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous) |
| 1867 | errors = [] |
| 1868 | |
| 1869 | for f in input_api.AffectedFiles(): |
| 1870 | if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')): |
| 1871 | continue |
| 1872 | for linenum, line in f.ChangedContents(): |
| 1873 | if bad_pattern.search(line) and not good_pattern.search(line): |
| 1874 | errors.append('%s:%d' % (f.LocalPath(), linenum)) |
| 1875 | |
| 1876 | if errors: |
| 1877 | return [output_api.PresubmitError( |
| 1878 | 'These lines create anonymous variables that need to be named:', |
| 1879 | items=errors)] |
| 1880 | return [] |
| 1881 | |
| 1882 | |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 1883 | def _CheckUniquePtr(input_api, output_api): |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 1884 | # Returns whether |template_str| is of the form <T, U...> for some types T |
| 1885 | # and U. Assumes that |template_str| is already in the form <...>. |
| 1886 | def HasMoreThanOneArg(template_str): |
| 1887 | # Level of <...> nesting. |
| 1888 | nesting = 0 |
| 1889 | for c in template_str: |
| 1890 | if c == '<': |
| 1891 | nesting += 1 |
| 1892 | elif c == '>': |
| 1893 | nesting -= 1 |
| 1894 | elif c == ',' and nesting == 1: |
| 1895 | return True |
| 1896 | return False |
| 1897 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1898 | file_inclusion_pattern = [r'.+%s' % _IMPLEMENTATION_EXTENSIONS] |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 1899 | sources = lambda affected_file: input_api.FilterSourceFile( |
| 1900 | affected_file, |
| 1901 | black_list=(_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS + |
| 1902 | input_api.DEFAULT_BLACK_LIST), |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 1903 | white_list=file_inclusion_pattern) |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 1904 | |
| 1905 | # Pattern to capture a single "<...>" block of template arguments. It can |
| 1906 | # handle linearly nested blocks, such as "<std::vector<std::set<T>>>", but |
| 1907 | # cannot handle branching structures, such as "<pair<set<T>,set<U>>". The |
| 1908 | # latter would likely require counting that < and > match, which is not |
| 1909 | # expressible in regular languages. Should the need arise, one can introduce |
| 1910 | # limited counting (matching up to a total number of nesting depth), which |
| 1911 | # should cover all practical cases for already a low nesting limit. |
| 1912 | template_arg_pattern = ( |
| 1913 | r'<[^>]*' # Opening block of <. |
| 1914 | r'>([^<]*>)?') # Closing block of >. |
| 1915 | # Prefix expressing that whatever follows is not already inside a <...> |
| 1916 | # block. |
| 1917 | not_inside_template_arg_pattern = r'(^|[^<,\s]\s*)' |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 1918 | null_construct_pattern = input_api.re.compile( |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 1919 | not_inside_template_arg_pattern |
| 1920 | + r'\bstd::unique_ptr' |
| 1921 | + template_arg_pattern |
| 1922 | + r'\(\)') |
| 1923 | |
| 1924 | # Same as template_arg_pattern, but excluding type arrays, e.g., <T[]>. |
| 1925 | template_arg_no_array_pattern = ( |
| 1926 | r'<[^>]*[^]]' # Opening block of <. |
| 1927 | r'>([^(<]*[^]]>)?') # Closing block of >. |
| 1928 | # Prefix saying that what follows is the start of an expression. |
| 1929 | start_of_expr_pattern = r'(=|\breturn|^)\s*' |
| 1930 | # Suffix saying that what follows are call parentheses with a non-empty list |
| 1931 | # of arguments. |
| 1932 | nonempty_arg_list_pattern = r'\(([^)]|$)' |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 1933 | # Put the template argument into a capture group for deeper examination later. |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 1934 | return_construct_pattern = input_api.re.compile( |
| 1935 | start_of_expr_pattern |
| 1936 | + r'std::unique_ptr' |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 1937 | + '(?P<template_arg>' |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 1938 | + template_arg_no_array_pattern |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 1939 | + ')' |
Vaclav Brozek | a54c528b | 2018-04-06 19:23:55 | [diff] [blame] | 1940 | + nonempty_arg_list_pattern) |
| 1941 | |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 1942 | problems_constructor = [] |
| 1943 | problems_nullptr = [] |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 1944 | for f in input_api.AffectedSourceFiles(sources): |
| 1945 | for line_number, line in f.ChangedContents(): |
| 1946 | # Disallow: |
| 1947 | # return std::unique_ptr<T>(foo); |
| 1948 | # bar = std::unique_ptr<T>(foo); |
| 1949 | # But allow: |
| 1950 | # return std::unique_ptr<T[]>(foo); |
| 1951 | # bar = std::unique_ptr<T[]>(foo); |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 1952 | # And also allow cases when the second template argument is present. Those |
| 1953 | # cases cannot be handled by std::make_unique: |
| 1954 | # return std::unique_ptr<T, U>(foo); |
| 1955 | # bar = std::unique_ptr<T, U>(foo); |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 1956 | local_path = f.LocalPath() |
Vaclav Brozek | b7fadb69 | 2018-08-30 06:39:53 | [diff] [blame] | 1957 | return_construct_result = return_construct_pattern.search(line) |
| 1958 | if return_construct_result and not HasMoreThanOneArg( |
| 1959 | return_construct_result.group('template_arg')): |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 1960 | problems_constructor.append( |
| 1961 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 1962 | # Disallow: |
| 1963 | # std::unique_ptr<T>() |
| 1964 | if null_construct_pattern.search(line): |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 1965 | problems_nullptr.append( |
| 1966 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
| 1967 | |
| 1968 | errors = [] |
Vaclav Brozek | c2fecf4 | 2018-04-06 16:40:16 | [diff] [blame] | 1969 | if problems_nullptr: |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 1970 | errors.append(output_api.PresubmitError( |
| 1971 | 'The following files use std::unique_ptr<T>(). Use nullptr instead.', |
Vaclav Brozek | c2fecf4 | 2018-04-06 16:40:16 | [diff] [blame] | 1972 | problems_nullptr)) |
| 1973 | if problems_constructor: |
Vaclav Brozek | 851d960 | 2018-04-04 16:13:05 | [diff] [blame] | 1974 | errors.append(output_api.PresubmitError( |
| 1975 | 'The following files use explicit std::unique_ptr constructor.' |
| 1976 | 'Use std::make_unique<T>() instead.', |
Vaclav Brozek | c2fecf4 | 2018-04-06 16:40:16 | [diff] [blame] | 1977 | problems_constructor)) |
Peter Kasting | 4844e46e | 2018-02-23 07:27:10 | [diff] [blame] | 1978 | return errors |
| 1979 | |
| 1980 | |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1981 | def _CheckUserActionUpdate(input_api, output_api): |
| 1982 | """Checks if any new user action has been added.""" |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1983 | if any('actions.xml' == input_api.os_path.basename(f) for f in |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1984 | input_api.LocalPaths()): |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1985 | # If actions.xml is already included in the changelist, the PRESUBMIT |
| 1986 | # for actions.xml will do a more complete presubmit check. |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1987 | return [] |
| 1988 | |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1989 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm')) |
| 1990 | action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)' |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1991 | current_actions = None |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1992 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1993 | for line_num, line in f.ChangedContents(): |
| 1994 | match = input_api.re.search(action_re, line) |
| 1995 | if match: |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1996 | # Loads contents in tools/metrics/actions/actions.xml to memory. It's |
| 1997 | # loaded only once. |
| 1998 | if not current_actions: |
| 1999 | with open('tools/metrics/actions/actions.xml') as actions_f: |
| 2000 | current_actions = actions_f.read() |
| 2001 | # Search for the matched user action name in |current_actions|. |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2002 | for action_name in match.groups(): |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 2003 | action = 'name="{0}"'.format(action_name) |
| 2004 | if action not in current_actions: |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2005 | return [output_api.PresubmitPromptWarning( |
| 2006 | 'File %s line %d: %s is missing in ' |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 2007 | 'tools/metrics/actions/actions.xml. Please run ' |
| 2008 | 'tools/metrics/actions/extract_actions.py to update.' |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 2009 | % (f.LocalPath(), line_num, action_name))] |
| 2010 | return [] |
| 2011 | |
| 2012 | |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2013 | def _ImportJSONCommentEater(input_api): |
| 2014 | import sys |
| 2015 | sys.path = sys.path + [input_api.os_path.join( |
| 2016 | input_api.PresubmitLocalPath(), |
| 2017 | 'tools', 'json_comment_eater')] |
| 2018 | import json_comment_eater |
| 2019 | return json_comment_eater |
| 2020 | |
| 2021 | |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2022 | def _GetJSONParseError(input_api, filename, eat_comments=True): |
| 2023 | try: |
| 2024 | contents = input_api.ReadFile(filename) |
| 2025 | if eat_comments: |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2026 | json_comment_eater = _ImportJSONCommentEater(input_api) |
plundblad | 1f5a4509f | 2015-07-23 11:31:13 | [diff] [blame] | 2027 | contents = json_comment_eater.Nom(contents) |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2028 | |
| 2029 | input_api.json.loads(contents) |
| 2030 | except ValueError as e: |
| 2031 | return e |
| 2032 | return None |
| 2033 | |
| 2034 | |
| 2035 | def _GetIDLParseError(input_api, filename): |
| 2036 | try: |
| 2037 | contents = input_api.ReadFile(filename) |
| 2038 | idl_schema = input_api.os_path.join( |
| 2039 | input_api.PresubmitLocalPath(), |
| 2040 | 'tools', 'json_schema_compiler', 'idl_schema.py') |
| 2041 | process = input_api.subprocess.Popen( |
| 2042 | [input_api.python_executable, idl_schema], |
| 2043 | stdin=input_api.subprocess.PIPE, |
| 2044 | stdout=input_api.subprocess.PIPE, |
| 2045 | stderr=input_api.subprocess.PIPE, |
| 2046 | universal_newlines=True) |
| 2047 | (_, error) = process.communicate(input=contents) |
| 2048 | return error or None |
| 2049 | except ValueError as e: |
| 2050 | return e |
| 2051 | |
| 2052 | |
| 2053 | def _CheckParseErrors(input_api, output_api): |
| 2054 | """Check that IDL and JSON files do not contain syntax errors.""" |
| 2055 | actions = { |
| 2056 | '.idl': _GetIDLParseError, |
| 2057 | '.json': _GetJSONParseError, |
| 2058 | } |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2059 | # Most JSON files are preprocessed and support comments, but these do not. |
| 2060 | json_no_comments_patterns = [ |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2061 | r'^testing[\\/]', |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2062 | ] |
| 2063 | # Only run IDL checker on files in these directories. |
| 2064 | idl_included_patterns = [ |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2065 | r'^chrome[\\/]common[\\/]extensions[\\/]api[\\/]', |
| 2066 | r'^extensions[\\/]common[\\/]api[\\/]', |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2067 | ] |
| 2068 | |
| 2069 | def get_action(affected_file): |
| 2070 | filename = affected_file.LocalPath() |
| 2071 | return actions.get(input_api.os_path.splitext(filename)[1]) |
| 2072 | |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2073 | def FilterFile(affected_file): |
| 2074 | action = get_action(affected_file) |
| 2075 | if not action: |
| 2076 | return False |
| 2077 | path = affected_file.LocalPath() |
| 2078 | |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 2079 | if _MatchesFile(input_api, _KNOWN_INVALID_JSON_FILE_PATTERNS, path): |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2080 | return False |
| 2081 | |
| 2082 | if (action == _GetIDLParseError and |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 2083 | not _MatchesFile(input_api, idl_included_patterns, path)): |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2084 | return False |
| 2085 | return True |
| 2086 | |
| 2087 | results = [] |
| 2088 | for affected_file in input_api.AffectedFiles( |
| 2089 | file_filter=FilterFile, include_deletes=False): |
| 2090 | action = get_action(affected_file) |
| 2091 | kwargs = {} |
| 2092 | if (action == _GetJSONParseError and |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 2093 | _MatchesFile(input_api, json_no_comments_patterns, |
| 2094 | affected_file.LocalPath())): |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 2095 | kwargs['eat_comments'] = False |
| 2096 | parse_error = action(input_api, |
| 2097 | affected_file.AbsoluteLocalPath(), |
| 2098 | **kwargs) |
| 2099 | if parse_error: |
| 2100 | results.append(output_api.PresubmitError('%s could not be parsed: %s' % |
| 2101 | (affected_file.LocalPath(), parse_error))) |
| 2102 | return results |
| 2103 | |
| 2104 | |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 2105 | def _CheckJavaStyle(input_api, output_api): |
| 2106 | """Runs checkstyle on changed java files and returns errors if any exist.""" |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 2107 | import sys |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 2108 | original_sys_path = sys.path |
| 2109 | try: |
| 2110 | sys.path = sys.path + [input_api.os_path.join( |
| 2111 | input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] |
| 2112 | import checkstyle |
| 2113 | finally: |
| 2114 | # Restore sys.path to what it was before. |
| 2115 | sys.path = original_sys_path |
| 2116 | |
| 2117 | return checkstyle.RunCheckstyle( |
davileen | 72d7653 | 2015-01-20 22:30:09 | [diff] [blame] | 2118 | input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml', |
newt | d8b7d30e9 | 2015-01-23 18:10:51 | [diff] [blame] | 2119 | black_list=_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 2120 | |
| 2121 | |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 2122 | def _MatchesFile(input_api, patterns, path): |
| 2123 | for pattern in patterns: |
| 2124 | if input_api.re.search(pattern, path): |
| 2125 | return True |
| 2126 | return False |
| 2127 | |
| 2128 | |
Daniel Cheng | 7052cdf | 2017-11-21 19:23:29 | [diff] [blame] | 2129 | def _GetOwnersFilesToCheckForIpcOwners(input_api): |
| 2130 | """Gets a list of OWNERS files to check for correct security owners. |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2131 | |
Daniel Cheng | 7052cdf | 2017-11-21 19:23:29 | [diff] [blame] | 2132 | Returns: |
| 2133 | A dictionary mapping an OWNER file to the list of OWNERS rules it must |
| 2134 | contain to cover IPC-related files with noparent reviewer rules. |
| 2135 | """ |
| 2136 | # Whether or not a file affects IPC is (mostly) determined by a simple list |
| 2137 | # of filename patterns. |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2138 | file_patterns = [ |
palmer | b19a093 | 2017-01-24 04:00:31 | [diff] [blame] | 2139 | # Legacy IPC: |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2140 | '*_messages.cc', |
| 2141 | '*_messages*.h', |
| 2142 | '*_param_traits*.*', |
palmer | b19a093 | 2017-01-24 04:00:31 | [diff] [blame] | 2143 | # Mojo IPC: |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2144 | '*.mojom', |
Daniel Cheng | 1f38693 | 2018-01-29 19:56:47 | [diff] [blame] | 2145 | '*_mojom_traits*.*', |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2146 | '*_struct_traits*.*', |
| 2147 | '*_type_converter*.*', |
palmer | b19a093 | 2017-01-24 04:00:31 | [diff] [blame] | 2148 | '*.typemap', |
| 2149 | # Android native IPC: |
| 2150 | '*.aidl', |
| 2151 | # Blink uses a different file naming convention: |
| 2152 | '*EnumTraits*.*', |
Daniel Cheng | e0bf3f6 | 2018-01-30 01:56:47 | [diff] [blame] | 2153 | "*MojomTraits*.*", |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2154 | '*StructTraits*.*', |
| 2155 | '*TypeConverter*.*', |
| 2156 | ] |
| 2157 | |
scottmg | 7a6ed5ba | 2016-11-04 18:22:04 | [diff] [blame] | 2158 | # These third_party directories do not contain IPCs, but contain files |
| 2159 | # matching the above patterns, which trigger false positives. |
| 2160 | exclude_paths = [ |
| 2161 | 'third_party/crashpad/*', |
Andres Medina | e684cf4 | 2018-08-27 18:48:23 | [diff] [blame] | 2162 | 'third_party/protobuf/benchmarks/python/*', |
Daniel Cheng | ebe635e | 2018-07-13 12:36:06 | [diff] [blame] | 2163 | 'third_party/third_party/blink/renderer/platform/bindings/*', |
Nico Weber | ee3dc9b | 2017-08-31 17:09:29 | [diff] [blame] | 2164 | 'third_party/win_build_output/*', |
scottmg | 7a6ed5ba | 2016-11-04 18:22:04 | [diff] [blame] | 2165 | ] |
| 2166 | |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2167 | # Dictionary mapping an OWNERS file path to Patterns. |
| 2168 | # Patterns is a dictionary mapping glob patterns (suitable for use in per-file |
| 2169 | # rules ) to a PatternEntry. |
| 2170 | # PatternEntry is a dictionary with two keys: |
| 2171 | # - 'files': the files that are matched by this pattern |
| 2172 | # - 'rules': the per-file rules needed for this pattern |
| 2173 | # For example, if we expect OWNERS file to contain rules for *.mojom and |
| 2174 | # *_struct_traits*.*, Patterns might look like this: |
| 2175 | # { |
| 2176 | # '*.mojom': { |
| 2177 | # 'files': ..., |
| 2178 | # 'rules': [ |
| 2179 | # 'per-file *.mojom=set noparent', |
| 2180 | # 'per-file *.mojom=file://ipc/SECURITY_OWNERS', |
| 2181 | # ], |
| 2182 | # }, |
| 2183 | # '*_struct_traits*.*': { |
| 2184 | # 'files': ..., |
| 2185 | # 'rules': [ |
| 2186 | # 'per-file *_struct_traits*.*=set noparent', |
| 2187 | # 'per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS', |
| 2188 | # ], |
| 2189 | # }, |
| 2190 | # } |
| 2191 | to_check = {} |
| 2192 | |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2193 | def AddPatternToCheck(input_file, pattern): |
| 2194 | owners_file = input_api.os_path.join( |
| 2195 | input_api.os_path.dirname(input_file.LocalPath()), 'OWNERS') |
| 2196 | if owners_file not in to_check: |
| 2197 | to_check[owners_file] = {} |
| 2198 | if pattern not in to_check[owners_file]: |
| 2199 | to_check[owners_file][pattern] = { |
| 2200 | 'files': [], |
| 2201 | 'rules': [ |
| 2202 | 'per-file %s=set noparent' % pattern, |
| 2203 | 'per-file %s=file://ipc/SECURITY_OWNERS' % pattern, |
| 2204 | ] |
| 2205 | } |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 2206 | to_check[owners_file][pattern]['files'].append(input_file) |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2207 | |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2208 | # Iterate through the affected files to see what we actually need to check |
| 2209 | # for. We should only nag patch authors about per-file rules if a file in that |
| 2210 | # directory would match that pattern. If a directory only contains *.mojom |
| 2211 | # files and no *_messages*.h files, we should only nag about rules for |
| 2212 | # *.mojom files. |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2213 | for f in input_api.AffectedFiles(include_deletes=False): |
| 2214 | # Manifest files don't have a strong naming convention. Instead, scan |
Ken Rockot | 9f66826 | 2018-12-21 18:56:36 | [diff] [blame] | 2215 | # affected files for .json, .cc, and .h files which look like they contain |
| 2216 | # a manifest definition. |
Sean Kau | 46e29bc | 2017-08-28 16:31:16 | [diff] [blame] | 2217 | if (f.LocalPath().endswith('.json') and |
| 2218 | not _MatchesFile(input_api, _KNOWN_INVALID_JSON_FILE_PATTERNS, |
| 2219 | f.LocalPath())): |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2220 | json_comment_eater = _ImportJSONCommentEater(input_api) |
| 2221 | mostly_json_lines = '\n'.join(f.NewContents()) |
| 2222 | # Comments aren't allowed in strict JSON, so filter them out. |
| 2223 | json_lines = json_comment_eater.Nom(mostly_json_lines) |
Daniel Cheng | e8efd09 | 2018-03-23 23:57:43 | [diff] [blame] | 2224 | try: |
| 2225 | json_content = input_api.json.loads(json_lines) |
| 2226 | except: |
| 2227 | # There's another PRESUBMIT check that already verifies that JSON files |
| 2228 | # are not invalid, so no need to emit another warning here. |
| 2229 | continue |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2230 | if 'interface_provider_specs' in json_content: |
| 2231 | AddPatternToCheck(f, input_api.os_path.basename(f.LocalPath())) |
Ken Rockot | 9f66826 | 2018-12-21 18:56:36 | [diff] [blame] | 2232 | else: |
| 2233 | manifest_pattern = input_api.re.compile('manifests?\.(cc|h)$') |
| 2234 | test_manifest_pattern = input_api.re.compile('test_manifests?\.(cc|h)') |
| 2235 | if (manifest_pattern.search(f.LocalPath()) and not |
| 2236 | test_manifest_pattern.search(f.LocalPath())): |
| 2237 | # We expect all actual service manifest files to contain at least one |
| 2238 | # qualified reference to service_manager::Manifest. |
| 2239 | if 'service_manager::Manifest' in '\n'.join(f.NewContents()): |
| 2240 | AddPatternToCheck(f, input_api.os_path.basename(f.LocalPath())) |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2241 | for pattern in file_patterns: |
| 2242 | if input_api.fnmatch.fnmatch( |
| 2243 | input_api.os_path.basename(f.LocalPath()), pattern): |
scottmg | 7a6ed5ba | 2016-11-04 18:22:04 | [diff] [blame] | 2244 | skip = False |
| 2245 | for exclude in exclude_paths: |
| 2246 | if input_api.fnmatch.fnmatch(f.LocalPath(), exclude): |
| 2247 | skip = True |
| 2248 | break |
| 2249 | if skip: |
| 2250 | continue |
Daniel Cheng | 13ca61a88 | 2017-08-25 15:11:25 | [diff] [blame] | 2251 | AddPatternToCheck(f, pattern) |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2252 | break |
| 2253 | |
Daniel Cheng | 7052cdf | 2017-11-21 19:23:29 | [diff] [blame] | 2254 | return to_check |
| 2255 | |
| 2256 | |
| 2257 | def _CheckIpcOwners(input_api, output_api): |
| 2258 | """Checks that affected files involving IPC have an IPC OWNERS rule.""" |
| 2259 | to_check = _GetOwnersFilesToCheckForIpcOwners(input_api) |
| 2260 | |
| 2261 | if to_check: |
| 2262 | # If there are any OWNERS files to check, there are IPC-related changes in |
| 2263 | # this CL. Auto-CC the review list. |
| 2264 | output_api.AppendCC('[email protected]') |
| 2265 | |
| 2266 | # Go through the OWNERS files to check, filtering out rules that are already |
| 2267 | # present in that OWNERS file. |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2268 | for owners_file, patterns in to_check.iteritems(): |
| 2269 | try: |
| 2270 | with file(owners_file) as f: |
| 2271 | lines = set(f.read().splitlines()) |
| 2272 | for entry in patterns.itervalues(): |
| 2273 | entry['rules'] = [rule for rule in entry['rules'] if rule not in lines |
| 2274 | ] |
| 2275 | except IOError: |
| 2276 | # No OWNERS file, so all the rules are definitely missing. |
| 2277 | continue |
| 2278 | |
| 2279 | # All the remaining lines weren't found in OWNERS files, so emit an error. |
| 2280 | errors = [] |
| 2281 | for owners_file, patterns in to_check.iteritems(): |
| 2282 | missing_lines = [] |
| 2283 | files = [] |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 2284 | for _, entry in patterns.iteritems(): |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2285 | missing_lines.extend(entry['rules']) |
| 2286 | files.extend([' %s' % f.LocalPath() for f in entry['files']]) |
| 2287 | if missing_lines: |
| 2288 | errors.append( |
Vaclav Brozek | 1893a97 | 2018-04-25 05:48:05 | [diff] [blame] | 2289 | 'Because of the presence of files:\n%s\n\n' |
| 2290 | '%s needs the following %d lines added:\n\n%s' % |
| 2291 | ('\n'.join(files), owners_file, len(missing_lines), |
| 2292 | '\n'.join(missing_lines))) |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2293 | |
| 2294 | results = [] |
| 2295 | if errors: |
vabr | f5ce3bf9 | 2016-07-11 14:52:41 | [diff] [blame] | 2296 | if input_api.is_committing: |
| 2297 | output = output_api.PresubmitError |
| 2298 | else: |
| 2299 | output = output_api.PresubmitPromptWarning |
| 2300 | results.append(output( |
Daniel Cheng | 5211169 | 2017-06-14 08:00:59 | [diff] [blame] | 2301 | 'Found OWNERS files that need to be updated for IPC security ' + |
| 2302 | 'review coverage.\nPlease update the OWNERS files below:', |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 2303 | long_text='\n\n'.join(errors))) |
| 2304 | |
| 2305 | return results |
| 2306 | |
| 2307 | |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 2308 | def _CheckUselessForwardDeclarations(input_api, output_api): |
jbriance | 2c51e821a | 2016-12-12 08:24:31 | [diff] [blame] | 2309 | """Checks that added or removed lines in non third party affected |
| 2310 | header files do not lead to new useless class or struct forward |
| 2311 | declaration. |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 2312 | """ |
| 2313 | results = [] |
| 2314 | class_pattern = input_api.re.compile(r'^class\s+(\w+);$', |
| 2315 | input_api.re.MULTILINE) |
| 2316 | struct_pattern = input_api.re.compile(r'^struct\s+(\w+);$', |
| 2317 | input_api.re.MULTILINE) |
| 2318 | for f in input_api.AffectedFiles(include_deletes=False): |
jbriance | 2c51e821a | 2016-12-12 08:24:31 | [diff] [blame] | 2319 | if (f.LocalPath().startswith('third_party') and |
Kent Tamura | e9b3a9ec | 2017-08-31 02:20:19 | [diff] [blame] | 2320 | not f.LocalPath().startswith('third_party/blink') and |
Kent Tamura | 32dbbcb | 2018-11-30 12:28:49 | [diff] [blame] | 2321 | not f.LocalPath().startswith('third_party\\blink')): |
jbriance | 2c51e821a | 2016-12-12 08:24:31 | [diff] [blame] | 2322 | continue |
| 2323 | |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 2324 | if not f.LocalPath().endswith('.h'): |
| 2325 | continue |
| 2326 | |
| 2327 | contents = input_api.ReadFile(f) |
| 2328 | fwd_decls = input_api.re.findall(class_pattern, contents) |
| 2329 | fwd_decls.extend(input_api.re.findall(struct_pattern, contents)) |
| 2330 | |
| 2331 | useless_fwd_decls = [] |
| 2332 | for decl in fwd_decls: |
| 2333 | count = sum(1 for _ in input_api.re.finditer( |
| 2334 | r'\b%s\b' % input_api.re.escape(decl), contents)) |
| 2335 | if count == 1: |
| 2336 | useless_fwd_decls.append(decl) |
| 2337 | |
| 2338 | if not useless_fwd_decls: |
| 2339 | continue |
| 2340 | |
| 2341 | for line in f.GenerateScmDiff().splitlines(): |
| 2342 | if (line.startswith('-') and not line.startswith('--') or |
| 2343 | line.startswith('+') and not line.startswith('++')): |
| 2344 | for decl in useless_fwd_decls: |
| 2345 | if input_api.re.search(r'\b%s\b' % decl, line[1:]): |
| 2346 | results.append(output_api.PresubmitPromptWarning( |
ricea | 6416dea | 2017-05-19 12:39:24 | [diff] [blame] | 2347 | '%s: %s forward declaration is no longer needed' % |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 2348 | (f.LocalPath(), decl))) |
| 2349 | useless_fwd_decls.remove(decl) |
| 2350 | |
| 2351 | return results |
| 2352 | |
| 2353 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2354 | # TODO: add unit tests |
dskiba | 88634f4e | 2015-08-14 23:03:29 | [diff] [blame] | 2355 | def _CheckAndroidToastUsage(input_api, output_api): |
| 2356 | """Checks that code uses org.chromium.ui.widget.Toast instead of |
| 2357 | android.widget.Toast (Chromium Toast doesn't force hardware |
| 2358 | acceleration on low-end devices, saving memory). |
| 2359 | """ |
| 2360 | toast_import_pattern = input_api.re.compile( |
| 2361 | r'^import android\.widget\.Toast;$') |
| 2362 | |
| 2363 | errors = [] |
| 2364 | |
| 2365 | sources = lambda affected_file: input_api.FilterSourceFile( |
| 2366 | affected_file, |
| 2367 | black_list=(_EXCLUDED_PATHS + |
| 2368 | _TEST_CODE_EXCLUDED_PATHS + |
| 2369 | input_api.DEFAULT_BLACK_LIST + |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2370 | (r'^chromecast[\\/].*', |
| 2371 | r'^remoting[\\/].*')), |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2372 | white_list=[r'.*\.java$']) |
dskiba | 88634f4e | 2015-08-14 23:03:29 | [diff] [blame] | 2373 | |
| 2374 | for f in input_api.AffectedSourceFiles(sources): |
| 2375 | for line_num, line in f.ChangedContents(): |
| 2376 | if toast_import_pattern.search(line): |
| 2377 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 2378 | |
| 2379 | results = [] |
| 2380 | |
| 2381 | if errors: |
| 2382 | results.append(output_api.PresubmitError( |
| 2383 | 'android.widget.Toast usage is detected. Android toasts use hardware' |
| 2384 | ' acceleration, and can be\ncostly on low-end devices. Please use' |
| 2385 | ' org.chromium.ui.widget.Toast instead.\n' |
| 2386 | 'Contact [email protected] if you have any questions.', |
| 2387 | errors)) |
| 2388 | |
| 2389 | return results |
| 2390 | |
| 2391 | |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2392 | def _CheckAndroidCrLogUsage(input_api, output_api): |
| 2393 | """Checks that new logs using org.chromium.base.Log: |
| 2394 | - Are using 'TAG' as variable name for the tags (warn) |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 2395 | - Are using a tag that is shorter than 20 characters (error) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2396 | """ |
pkotwicz | a1dd0b00 | 2016-05-16 14:41:04 | [diff] [blame] | 2397 | |
torne | 8954062 | 2017-03-24 19:41:30 | [diff] [blame] | 2398 | # Do not check format of logs in the given files |
pkotwicz | a1dd0b00 | 2016-05-16 14:41:04 | [diff] [blame] | 2399 | cr_log_check_excluded_paths = [ |
torne | 8954062 | 2017-03-24 19:41:30 | [diff] [blame] | 2400 | # //chrome/android/webapk cannot depend on //base |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2401 | r"^chrome[\\/]android[\\/]webapk[\\/].*", |
torne | 8954062 | 2017-03-24 19:41:30 | [diff] [blame] | 2402 | # WebView license viewer code cannot depend on //base; used in stub APK. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2403 | r"^android_webview[\\/]glue[\\/]java[\\/]src[\\/]com[\\/]android[\\/]" |
| 2404 | r"webview[\\/]chromium[\\/]License.*", |
Egor Pasko | a5c05b0 | 2018-09-28 16:04:09 | [diff] [blame] | 2405 | # The customtabs_benchmark is a small app that does not depend on Chromium |
| 2406 | # java pieces. |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2407 | r"tools[\\/]android[\\/]customtabs_benchmark[\\/].*", |
pkotwicz | a1dd0b00 | 2016-05-16 14:41:04 | [diff] [blame] | 2408 | ] |
| 2409 | |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2410 | cr_log_import_pattern = input_api.re.compile( |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2411 | r'^import org\.chromium\.base\.Log;$', input_api.re.MULTILINE) |
| 2412 | class_in_base_pattern = input_api.re.compile( |
| 2413 | r'^package org\.chromium\.base;$', input_api.re.MULTILINE) |
| 2414 | has_some_log_import_pattern = input_api.re.compile( |
| 2415 | r'^import .*\.Log;$', input_api.re.MULTILINE) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2416 | # Extract the tag from lines like `Log.d(TAG, "*");` or `Log.d("TAG", "*");` |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2417 | log_call_pattern = input_api.re.compile(r'^\s*Log\.\w\((?P<tag>\"?\w+\"?)\,') |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2418 | log_decl_pattern = input_api.re.compile( |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 2419 | r'^\s*private static final String TAG = "(?P<name>(.*))";', |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2420 | input_api.re.MULTILINE) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2421 | |
Vincent Scheib | 16d7b27 | 2015-09-15 18:09:07 | [diff] [blame] | 2422 | REF_MSG = ('See docs/android_logging.md ' |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2423 | 'or contact [email protected] for more info.') |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2424 | sources = lambda x: input_api.FilterSourceFile(x, white_list=[r'.*\.java$'], |
pkotwicz | a1dd0b00 | 2016-05-16 14:41:04 | [diff] [blame] | 2425 | black_list=cr_log_check_excluded_paths) |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2426 | |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2427 | tag_decl_errors = [] |
| 2428 | tag_length_errors = [] |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2429 | tag_errors = [] |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 2430 | tag_with_dot_errors = [] |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2431 | util_log_errors = [] |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2432 | |
| 2433 | for f in input_api.AffectedSourceFiles(sources): |
| 2434 | file_content = input_api.ReadFile(f) |
| 2435 | has_modified_logs = False |
| 2436 | |
| 2437 | # Per line checks |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2438 | if (cr_log_import_pattern.search(file_content) or |
| 2439 | (class_in_base_pattern.search(file_content) and |
| 2440 | not has_some_log_import_pattern.search(file_content))): |
| 2441 | # Checks to run for files using cr log |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2442 | for line_num, line in f.ChangedContents(): |
| 2443 | |
| 2444 | # Check if the new line is doing some logging |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2445 | match = log_call_pattern.search(line) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2446 | if match: |
| 2447 | has_modified_logs = True |
| 2448 | |
| 2449 | # Make sure it uses "TAG" |
| 2450 | if not match.group('tag') == 'TAG': |
| 2451 | tag_errors.append("%s:%d" % (f.LocalPath(), line_num)) |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2452 | else: |
| 2453 | # Report non cr Log function calls in changed lines |
| 2454 | for line_num, line in f.ChangedContents(): |
| 2455 | if log_call_pattern.search(line): |
| 2456 | util_log_errors.append("%s:%d" % (f.LocalPath(), line_num)) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2457 | |
| 2458 | # Per file checks |
| 2459 | if has_modified_logs: |
| 2460 | # Make sure the tag is using the "cr" prefix and is not too long |
| 2461 | match = log_decl_pattern.search(file_content) |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 2462 | tag_name = match.group('name') if match else None |
| 2463 | if not tag_name: |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2464 | tag_decl_errors.append(f.LocalPath()) |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 2465 | elif len(tag_name) > 20: |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2466 | tag_length_errors.append(f.LocalPath()) |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 2467 | elif '.' in tag_name: |
| 2468 | tag_with_dot_errors.append(f.LocalPath()) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2469 | |
| 2470 | results = [] |
| 2471 | if tag_decl_errors: |
| 2472 | results.append(output_api.PresubmitPromptWarning( |
| 2473 | 'Please define your tags using the suggested format: .\n' |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 2474 | '"private static final String TAG = "<package tag>".\n' |
| 2475 | 'They will be prepended with "cr_" automatically.\n' + REF_MSG, |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2476 | tag_decl_errors)) |
| 2477 | |
| 2478 | if tag_length_errors: |
| 2479 | results.append(output_api.PresubmitError( |
| 2480 | 'The tag length is restricted by the system to be at most ' |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 2481 | '20 characters.\n' + REF_MSG, |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 2482 | tag_length_errors)) |
| 2483 | |
| 2484 | if tag_errors: |
| 2485 | results.append(output_api.PresubmitPromptWarning( |
| 2486 | 'Please use a variable named "TAG" for your log tags.\n' + REF_MSG, |
| 2487 | tag_errors)) |
| 2488 | |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2489 | if util_log_errors: |
dgn | 4401aa5 | 2015-04-29 16:26:17 | [diff] [blame] | 2490 | results.append(output_api.PresubmitPromptWarning( |
dgn | 87d9fb6 | 2015-06-12 09:15:12 | [diff] [blame] | 2491 | 'Please use org.chromium.base.Log for new logs.\n' + REF_MSG, |
| 2492 | util_log_errors)) |
| 2493 | |
dgn | 38736db | 2015-09-18 19:20:51 | [diff] [blame] | 2494 | if tag_with_dot_errors: |
| 2495 | results.append(output_api.PresubmitPromptWarning( |
| 2496 | 'Dot in log tags cause them to be elided in crash reports.\n' + REF_MSG, |
| 2497 | tag_with_dot_errors)) |
| 2498 | |
dgn | 4401aa5 | 2015-04-29 16:26:17 | [diff] [blame] | 2499 | return results |
| 2500 | |
| 2501 | |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 2502 | def _CheckAndroidTestJUnitFrameworkImport(input_api, output_api): |
| 2503 | """Checks that junit.framework.* is no longer used.""" |
| 2504 | deprecated_junit_framework_pattern = input_api.re.compile( |
| 2505 | r'^import junit\.framework\..*;', |
| 2506 | input_api.re.MULTILINE) |
| 2507 | sources = lambda x: input_api.FilterSourceFile( |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2508 | x, white_list=[r'.*\.java$'], black_list=None) |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 2509 | errors = [] |
| 2510 | for f in input_api.AffectedFiles(sources): |
| 2511 | for line_num, line in f.ChangedContents(): |
| 2512 | if deprecated_junit_framework_pattern.search(line): |
| 2513 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 2514 | |
| 2515 | results = [] |
| 2516 | if errors: |
| 2517 | results.append(output_api.PresubmitError( |
| 2518 | 'APIs from junit.framework.* are deprecated, please use JUnit4 framework' |
| 2519 | '(org.junit.*) from //third_party/junit. Contact [email protected]' |
| 2520 | ' if you have any question.', errors)) |
| 2521 | return results |
| 2522 | |
| 2523 | |
| 2524 | def _CheckAndroidTestJUnitInheritance(input_api, output_api): |
| 2525 | """Checks that if new Java test classes have inheritance. |
| 2526 | Either the new test class is JUnit3 test or it is a JUnit4 test class |
| 2527 | with a base class, either case is undesirable. |
| 2528 | """ |
| 2529 | class_declaration_pattern = input_api.re.compile(r'^public class \w*Test ') |
| 2530 | |
| 2531 | sources = lambda x: input_api.FilterSourceFile( |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2532 | x, white_list=[r'.*Test\.java$'], black_list=None) |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 2533 | errors = [] |
| 2534 | for f in input_api.AffectedFiles(sources): |
| 2535 | if not f.OldContents(): |
| 2536 | class_declaration_start_flag = False |
| 2537 | for line_num, line in f.ChangedContents(): |
| 2538 | if class_declaration_pattern.search(line): |
| 2539 | class_declaration_start_flag = True |
| 2540 | if class_declaration_start_flag and ' extends ' in line: |
| 2541 | errors.append('%s:%d' % (f.LocalPath(), line_num)) |
| 2542 | if '{' in line: |
| 2543 | class_declaration_start_flag = False |
| 2544 | |
| 2545 | results = [] |
| 2546 | if errors: |
| 2547 | results.append(output_api.PresubmitPromptWarning( |
| 2548 | 'The newly created files include Test classes that inherits from base' |
| 2549 | ' class. Please do not use inheritance in JUnit4 tests or add new' |
| 2550 | ' JUnit3 tests. Contact [email protected] if you have any' |
| 2551 | ' questions.', errors)) |
| 2552 | return results |
| 2553 | |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 2554 | |
yolandyan | 4500147 | 2016-12-21 21:12:42 | [diff] [blame] | 2555 | def _CheckAndroidTestAnnotationUsage(input_api, output_api): |
| 2556 | """Checks that android.test.suitebuilder.annotation.* is no longer used.""" |
| 2557 | deprecated_annotation_import_pattern = input_api.re.compile( |
| 2558 | r'^import android\.test\.suitebuilder\.annotation\..*;', |
| 2559 | input_api.re.MULTILINE) |
| 2560 | sources = lambda x: input_api.FilterSourceFile( |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2561 | x, white_list=[r'.*\.java$'], black_list=None) |
yolandyan | 4500147 | 2016-12-21 21:12:42 | [diff] [blame] | 2562 | errors = [] |
| 2563 | for f in input_api.AffectedFiles(sources): |
| 2564 | for line_num, line in f.ChangedContents(): |
| 2565 | if deprecated_annotation_import_pattern.search(line): |
| 2566 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 2567 | |
| 2568 | results = [] |
| 2569 | if errors: |
| 2570 | results.append(output_api.PresubmitError( |
| 2571 | 'Annotations in android.test.suitebuilder.annotation have been' |
| 2572 | ' deprecated since API level 24. Please use android.support.test.filters' |
| 2573 | ' from //third_party/android_support_test_runner:runner_java instead.' |
| 2574 | ' Contact [email protected] if you have any questions.', errors)) |
| 2575 | return results |
| 2576 | |
| 2577 | |
agrieve | 7b6479d8 | 2015-10-07 14:24:22 | [diff] [blame] | 2578 | def _CheckAndroidNewMdpiAssetLocation(input_api, output_api): |
| 2579 | """Checks if MDPI assets are placed in a correct directory.""" |
| 2580 | file_filter = lambda f: (f.LocalPath().endswith('.png') and |
| 2581 | ('/res/drawable/' in f.LocalPath() or |
| 2582 | '/res/drawable-ldrtl/' in f.LocalPath())) |
| 2583 | errors = [] |
| 2584 | for f in input_api.AffectedFiles(include_deletes=False, |
| 2585 | file_filter=file_filter): |
| 2586 | errors.append(' %s' % f.LocalPath()) |
| 2587 | |
| 2588 | results = [] |
| 2589 | if errors: |
| 2590 | results.append(output_api.PresubmitError( |
| 2591 | 'MDPI assets should be placed in /res/drawable-mdpi/ or ' |
| 2592 | '/res/drawable-ldrtl-mdpi/\ninstead of /res/drawable/ and' |
| 2593 | '/res/drawable-ldrtl/.\n' |
| 2594 | 'Contact [email protected] if you have questions.', errors)) |
| 2595 | return results |
| 2596 | |
| 2597 | |
Nate Fischer | 535972b | 2017-09-16 01:06:18 | [diff] [blame] | 2598 | def _CheckAndroidWebkitImports(input_api, output_api): |
| 2599 | """Checks that code uses org.chromium.base.Callback instead of |
| 2600 | android.widget.ValueCallback except in the WebView glue layer. |
| 2601 | """ |
| 2602 | valuecallback_import_pattern = input_api.re.compile( |
| 2603 | r'^import android\.webkit\.ValueCallback;$') |
| 2604 | |
| 2605 | errors = [] |
| 2606 | |
| 2607 | sources = lambda affected_file: input_api.FilterSourceFile( |
| 2608 | affected_file, |
| 2609 | black_list=(_EXCLUDED_PATHS + |
| 2610 | _TEST_CODE_EXCLUDED_PATHS + |
| 2611 | input_api.DEFAULT_BLACK_LIST + |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2612 | (r'^android_webview[\\/]glue[\\/].*',)), |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2613 | white_list=[r'.*\.java$']) |
Nate Fischer | 535972b | 2017-09-16 01:06:18 | [diff] [blame] | 2614 | |
| 2615 | for f in input_api.AffectedSourceFiles(sources): |
| 2616 | for line_num, line in f.ChangedContents(): |
| 2617 | if valuecallback_import_pattern.search(line): |
| 2618 | errors.append("%s:%d" % (f.LocalPath(), line_num)) |
| 2619 | |
| 2620 | results = [] |
| 2621 | |
| 2622 | if errors: |
| 2623 | results.append(output_api.PresubmitError( |
| 2624 | 'android.webkit.ValueCallback usage is detected outside of the glue' |
| 2625 | ' layer. To stay compatible with the support library, android.webkit.*' |
| 2626 | ' classes should only be used inside the glue layer and' |
| 2627 | ' org.chromium.base.Callback should be used instead.', |
| 2628 | errors)) |
| 2629 | |
| 2630 | return results |
| 2631 | |
| 2632 | |
Becky Zhou | 7c69b5099 | 2018-12-10 19:37:57 | [diff] [blame] | 2633 | def _CheckAndroidXmlStyle(input_api, output_api, is_check_on_upload): |
| 2634 | """Checks Android XML styles """ |
| 2635 | import sys |
| 2636 | original_sys_path = sys.path |
| 2637 | try: |
| 2638 | sys.path = sys.path + [input_api.os_path.join( |
| 2639 | input_api.PresubmitLocalPath(), 'tools', 'android', 'checkxmlstyle')] |
| 2640 | import checkxmlstyle |
| 2641 | finally: |
| 2642 | # Restore sys.path to what it was before. |
| 2643 | sys.path = original_sys_path |
| 2644 | |
| 2645 | if is_check_on_upload: |
| 2646 | return checkxmlstyle.CheckStyleOnUpload(input_api, output_api) |
| 2647 | else: |
| 2648 | return checkxmlstyle.CheckStyleOnCommit(input_api, output_api) |
| 2649 | |
| 2650 | |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2651 | class PydepsChecker(object): |
| 2652 | def __init__(self, input_api, pydeps_files): |
| 2653 | self._file_cache = {} |
| 2654 | self._input_api = input_api |
| 2655 | self._pydeps_files = pydeps_files |
| 2656 | |
| 2657 | def _LoadFile(self, path): |
| 2658 | """Returns the list of paths within a .pydeps file relative to //.""" |
| 2659 | if path not in self._file_cache: |
| 2660 | with open(path) as f: |
| 2661 | self._file_cache[path] = f.read() |
| 2662 | return self._file_cache[path] |
| 2663 | |
| 2664 | def _ComputeNormalizedPydepsEntries(self, pydeps_path): |
| 2665 | """Returns an interable of paths within the .pydep, relativized to //.""" |
| 2666 | os_path = self._input_api.os_path |
| 2667 | pydeps_dir = os_path.dirname(pydeps_path) |
| 2668 | entries = (l.rstrip() for l in self._LoadFile(pydeps_path).splitlines() |
| 2669 | if not l.startswith('*')) |
| 2670 | return (os_path.normpath(os_path.join(pydeps_dir, e)) for e in entries) |
| 2671 | |
| 2672 | def _CreateFilesToPydepsMap(self): |
| 2673 | """Returns a map of local_path -> list_of_pydeps.""" |
| 2674 | ret = {} |
| 2675 | for pydep_local_path in self._pydeps_files: |
| 2676 | for path in self._ComputeNormalizedPydepsEntries(pydep_local_path): |
| 2677 | ret.setdefault(path, []).append(pydep_local_path) |
| 2678 | return ret |
| 2679 | |
| 2680 | def ComputeAffectedPydeps(self): |
| 2681 | """Returns an iterable of .pydeps files that might need regenerating.""" |
| 2682 | affected_pydeps = set() |
| 2683 | file_to_pydeps_map = None |
| 2684 | for f in self._input_api.AffectedFiles(include_deletes=True): |
| 2685 | local_path = f.LocalPath() |
Andrew Grieve | 892bb3f | 2019-03-20 17:33:46 | [diff] [blame] | 2686 | # Changes to DEPS can lead to .pydeps changes if any .py files are in |
| 2687 | # subrepositories. We can't figure out which files change, so re-check |
| 2688 | # all files. |
| 2689 | # Changes to print_python_deps.py affect all .pydeps. |
| 2690 | if local_path == 'DEPS' or local_path.endswith('print_python_deps.py'): |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2691 | return self._pydeps_files |
| 2692 | elif local_path.endswith('.pydeps'): |
| 2693 | if local_path in self._pydeps_files: |
| 2694 | affected_pydeps.add(local_path) |
| 2695 | elif local_path.endswith('.py'): |
| 2696 | if file_to_pydeps_map is None: |
| 2697 | file_to_pydeps_map = self._CreateFilesToPydepsMap() |
| 2698 | affected_pydeps.update(file_to_pydeps_map.get(local_path, ())) |
| 2699 | return affected_pydeps |
| 2700 | |
| 2701 | def DetermineIfStale(self, pydeps_path): |
| 2702 | """Runs print_python_deps.py to see if the files is stale.""" |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 2703 | import difflib |
John Budorick | 47ca3fe | 2018-02-10 00:53:10 | [diff] [blame] | 2704 | import os |
| 2705 | |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2706 | old_pydeps_data = self._LoadFile(pydeps_path).splitlines() |
| 2707 | cmd = old_pydeps_data[1][1:].strip() |
John Budorick | 47ca3fe | 2018-02-10 00:53:10 | [diff] [blame] | 2708 | env = dict(os.environ) |
| 2709 | env['PYTHONDONTWRITEBYTECODE'] = '1' |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2710 | new_pydeps_data = self._input_api.subprocess.check_output( |
John Budorick | 47ca3fe | 2018-02-10 00:53:10 | [diff] [blame] | 2711 | cmd + ' --output ""', shell=True, env=env) |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 2712 | old_contents = old_pydeps_data[2:] |
| 2713 | new_contents = new_pydeps_data.splitlines()[2:] |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2714 | if old_pydeps_data[2:] != new_pydeps_data.splitlines()[2:]: |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 2715 | return cmd, '\n'.join(difflib.context_diff(old_contents, new_contents)) |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2716 | |
| 2717 | |
| 2718 | def _CheckPydepsNeedsUpdating(input_api, output_api, checker_for_tests=None): |
| 2719 | """Checks if a .pydeps file needs to be regenerated.""" |
John Chen | cde8919 | 2018-01-27 21:18:40 | [diff] [blame] | 2720 | # This check is for Python dependency lists (.pydeps files), and involves |
| 2721 | # paths not only in the PRESUBMIT.py, but also in the .pydeps files. It |
| 2722 | # doesn't work on Windows and Mac, so skip it on other platforms. |
agrieve | 9bc4200b | 2016-05-04 16:33:28 | [diff] [blame] | 2723 | if input_api.platform != 'linux2': |
agrieve | bb9c5b47 | 2016-04-22 15:13:00 | [diff] [blame] | 2724 | return [] |
Mostyn Bramley-Moore | 6b42732 | 2017-12-21 22:11:02 | [diff] [blame] | 2725 | # TODO(agrieve): Update when there's a better way to detect |
| 2726 | # this: crbug.com/570091 |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2727 | is_android = input_api.os_path.exists('third_party/android_tools') |
| 2728 | pydeps_files = _ALL_PYDEPS_FILES if is_android else _GENERIC_PYDEPS_FILES |
| 2729 | results = [] |
| 2730 | # First, check for new / deleted .pydeps. |
| 2731 | for f in input_api.AffectedFiles(include_deletes=True): |
Zhiling Huang | 45cabf3 | 2018-03-10 00:50:03 | [diff] [blame] | 2732 | # Check whether we are running the presubmit check for a file in src. |
| 2733 | # f.LocalPath is relative to repo (src, or internal repo). |
| 2734 | # os_path.exists is relative to src repo. |
| 2735 | # Therefore if os_path.exists is true, it means f.LocalPath is relative |
| 2736 | # to src and we can conclude that the pydeps is in src. |
| 2737 | if input_api.os_path.exists(f.LocalPath()): |
| 2738 | if f.LocalPath().endswith('.pydeps'): |
| 2739 | if f.Action() == 'D' and f.LocalPath() in _ALL_PYDEPS_FILES: |
| 2740 | results.append(output_api.PresubmitError( |
| 2741 | 'Please update _ALL_PYDEPS_FILES within //PRESUBMIT.py to ' |
| 2742 | 'remove %s' % f.LocalPath())) |
| 2743 | elif f.Action() != 'D' and f.LocalPath() not in _ALL_PYDEPS_FILES: |
| 2744 | results.append(output_api.PresubmitError( |
| 2745 | 'Please update _ALL_PYDEPS_FILES within //PRESUBMIT.py to ' |
| 2746 | 'include %s' % f.LocalPath())) |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2747 | |
| 2748 | if results: |
| 2749 | return results |
| 2750 | |
| 2751 | checker = checker_for_tests or PydepsChecker(input_api, pydeps_files) |
| 2752 | |
| 2753 | for pydep_path in checker.ComputeAffectedPydeps(): |
| 2754 | try: |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 2755 | result = checker.DetermineIfStale(pydep_path) |
| 2756 | if result: |
| 2757 | cmd, diff = result |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2758 | results.append(output_api.PresubmitError( |
phajdan.jr | 0d987855 | 2016-11-04 10:49:41 | [diff] [blame] | 2759 | 'File is stale: %s\nDiff (apply to fix):\n%s\n' |
| 2760 | 'To regenerate, run:\n\n %s' % |
| 2761 | (pydep_path, diff, cmd))) |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 2762 | except input_api.subprocess.CalledProcessError as error: |
| 2763 | return [output_api.PresubmitError('Error running: %s' % error.cmd, |
| 2764 | long_text=error.output)] |
| 2765 | |
| 2766 | return results |
| 2767 | |
| 2768 | |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 2769 | def _CheckSingletonInHeaders(input_api, output_api): |
| 2770 | """Checks to make sure no header files have |Singleton<|.""" |
| 2771 | def FileFilter(affected_file): |
| 2772 | # It's ok for base/memory/singleton.h to have |Singleton<|. |
| 2773 | black_list = (_EXCLUDED_PATHS + |
| 2774 | input_api.DEFAULT_BLACK_LIST + |
Egor Pasko | ce145c4 | 2018-09-28 19:31:04 | [diff] [blame] | 2775 | (r"^base[\\/]memory[\\/]singleton\.h$", |
| 2776 | r"^net[\\/]quic[\\/]platform[\\/]impl[\\/]" |
Michael Warres | e445149 | 2018-03-07 04:42:47 | [diff] [blame] | 2777 | r"quic_singleton_impl\.h$")) |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 2778 | return input_api.FilterSourceFile(affected_file, black_list=black_list) |
| 2779 | |
sergeyu | 34d2122 | 2015-09-16 00:11:44 | [diff] [blame] | 2780 | pattern = input_api.re.compile(r'(?<!class\sbase::)Singleton\s*<') |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 2781 | files = [] |
| 2782 | for f in input_api.AffectedSourceFiles(FileFilter): |
| 2783 | if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or |
| 2784 | f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): |
| 2785 | contents = input_api.ReadFile(f) |
| 2786 | for line in contents.splitlines(False): |
oysteine | c430ad4 | 2015-10-22 20:55:24 | [diff] [blame] | 2787 | if (not line.lstrip().startswith('//') and # Strip C++ comment. |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 2788 | pattern.search(line)): |
| 2789 | files.append(f) |
| 2790 | break |
| 2791 | |
| 2792 | if files: |
yolandyan | daabc6d | 2016-04-18 18:29:39 | [diff] [blame] | 2793 | return [output_api.PresubmitError( |
sergeyu | 34d2122 | 2015-09-16 00:11:44 | [diff] [blame] | 2794 | 'Found base::Singleton<T> in the following header files.\n' + |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 2795 | 'Please move them to an appropriate source file so that the ' + |
| 2796 | 'template gets instantiated in a single compilation unit.', |
| 2797 | files) ] |
| 2798 | return [] |
| 2799 | |
| 2800 | |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 2801 | _DEPRECATED_CSS = [ |
| 2802 | # Values |
| 2803 | ( "-webkit-box", "flex" ), |
| 2804 | ( "-webkit-inline-box", "inline-flex" ), |
| 2805 | ( "-webkit-flex", "flex" ), |
| 2806 | ( "-webkit-inline-flex", "inline-flex" ), |
| 2807 | ( "-webkit-min-content", "min-content" ), |
| 2808 | ( "-webkit-max-content", "max-content" ), |
| 2809 | |
| 2810 | # Properties |
| 2811 | ( "-webkit-background-clip", "background-clip" ), |
| 2812 | ( "-webkit-background-origin", "background-origin" ), |
| 2813 | ( "-webkit-background-size", "background-size" ), |
| 2814 | ( "-webkit-box-shadow", "box-shadow" ), |
dbeam | 6936c67f | 2017-01-19 01:51:44 | [diff] [blame] | 2815 | ( "-webkit-user-select", "user-select" ), |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 2816 | |
| 2817 | # Functions |
| 2818 | ( "-webkit-gradient", "gradient" ), |
| 2819 | ( "-webkit-repeating-gradient", "repeating-gradient" ), |
| 2820 | ( "-webkit-linear-gradient", "linear-gradient" ), |
| 2821 | ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ), |
| 2822 | ( "-webkit-radial-gradient", "radial-gradient" ), |
| 2823 | ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ), |
| 2824 | ] |
| 2825 | |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 2826 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2827 | # TODO: add unit tests |
dbeam | 1ec68ac | 2016-12-15 05:22:24 | [diff] [blame] | 2828 | def _CheckNoDeprecatedCss(input_api, output_api): |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 2829 | """ Make sure that we don't use deprecated CSS |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 2830 | properties, functions or values. Our external |
mdjones | ae0286c3 | 2015-06-10 18:10:34 | [diff] [blame] | 2831 | documentation and iOS CSS for dom distiller |
| 2832 | (reader mode) are ignored by the hooks as it |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 2833 | needs to be consumed by WebKit. """ |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 2834 | results = [] |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2835 | file_inclusion_pattern = [r".+\.css$"] |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 2836 | black_list = (_EXCLUDED_PATHS + |
| 2837 | _TEST_CODE_EXCLUDED_PATHS + |
| 2838 | input_api.DEFAULT_BLACK_LIST + |
| 2839 | (r"^chrome/common/extensions/docs", |
| 2840 | r"^chrome/docs", |
mdjones | ae0286c3 | 2015-06-10 18:10:34 | [diff] [blame] | 2841 | r"^components/dom_distiller/core/css/distilledpage_ios.css", |
sdefresne | 6308d7f | 2016-02-15 09:38:44 | [diff] [blame] | 2842 | r"^components/neterror/resources/neterror.css", |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 2843 | r"^native_client_sdk")) |
| 2844 | file_filter = lambda f: input_api.FilterSourceFile( |
| 2845 | f, white_list=file_inclusion_pattern, black_list=black_list) |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 2846 | for fpath in input_api.AffectedFiles(file_filter=file_filter): |
| 2847 | for line_num, line in fpath.ChangedContents(): |
| 2848 | for (deprecated_value, value) in _DEPRECATED_CSS: |
dbeam | 070cfe6 | 2014-10-22 06:44:02 | [diff] [blame] | 2849 | if deprecated_value in line: |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 2850 | results.append(output_api.PresubmitError( |
| 2851 | "%s:%d: Use of deprecated CSS %s, use %s instead" % |
| 2852 | (fpath.LocalPath(), line_num, deprecated_value, value))) |
| 2853 | return results |
| 2854 | |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 2855 | |
dbeam | 070cfe6 | 2014-10-22 06:44:02 | [diff] [blame] | 2856 | _DEPRECATED_JS = [ |
| 2857 | ( "__lookupGetter__", "Object.getOwnPropertyDescriptor" ), |
| 2858 | ( "__defineGetter__", "Object.defineProperty" ), |
| 2859 | ( "__defineSetter__", "Object.defineProperty" ), |
| 2860 | ] |
| 2861 | |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 2862 | |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2863 | # TODO: add unit tests |
dbeam | 1ec68ac | 2016-12-15 05:22:24 | [diff] [blame] | 2864 | def _CheckNoDeprecatedJs(input_api, output_api): |
dbeam | 070cfe6 | 2014-10-22 06:44:02 | [diff] [blame] | 2865 | """Make sure that we don't use deprecated JS in Chrome code.""" |
| 2866 | results = [] |
Wei-Yin Chen (陳威尹) | dca729a | 2018-07-31 21:35:49 | [diff] [blame] | 2867 | file_inclusion_pattern = [r".+\.js$"] # TODO(dbeam): .html? |
dbeam | 070cfe6 | 2014-10-22 06:44:02 | [diff] [blame] | 2868 | black_list = (_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS + |
| 2869 | input_api.DEFAULT_BLACK_LIST) |
| 2870 | file_filter = lambda f: input_api.FilterSourceFile( |
| 2871 | f, white_list=file_inclusion_pattern, black_list=black_list) |
| 2872 | for fpath in input_api.AffectedFiles(file_filter=file_filter): |
| 2873 | for lnum, line in fpath.ChangedContents(): |
| 2874 | for (deprecated, replacement) in _DEPRECATED_JS: |
| 2875 | if deprecated in line: |
| 2876 | results.append(output_api.PresubmitError( |
| 2877 | "%s:%d: Use of deprecated JS %s, use %s instead" % |
| 2878 | (fpath.LocalPath(), lnum, deprecated, replacement))) |
| 2879 | return results |
| 2880 | |
Wei-Yin Chen (陳威尹) | f799d44 | 2018-07-31 02:20:20 | [diff] [blame] | 2881 | |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 2882 | def _CheckForRelativeIncludes(input_api, output_api): |
| 2883 | # Need to set the sys.path so PRESUBMIT_test.py runs properly |
| 2884 | import sys |
| 2885 | original_sys_path = sys.path |
| 2886 | try: |
| 2887 | sys.path = sys.path + [input_api.os_path.join( |
| 2888 | input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
| 2889 | from cpp_checker import CppChecker |
| 2890 | finally: |
| 2891 | # Restore sys.path to what it was before. |
| 2892 | sys.path = original_sys_path |
| 2893 | |
| 2894 | bad_files = {} |
| 2895 | for f in input_api.AffectedFiles(include_deletes=False): |
| 2896 | if (f.LocalPath().startswith('third_party') and |
Kent Tamura | 32dbbcb | 2018-11-30 12:28:49 | [diff] [blame] | 2897 | not f.LocalPath().startswith('third_party/blink') and |
| 2898 | not f.LocalPath().startswith('third_party\\blink')): |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 2899 | continue |
| 2900 | |
| 2901 | if not CppChecker.IsCppFile(f.LocalPath()): |
| 2902 | continue |
| 2903 | |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 2904 | relative_includes = [line for _, line in f.ChangedContents() |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 2905 | if "#include" in line and "../" in line] |
| 2906 | if not relative_includes: |
| 2907 | continue |
| 2908 | bad_files[f.LocalPath()] = relative_includes |
| 2909 | |
| 2910 | if not bad_files: |
| 2911 | return [] |
| 2912 | |
| 2913 | error_descriptions = [] |
| 2914 | for file_path, bad_lines in bad_files.iteritems(): |
| 2915 | error_description = file_path |
| 2916 | for line in bad_lines: |
| 2917 | error_description += '\n ' + line |
| 2918 | error_descriptions.append(error_description) |
| 2919 | |
| 2920 | results = [] |
| 2921 | results.append(output_api.PresubmitError( |
| 2922 | 'You added one or more relative #include paths (including "../").\n' |
| 2923 | 'These shouldn\'t be used because they can be used to include headers\n' |
| 2924 | 'from code that\'s not correctly specified as a dependency in the\n' |
| 2925 | 'relevant BUILD.gn file(s).', |
| 2926 | error_descriptions)) |
| 2927 | |
| 2928 | return results |
| 2929 | |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 2930 | |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 2931 | def _CheckWatchlistDefinitionsEntrySyntax(key, value, ast): |
| 2932 | if not isinstance(key, ast.Str): |
| 2933 | return 'Key at line %d must be a string literal' % key.lineno |
| 2934 | if not isinstance(value, ast.Dict): |
| 2935 | return 'Value at line %d must be a dict' % value.lineno |
| 2936 | if len(value.keys) != 1: |
| 2937 | return 'Dict at line %d must have single entry' % value.lineno |
| 2938 | if not isinstance(value.keys[0], ast.Str) or value.keys[0].s != 'filepath': |
| 2939 | return ( |
| 2940 | 'Entry at line %d must have a string literal \'filepath\' as key' % |
| 2941 | value.lineno) |
| 2942 | return None |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 2943 | |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 2944 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 2945 | def _CheckWatchlistsEntrySyntax(key, value, ast, email_regex): |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 2946 | if not isinstance(key, ast.Str): |
| 2947 | return 'Key at line %d must be a string literal' % key.lineno |
| 2948 | if not isinstance(value, ast.List): |
| 2949 | return 'Value at line %d must be a list' % value.lineno |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 2950 | for element in value.elts: |
| 2951 | if not isinstance(element, ast.Str): |
| 2952 | return 'Watchlist elements on line %d is not a string' % key.lineno |
| 2953 | if not email_regex.match(element.s): |
| 2954 | return ('Watchlist element on line %d doesn\'t look like a valid ' + |
| 2955 | 'email: %s') % (key.lineno, element.s) |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 2956 | return None |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 2957 | |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 2958 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 2959 | def _CheckWATCHLISTSEntries(wd_dict, w_dict, input_api): |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 2960 | mismatch_template = ( |
| 2961 | 'Mismatch between WATCHLIST_DEFINITIONS entry (%s) and WATCHLISTS ' |
| 2962 | 'entry (%s)') |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 2963 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 2964 | email_regex = input_api.re.compile( |
| 2965 | r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+$") |
| 2966 | |
| 2967 | ast = input_api.ast |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 2968 | i = 0 |
| 2969 | last_key = '' |
| 2970 | while True: |
| 2971 | if i >= len(wd_dict.keys): |
| 2972 | if i >= len(w_dict.keys): |
| 2973 | return None |
| 2974 | return mismatch_template % ('missing', 'line %d' % w_dict.keys[i].lineno) |
| 2975 | elif i >= len(w_dict.keys): |
| 2976 | return ( |
| 2977 | mismatch_template % ('line %d' % wd_dict.keys[i].lineno, 'missing')) |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 2978 | |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 2979 | wd_key = wd_dict.keys[i] |
| 2980 | w_key = w_dict.keys[i] |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 2981 | |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 2982 | result = _CheckWatchlistDefinitionsEntrySyntax( |
| 2983 | wd_key, wd_dict.values[i], ast) |
| 2984 | if result is not None: |
| 2985 | return 'Bad entry in WATCHLIST_DEFINITIONS dict: %s' % result |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 2986 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 2987 | result = _CheckWatchlistsEntrySyntax( |
| 2988 | w_key, w_dict.values[i], ast, email_regex) |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 2989 | if result is not None: |
| 2990 | return 'Bad entry in WATCHLISTS dict: %s' % result |
| 2991 | |
| 2992 | if wd_key.s != w_key.s: |
| 2993 | return mismatch_template % ( |
| 2994 | '%s at line %d' % (wd_key.s, wd_key.lineno), |
| 2995 | '%s at line %d' % (w_key.s, w_key.lineno)) |
| 2996 | |
| 2997 | if wd_key.s < last_key: |
| 2998 | return ( |
| 2999 | 'WATCHLISTS dict is not sorted lexicographically at line %d and %d' % |
| 3000 | (wd_key.lineno, w_key.lineno)) |
| 3001 | last_key = wd_key.s |
| 3002 | |
| 3003 | i = i + 1 |
| 3004 | |
| 3005 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 3006 | def _CheckWATCHLISTSSyntax(expression, input_api): |
| 3007 | ast = input_api.ast |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3008 | if not isinstance(expression, ast.Expression): |
| 3009 | return 'WATCHLISTS file must contain a valid expression' |
| 3010 | dictionary = expression.body |
| 3011 | if not isinstance(dictionary, ast.Dict) or len(dictionary.keys) != 2: |
| 3012 | return 'WATCHLISTS file must have single dict with exactly two entries' |
| 3013 | |
| 3014 | first_key = dictionary.keys[0] |
| 3015 | first_value = dictionary.values[0] |
| 3016 | second_key = dictionary.keys[1] |
| 3017 | second_value = dictionary.values[1] |
| 3018 | |
| 3019 | if (not isinstance(first_key, ast.Str) or |
| 3020 | first_key.s != 'WATCHLIST_DEFINITIONS' or |
| 3021 | not isinstance(first_value, ast.Dict)): |
| 3022 | return ( |
| 3023 | 'The first entry of the dict in WATCHLISTS file must be ' |
| 3024 | 'WATCHLIST_DEFINITIONS dict') |
| 3025 | |
| 3026 | if (not isinstance(second_key, ast.Str) or |
| 3027 | second_key.s != 'WATCHLISTS' or |
| 3028 | not isinstance(second_value, ast.Dict)): |
| 3029 | return ( |
| 3030 | 'The second entry of the dict in WATCHLISTS file must be ' |
| 3031 | 'WATCHLISTS dict') |
| 3032 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 3033 | return _CheckWATCHLISTSEntries(first_value, second_value, input_api) |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3034 | |
| 3035 | |
| 3036 | def _CheckWATCHLISTS(input_api, output_api): |
| 3037 | for f in input_api.AffectedFiles(include_deletes=False): |
| 3038 | if f.LocalPath() == 'WATCHLISTS': |
| 3039 | contents = input_api.ReadFile(f, 'r') |
| 3040 | |
| 3041 | try: |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3042 | # First, make sure that it can be evaluated. |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3043 | input_api.ast.literal_eval(contents) |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3044 | # Get an AST tree for it and scan the tree for detailed style checking. |
| 3045 | expression = input_api.ast.parse( |
| 3046 | contents, filename='WATCHLISTS', mode='eval') |
| 3047 | except ValueError as e: |
| 3048 | return [output_api.PresubmitError( |
| 3049 | 'Cannot parse WATCHLISTS file', long_text=repr(e))] |
| 3050 | except SyntaxError as e: |
| 3051 | return [output_api.PresubmitError( |
| 3052 | 'Cannot parse WATCHLISTS file', long_text=repr(e))] |
| 3053 | except TypeError as e: |
| 3054 | return [output_api.PresubmitError( |
| 3055 | 'Cannot parse WATCHLISTS file', long_text=repr(e))] |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3056 | |
Sergey Ulanov | 4af1605 | 2018-11-08 02:41:46 | [diff] [blame] | 3057 | result = _CheckWATCHLISTSSyntax(expression, input_api) |
Takeshi Yoshino | 3a8f9cb5 | 2017-08-10 11:32:20 | [diff] [blame] | 3058 | if result is not None: |
| 3059 | return [output_api.PresubmitError(result)] |
| 3060 | break |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3061 | |
| 3062 | return [] |
| 3063 | |
| 3064 | |
Wei-Yin Chen (陳威尹) | c0624d00 | 2018-07-30 18:22:19 | [diff] [blame] | 3065 | def _CheckNewHeaderWithoutGnChange(input_api, output_api): |
| 3066 | """Checks that newly added header files have corresponding GN changes. |
| 3067 | Note that this is only a heuristic. To be precise, run script: |
| 3068 | build/check_gn_headers.py. |
| 3069 | """ |
| 3070 | |
| 3071 | def headers(f): |
| 3072 | return input_api.FilterSourceFile( |
| 3073 | f, white_list=(r'.+%s' % _HEADER_EXTENSIONS, )) |
| 3074 | |
| 3075 | new_headers = [] |
| 3076 | for f in input_api.AffectedSourceFiles(headers): |
| 3077 | if f.Action() != 'A': |
| 3078 | continue |
| 3079 | new_headers.append(f.LocalPath()) |
| 3080 | |
| 3081 | def gn_files(f): |
| 3082 | return input_api.FilterSourceFile(f, white_list=(r'.+\.gn', )) |
| 3083 | |
| 3084 | all_gn_changed_contents = '' |
| 3085 | for f in input_api.AffectedSourceFiles(gn_files): |
| 3086 | for _, line in f.ChangedContents(): |
| 3087 | all_gn_changed_contents += line |
| 3088 | |
| 3089 | problems = [] |
| 3090 | for header in new_headers: |
| 3091 | basename = input_api.os_path.basename(header) |
| 3092 | if basename not in all_gn_changed_contents: |
| 3093 | problems.append(header) |
| 3094 | |
| 3095 | if problems: |
| 3096 | return [output_api.PresubmitPromptWarning( |
| 3097 | 'Missing GN changes for new header files', items=sorted(problems), |
| 3098 | long_text='Please double check whether newly added header files need ' |
| 3099 | 'corresponding changes in gn or gni files.\nThis checking is only a ' |
| 3100 | 'heuristic. Run build/check_gn_headers.py to be precise.\n' |
| 3101 | 'Read https://crbug.com/661774 for more info.')] |
| 3102 | return [] |
| 3103 | |
| 3104 | |
Michael Giuffrida | d3bc867 | 2018-10-25 22:48:02 | [diff] [blame] | 3105 | def _CheckCorrectProductNameInMessages(input_api, output_api): |
| 3106 | """Check that Chromium-branded strings don't include "Chrome" or vice versa. |
| 3107 | |
| 3108 | This assumes we won't intentionally reference one product from the other |
| 3109 | product. |
| 3110 | """ |
| 3111 | all_problems = [] |
| 3112 | test_cases = [{ |
| 3113 | "filename_postfix": "google_chrome_strings.grd", |
| 3114 | "correct_name": "Chrome", |
| 3115 | "incorrect_name": "Chromium", |
| 3116 | }, { |
| 3117 | "filename_postfix": "chromium_strings.grd", |
| 3118 | "correct_name": "Chromium", |
| 3119 | "incorrect_name": "Chrome", |
| 3120 | }] |
| 3121 | |
| 3122 | for test_case in test_cases: |
| 3123 | problems = [] |
| 3124 | filename_filter = lambda x: x.LocalPath().endswith( |
| 3125 | test_case["filename_postfix"]) |
| 3126 | |
| 3127 | # Check each new line. Can yield false positives in multiline comments, but |
| 3128 | # easier than trying to parse the XML because messages can have nested |
| 3129 | # children, and associating message elements with affected lines is hard. |
| 3130 | for f in input_api.AffectedSourceFiles(filename_filter): |
| 3131 | for line_num, line in f.ChangedContents(): |
| 3132 | if "<message" in line or "<!--" in line or "-->" in line: |
| 3133 | continue |
| 3134 | if test_case["incorrect_name"] in line: |
| 3135 | problems.append( |
| 3136 | "Incorrect product name in %s:%d" % (f.LocalPath(), line_num)) |
| 3137 | |
| 3138 | if problems: |
| 3139 | message = ( |
| 3140 | "Strings in %s-branded string files should reference \"%s\", not \"%s\"" |
| 3141 | % (test_case["correct_name"], test_case["correct_name"], |
| 3142 | test_case["incorrect_name"])) |
| 3143 | all_problems.append( |
| 3144 | output_api.PresubmitPromptWarning(message, items=problems)) |
| 3145 | |
| 3146 | return all_problems |
| 3147 | |
| 3148 | |
Dirk Pranke | 3c18a38 | 2019-03-15 01:07:51 | [diff] [blame] | 3149 | def _CheckBuildtoolsRevisionsAreInSync(input_api, output_api): |
| 3150 | # TODO(crbug.com/941824): We need to make sure the entries in |
| 3151 | # //buildtools/DEPS are kept in sync with the entries in //DEPS |
| 3152 | # so that users of //buildtools in other projects get the same tooling |
| 3153 | # Chromium gets. If we ever fix the referenced bug and add 'includedeps' |
| 3154 | # support to gclient, we can eliminate the duplication and delete |
| 3155 | # this presubmit check. |
| 3156 | |
| 3157 | # Update this regexp if new revisions are added to the files. |
| 3158 | rev_regexp = input_api.re.compile( |
Dirk Pranke | 6d095b4 | 2019-03-15 23:44:01 | [diff] [blame] | 3159 | "'((clang_format|libcxx|libcxxabi|libunwind)_revision|gn_version)':") |
Dirk Pranke | 3c18a38 | 2019-03-15 01:07:51 | [diff] [blame] | 3160 | |
| 3161 | # If a user is changing one revision, they need to change the same |
| 3162 | # line in both files. This means that any given change should contain |
| 3163 | # exactly the same list of changed lines that match the regexps. The |
| 3164 | # replace(' ', '') call allows us to ignore whitespace changes to the |
| 3165 | # lines. The 'long_text' parameter to the error will contain the |
| 3166 | # list of changed lines in both files, which should make it easy enough |
| 3167 | # to spot the error without going overboard in this implementation. |
| 3168 | revs_changes = { |
| 3169 | 'DEPS': {}, |
| 3170 | 'buildtools/DEPS': {}, |
| 3171 | } |
| 3172 | long_text = '' |
| 3173 | |
| 3174 | for f in input_api.AffectedFiles( |
| 3175 | file_filter=lambda f: f.LocalPath() in ('DEPS', 'buildtools/DEPS')): |
| 3176 | for line_num, line in f.ChangedContents(): |
| 3177 | if rev_regexp.search(line): |
| 3178 | revs_changes[f.LocalPath()][line.replace(' ', '')] = line |
| 3179 | long_text += '%s:%d: %s\n' % (f.LocalPath(), line_num, line) |
| 3180 | |
| 3181 | if set(revs_changes['DEPS']) != set(revs_changes['buildtools/DEPS']): |
| 3182 | return [output_api.PresubmitError( |
| 3183 | 'Change buildtools revisions in sync in both //DEPS and ' |
| 3184 | '//buildtools/DEPS.', long_text=long_text + '\n')] |
| 3185 | else: |
| 3186 | return [] |
| 3187 | |
| 3188 | |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3189 | def _AndroidSpecificOnUploadChecks(input_api, output_api): |
Becky Zhou | 7c69b5099 | 2018-12-10 19:37:57 | [diff] [blame] | 3190 | """Groups upload checks that target android code.""" |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3191 | results = [] |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3192 | results.extend(_CheckAndroidCrLogUsage(input_api, output_api)) |
agrieve | 7b6479d8 | 2015-10-07 14:24:22 | [diff] [blame] | 3193 | results.extend(_CheckAndroidNewMdpiAssetLocation(input_api, output_api)) |
dskiba | 88634f4e | 2015-08-14 23:03:29 | [diff] [blame] | 3194 | results.extend(_CheckAndroidToastUsage(input_api, output_api)) |
Yoland Yan | b92fa52 | 2017-08-28 17:37:06 | [diff] [blame] | 3195 | results.extend(_CheckAndroidTestJUnitInheritance(input_api, output_api)) |
| 3196 | results.extend(_CheckAndroidTestJUnitFrameworkImport(input_api, output_api)) |
yolandyan | 4500147 | 2016-12-21 21:12:42 | [diff] [blame] | 3197 | results.extend(_CheckAndroidTestAnnotationUsage(input_api, output_api)) |
Nate Fischer | 535972b | 2017-09-16 01:06:18 | [diff] [blame] | 3198 | results.extend(_CheckAndroidWebkitImports(input_api, output_api)) |
Becky Zhou | 7c69b5099 | 2018-12-10 19:37:57 | [diff] [blame] | 3199 | results.extend(_CheckAndroidXmlStyle(input_api, output_api, True)) |
| 3200 | return results |
| 3201 | |
| 3202 | def _AndroidSpecificOnCommitChecks(input_api, output_api): |
| 3203 | """Groups commit checks that target android code.""" |
| 3204 | results = [] |
| 3205 | results.extend(_CheckAndroidXmlStyle(input_api, output_api, False)) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3206 | return results |
| 3207 | |
| 3208 | |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 3209 | def _CommonChecks(input_api, output_api): |
| 3210 | """Checks common to both upload and commit.""" |
| 3211 | results = [] |
| 3212 | results.extend(input_api.canned_checks.PanProjectChecks( |
[email protected] | 3de922f | 2013-12-20 13:27:38 | [diff] [blame] | 3213 | input_api, output_api, |
qyearsley | fa2cfcf8 | 2016-12-15 18:03:54 | [diff] [blame] | 3214 | excluded_paths=_EXCLUDED_PATHS)) |
Eric Boren | 6fd2b93 | 2018-01-25 15:05:08 | [diff] [blame] | 3215 | |
| 3216 | author = input_api.change.author_email |
| 3217 | if author and author not in _KNOWN_ROBOTS: |
| 3218 | results.extend( |
| 3219 | input_api.canned_checks.CheckAuthorizedAuthor(input_api, output_api)) |
| 3220 | |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 3221 | results.extend( |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 3222 | _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
Vaclav Brozek | 7dbc28c | 2018-03-27 08:35:23 | [diff] [blame] | 3223 | results.extend( |
| 3224 | _CheckNoProductionCodeUsingTestOnlyFunctionsJava(input_api, output_api)) |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 3225 | results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 3226 | results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) |
Dominic Battre | 03353105 | 2018-09-24 15:45:34 | [diff] [blame] | 3227 | results.extend(_CheckNoDISABLETypoInTests(input_api, output_api)) |
danakj | 61c1aa2 | 2015-10-26 19:55:52 | [diff] [blame] | 3228 | results.extend(_CheckDCHECK_IS_ONHasBraces(input_api, output_api)) |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 3229 | results.extend(_CheckNoNewWStrings(input_api, output_api)) |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 3230 | results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 3231 | results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 3232 | results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
[email protected] | e747905 | 2012-09-19 00:26:12 | [diff] [blame] | 3233 | results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 3234 | results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 3235 | results.extend(_CheckFilePermissions(input_api, output_api)) |
robertocn | 832f599 | 2017-01-04 19:01:30 | [diff] [blame] | 3236 | results.extend(_CheckTeamTags(input_api, output_api)) |
[email protected] | c8278b3 | 2012-10-30 20:35:49 | [diff] [blame] | 3237 | results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 3238 | results.extend(_CheckForVersionControlConflicts(input_api, output_api)) |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 3239 | results.extend(_CheckPatchFiles(input_api, output_api)) |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 3240 | results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 3241 | results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) |
Kent Tamura | 5a8755d | 2017-06-29 23:37:07 | [diff] [blame] | 3242 | results.extend(_CheckBuildConfigMacrosWithoutInclude(input_api, output_api)) |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 3243 | results.extend(_CheckForInvalidOSMacros(input_api, output_api)) |
lliabraa | 35bab393 | 2014-10-01 12:16:44 | [diff] [blame] | 3244 | results.extend(_CheckForInvalidIfDefinedMacros(input_api, output_api)) |
yolandyan | daabc6d | 2016-04-18 18:29:39 | [diff] [blame] | 3245 | results.extend(_CheckFlakyTestUsage(input_api, output_api)) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 3246 | results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) |
[email protected] | 9f919cc | 2013-07-31 03:04:04 | [diff] [blame] | 3247 | results.extend( |
| 3248 | input_api.canned_checks.CheckChangeHasNoTabs( |
| 3249 | input_api, |
| 3250 | output_api, |
| 3251 | source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 3252 | results.extend(_CheckSpamLogging(input_api, output_api)) |
[email protected] | 49aa76a | 2013-12-04 06:59:16 | [diff] [blame] | 3253 | results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 3254 | results.extend(_CheckUserActionUpdate(input_api, output_api)) |
dbeam | 1ec68ac | 2016-12-15 05:22:24 | [diff] [blame] | 3255 | results.extend(_CheckNoDeprecatedCss(input_api, output_api)) |
| 3256 | results.extend(_CheckNoDeprecatedJs(input_api, output_api)) |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 3257 | results.extend(_CheckParseErrors(input_api, output_api)) |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 3258 | results.extend(_CheckForIPCRules(input_api, output_api)) |
Stephen Martinis | 97a39414 | 2018-06-07 23:06:05 | [diff] [blame] | 3259 | results.extend(_CheckForLongPathnames(input_api, output_api)) |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3260 | results.extend(_CheckForIncludeGuards(input_api, output_api)) |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 3261 | results.extend(_CheckForWindowsLineEndings(input_api, output_api)) |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 3262 | results.extend(_CheckSingletonInHeaders(input_api, output_api)) |
agrieve | f32bcc7 | 2016-04-04 14:57:40 | [diff] [blame] | 3263 | results.extend(_CheckPydepsNeedsUpdating(input_api, output_api)) |
wnwen | bdc444e | 2016-05-25 13:44:15 | [diff] [blame] | 3264 | results.extend(_CheckJavaStyle(input_api, output_api)) |
dcheng | e07de81 | 2016-06-20 19:27:17 | [diff] [blame] | 3265 | results.extend(_CheckIpcOwners(input_api, output_api)) |
jbriance | 9e12f16 | 2016-11-25 07:57:50 | [diff] [blame] | 3266 | results.extend(_CheckUselessForwardDeclarations(input_api, output_api)) |
rlanday | 6802cf63 | 2017-05-30 17:48:36 | [diff] [blame] | 3267 | results.extend(_CheckForRelativeIncludes(input_api, output_api)) |
Takeshi Yoshino | e387aa3 | 2017-08-02 13:16:13 | [diff] [blame] | 3268 | results.extend(_CheckWATCHLISTS(input_api, output_api)) |
Sergiy Byelozyorov | 366b648 | 2017-11-06 18:20:43 | [diff] [blame] | 3269 | results.extend(input_api.RunTests( |
| 3270 | input_api.canned_checks.CheckVPythonSpec(input_api, output_api))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 3271 | results.extend(_CheckTranslationScreenshots(input_api, output_api)) |
Michael Giuffrida | d3bc867 | 2018-10-25 22:48:02 | [diff] [blame] | 3272 | results.extend(_CheckCorrectProductNameInMessages(input_api, output_api)) |
Dirk Pranke | 3c18a38 | 2019-03-15 01:07:51 | [diff] [blame] | 3273 | results.extend(_CheckBuildtoolsRevisionsAreInSync(input_api, output_api)) |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 3274 | |
Vaclav Brozek | cdc7defb | 2018-03-20 09:54:35 | [diff] [blame] | 3275 | for f in input_api.AffectedFiles(): |
| 3276 | path, name = input_api.os_path.split(f.LocalPath()) |
| 3277 | if name == 'PRESUBMIT.py': |
| 3278 | full_path = input_api.os_path.join(input_api.PresubmitLocalPath(), path) |
Caleb Rouleau | a6117be | 2018-05-11 20:10:00 | [diff] [blame] | 3279 | test_file = input_api.os_path.join(path, 'PRESUBMIT_test.py') |
| 3280 | if f.Action() != 'D' and input_api.os_path.exists(test_file): |
Dirk Pranke | 3855731 | 2018-04-18 00:53:07 | [diff] [blame] | 3281 | # The PRESUBMIT.py file (and the directory containing it) might |
| 3282 | # have been affected by being moved or removed, so only try to |
| 3283 | # run the tests if they still exist. |
| 3284 | results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 3285 | input_api, output_api, full_path, |
| 3286 | whitelist=[r'^PRESUBMIT_test\.py$'])) |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 3287 | return results |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 3288 | |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 3289 | |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 3290 | def _CheckPatchFiles(input_api, output_api): |
| 3291 | problems = [f.LocalPath() for f in input_api.AffectedFiles() |
| 3292 | if f.LocalPath().endswith(('.orig', '.rej'))] |
| 3293 | if problems: |
| 3294 | return [output_api.PresubmitError( |
| 3295 | "Don't commit .rej and .orig files.", problems)] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 3296 | else: |
| 3297 | return [] |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 3298 | |
| 3299 | |
Kent Tamura | 5a8755d | 2017-06-29 23:37:07 | [diff] [blame] | 3300 | def _CheckBuildConfigMacrosWithoutInclude(input_api, output_api): |
Kent Tamura | 79ef8f8 | 2017-07-18 00:00:21 | [diff] [blame] | 3301 | # Excludes OS_CHROMEOS, which is not defined in build_config.h. |
| 3302 | macro_re = input_api.re.compile(r'^\s*#(el)?if.*\bdefined\(((OS_(?!CHROMEOS)|' |
| 3303 | 'COMPILER_|ARCH_CPU_|WCHAR_T_IS_)[^)]*)') |
Kent Tamura | 5a8755d | 2017-06-29 23:37:07 | [diff] [blame] | 3304 | include_re = input_api.re.compile( |
| 3305 | r'^#include\s+"build/build_config.h"', input_api.re.MULTILINE) |
| 3306 | extension_re = input_api.re.compile(r'\.[a-z]+$') |
| 3307 | errors = [] |
| 3308 | for f in input_api.AffectedFiles(): |
| 3309 | if not f.LocalPath().endswith(('.h', '.c', '.cc', '.cpp', '.m', '.mm')): |
| 3310 | continue |
| 3311 | found_line_number = None |
| 3312 | found_macro = None |
| 3313 | for line_num, line in f.ChangedContents(): |
| 3314 | match = macro_re.search(line) |
| 3315 | if match: |
| 3316 | found_line_number = line_num |
| 3317 | found_macro = match.group(2) |
| 3318 | break |
| 3319 | if not found_line_number: |
| 3320 | continue |
| 3321 | |
| 3322 | found_include = False |
| 3323 | for line in f.NewContents(): |
| 3324 | if include_re.search(line): |
| 3325 | found_include = True |
| 3326 | break |
| 3327 | if found_include: |
| 3328 | continue |
| 3329 | |
| 3330 | if not f.LocalPath().endswith('.h'): |
| 3331 | primary_header_path = extension_re.sub('.h', f.AbsoluteLocalPath()) |
| 3332 | try: |
| 3333 | content = input_api.ReadFile(primary_header_path, 'r') |
| 3334 | if include_re.search(content): |
| 3335 | continue |
| 3336 | except IOError: |
| 3337 | pass |
| 3338 | errors.append('%s:%d %s macro is used without including build/' |
| 3339 | 'build_config.h.' |
| 3340 | % (f.LocalPath(), found_line_number, found_macro)) |
| 3341 | if errors: |
| 3342 | return [output_api.PresubmitPromptWarning('\n'.join(errors))] |
| 3343 | return [] |
| 3344 | |
| 3345 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 3346 | def _DidYouMeanOSMacro(bad_macro): |
| 3347 | try: |
| 3348 | return {'A': 'OS_ANDROID', |
| 3349 | 'B': 'OS_BSD', |
| 3350 | 'C': 'OS_CHROMEOS', |
| 3351 | 'F': 'OS_FREEBSD', |
| 3352 | 'L': 'OS_LINUX', |
| 3353 | 'M': 'OS_MACOSX', |
| 3354 | 'N': 'OS_NACL', |
| 3355 | 'O': 'OS_OPENBSD', |
| 3356 | 'P': 'OS_POSIX', |
| 3357 | 'S': 'OS_SOLARIS', |
| 3358 | 'W': 'OS_WIN'}[bad_macro[3].upper()] |
| 3359 | except KeyError: |
| 3360 | return '' |
| 3361 | |
| 3362 | |
| 3363 | def _CheckForInvalidOSMacrosInFile(input_api, f): |
| 3364 | """Check for sensible looking, totally invalid OS macros.""" |
| 3365 | preprocessor_statement = input_api.re.compile(r'^\s*#') |
| 3366 | os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)') |
| 3367 | results = [] |
| 3368 | for lnum, line in f.ChangedContents(): |
| 3369 | if preprocessor_statement.search(line): |
| 3370 | for match in os_macro.finditer(line): |
| 3371 | if not match.group(1) in _VALID_OS_MACROS: |
| 3372 | good = _DidYouMeanOSMacro(match.group(1)) |
| 3373 | did_you_mean = ' (did you mean %s?)' % good if good else '' |
| 3374 | results.append(' %s:%d %s%s' % (f.LocalPath(), |
| 3375 | lnum, |
| 3376 | match.group(1), |
| 3377 | did_you_mean)) |
| 3378 | return results |
| 3379 | |
| 3380 | |
| 3381 | def _CheckForInvalidOSMacros(input_api, output_api): |
| 3382 | """Check all affected files for invalid OS macros.""" |
| 3383 | bad_macros = [] |
tzik | 3f29599 | 2018-12-04 20:32:23 | [diff] [blame] | 3384 | for f in input_api.AffectedSourceFiles(None): |
ellyjones | 4765434 | 2016-05-06 15:50:47 | [diff] [blame] | 3385 | if not f.LocalPath().endswith(('.py', '.js', '.html', '.css', '.md')): |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 3386 | bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f)) |
| 3387 | |
| 3388 | if not bad_macros: |
| 3389 | return [] |
| 3390 | |
| 3391 | return [output_api.PresubmitError( |
| 3392 | 'Possibly invalid OS macro[s] found. Please fix your code\n' |
| 3393 | 'or add your macro to src/PRESUBMIT.py.', bad_macros)] |
| 3394 | |
lliabraa | 35bab393 | 2014-10-01 12:16:44 | [diff] [blame] | 3395 | |
| 3396 | def _CheckForInvalidIfDefinedMacrosInFile(input_api, f): |
| 3397 | """Check all affected files for invalid "if defined" macros.""" |
| 3398 | ALWAYS_DEFINED_MACROS = ( |
| 3399 | "TARGET_CPU_PPC", |
| 3400 | "TARGET_CPU_PPC64", |
| 3401 | "TARGET_CPU_68K", |
| 3402 | "TARGET_CPU_X86", |
| 3403 | "TARGET_CPU_ARM", |
| 3404 | "TARGET_CPU_MIPS", |
| 3405 | "TARGET_CPU_SPARC", |
| 3406 | "TARGET_CPU_ALPHA", |
| 3407 | "TARGET_IPHONE_SIMULATOR", |
| 3408 | "TARGET_OS_EMBEDDED", |
| 3409 | "TARGET_OS_IPHONE", |
| 3410 | "TARGET_OS_MAC", |
| 3411 | "TARGET_OS_UNIX", |
| 3412 | "TARGET_OS_WIN32", |
| 3413 | ) |
| 3414 | ifdef_macro = input_api.re.compile(r'^\s*#.*(?:ifdef\s|defined\()([^\s\)]+)') |
| 3415 | results = [] |
| 3416 | for lnum, line in f.ChangedContents(): |
| 3417 | for match in ifdef_macro.finditer(line): |
| 3418 | if match.group(1) in ALWAYS_DEFINED_MACROS: |
| 3419 | always_defined = ' %s is always defined. ' % match.group(1) |
| 3420 | did_you_mean = 'Did you mean \'#if %s\'?' % match.group(1) |
| 3421 | results.append(' %s:%d %s\n\t%s' % (f.LocalPath(), |
| 3422 | lnum, |
| 3423 | always_defined, |
| 3424 | did_you_mean)) |
| 3425 | return results |
| 3426 | |
| 3427 | |
| 3428 | def _CheckForInvalidIfDefinedMacros(input_api, output_api): |
| 3429 | """Check all affected files for invalid "if defined" macros.""" |
| 3430 | bad_macros = [] |
| 3431 | for f in input_api.AffectedFiles(): |
sdefresne | 4e1eccb3 | 2017-05-24 08:45:21 | [diff] [blame] | 3432 | if f.LocalPath().startswith('third_party/sqlite/'): |
| 3433 | continue |
lliabraa | 35bab393 | 2014-10-01 12:16:44 | [diff] [blame] | 3434 | if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): |
| 3435 | bad_macros.extend(_CheckForInvalidIfDefinedMacrosInFile(input_api, f)) |
| 3436 | |
| 3437 | if not bad_macros: |
| 3438 | return [] |
| 3439 | |
| 3440 | return [output_api.PresubmitError( |
| 3441 | 'Found ifdef check on always-defined macro[s]. Please fix your code\n' |
| 3442 | 'or check the list of ALWAYS_DEFINED_MACROS in src/PRESUBMIT.py.', |
| 3443 | bad_macros)] |
| 3444 | |
| 3445 | |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 3446 | def _CheckForIPCRules(input_api, output_api): |
| 3447 | """Check for same IPC rules described in |
| 3448 | http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc |
| 3449 | """ |
| 3450 | base_pattern = r'IPC_ENUM_TRAITS\(' |
| 3451 | inclusion_pattern = input_api.re.compile(r'(%s)' % base_pattern) |
| 3452 | comment_pattern = input_api.re.compile(r'//.*(%s)' % base_pattern) |
| 3453 | |
| 3454 | problems = [] |
| 3455 | for f in input_api.AffectedSourceFiles(None): |
| 3456 | local_path = f.LocalPath() |
| 3457 | if not local_path.endswith('.h'): |
| 3458 | continue |
| 3459 | for line_number, line in f.ChangedContents(): |
| 3460 | if inclusion_pattern.search(line) and not comment_pattern.search(line): |
| 3461 | problems.append( |
| 3462 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
| 3463 | |
| 3464 | if problems: |
| 3465 | return [output_api.PresubmitPromptWarning( |
| 3466 | _IPC_ENUM_TRAITS_DEPRECATED, problems)] |
| 3467 | else: |
| 3468 | return [] |
| 3469 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 3470 | |
Stephen Martinis | 97a39414 | 2018-06-07 23:06:05 | [diff] [blame] | 3471 | def _CheckForLongPathnames(input_api, output_api): |
| 3472 | """Check to make sure no files being submitted have long paths. |
| 3473 | This causes issues on Windows. |
| 3474 | """ |
| 3475 | problems = [] |
| 3476 | for f in input_api.AffectedSourceFiles(None): |
| 3477 | local_path = f.LocalPath() |
| 3478 | # Windows has a path limit of 260 characters. Limit path length to 200 so |
| 3479 | # that we have some extra for the prefix on dev machines and the bots. |
| 3480 | if len(local_path) > 200: |
| 3481 | problems.append(local_path) |
| 3482 | |
| 3483 | if problems: |
| 3484 | return [output_api.PresubmitError(_LONG_PATH_ERROR, problems)] |
| 3485 | else: |
| 3486 | return [] |
| 3487 | |
| 3488 | |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3489 | def _CheckForIncludeGuards(input_api, output_api): |
| 3490 | """Check that header files have proper guards against multiple inclusion. |
| 3491 | If a file should not have such guards (and it probably should) then it |
| 3492 | should include the string "no-include-guard-because-multiply-included". |
| 3493 | """ |
Daniel Bratell | 6a75baef6 | 2018-06-04 10:04:45 | [diff] [blame] | 3494 | def is_chromium_header_file(f): |
| 3495 | # We only check header files under the control of the Chromium |
| 3496 | # project. That is, those outside third_party apart from |
| 3497 | # third_party/blink. |
| 3498 | file_with_path = input_api.os_path.normpath(f.LocalPath()) |
| 3499 | return (file_with_path.endswith('.h') and |
| 3500 | (not file_with_path.startswith('third_party') or |
| 3501 | file_with_path.startswith( |
| 3502 | input_api.os_path.join('third_party', 'blink')))) |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3503 | |
| 3504 | def replace_special_with_underscore(string): |
Olivier Robin | bba13749 | 2018-07-30 11:31:34 | [diff] [blame] | 3505 | return input_api.re.sub(r'[+\\/.-]', '_', string) |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3506 | |
| 3507 | errors = [] |
| 3508 | |
Daniel Bratell | 6a75baef6 | 2018-06-04 10:04:45 | [diff] [blame] | 3509 | for f in input_api.AffectedSourceFiles(is_chromium_header_file): |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3510 | guard_name = None |
| 3511 | guard_line_number = None |
| 3512 | seen_guard_end = False |
| 3513 | |
| 3514 | file_with_path = input_api.os_path.normpath(f.LocalPath()) |
| 3515 | base_file_name = input_api.os_path.splitext( |
| 3516 | input_api.os_path.basename(file_with_path))[0] |
| 3517 | upper_base_file_name = base_file_name.upper() |
| 3518 | |
| 3519 | expected_guard = replace_special_with_underscore( |
| 3520 | file_with_path.upper() + '_') |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3521 | |
| 3522 | # For "path/elem/file_name.h" we should really only accept |
Daniel Bratell | 39b5b06 | 2018-05-16 18:09:57 | [diff] [blame] | 3523 | # PATH_ELEM_FILE_NAME_H_ per coding style. Unfortunately there |
| 3524 | # are too many (1000+) files with slight deviations from the |
| 3525 | # coding style. The most important part is that the include guard |
| 3526 | # is there, and that it's unique, not the name so this check is |
| 3527 | # forgiving for existing files. |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3528 | # |
| 3529 | # As code becomes more uniform, this could be made stricter. |
| 3530 | |
| 3531 | guard_name_pattern_list = [ |
| 3532 | # Anything with the right suffix (maybe with an extra _). |
| 3533 | r'\w+_H__?', |
| 3534 | |
Daniel Bratell | 39b5b06 | 2018-05-16 18:09:57 | [diff] [blame] | 3535 | # To cover include guards with old Blink style. |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3536 | r'\w+_h', |
| 3537 | |
| 3538 | # Anything including the uppercase name of the file. |
| 3539 | r'\w*' + input_api.re.escape(replace_special_with_underscore( |
| 3540 | upper_base_file_name)) + r'\w*', |
| 3541 | ] |
| 3542 | guard_name_pattern = '|'.join(guard_name_pattern_list) |
| 3543 | guard_pattern = input_api.re.compile( |
| 3544 | r'#ifndef\s+(' + guard_name_pattern + ')') |
| 3545 | |
| 3546 | for line_number, line in enumerate(f.NewContents()): |
| 3547 | if 'no-include-guard-because-multiply-included' in line: |
| 3548 | guard_name = 'DUMMY' # To not trigger check outside the loop. |
| 3549 | break |
| 3550 | |
| 3551 | if guard_name is None: |
| 3552 | match = guard_pattern.match(line) |
| 3553 | if match: |
| 3554 | guard_name = match.group(1) |
| 3555 | guard_line_number = line_number |
| 3556 | |
Daniel Bratell | 39b5b06 | 2018-05-16 18:09:57 | [diff] [blame] | 3557 | # We allow existing files to use include guards whose names |
Daniel Bratell | 6a75baef6 | 2018-06-04 10:04:45 | [diff] [blame] | 3558 | # don't match the chromium style guide, but new files should |
| 3559 | # get it right. |
| 3560 | if not f.OldContents(): |
Daniel Bratell | 39b5b06 | 2018-05-16 18:09:57 | [diff] [blame] | 3561 | if guard_name != expected_guard: |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3562 | errors.append(output_api.PresubmitPromptWarning( |
| 3563 | 'Header using the wrong include guard name %s' % guard_name, |
| 3564 | ['%s:%d' % (f.LocalPath(), line_number + 1)], |
Daniel Bratell | 39b5b06 | 2018-05-16 18:09:57 | [diff] [blame] | 3565 | 'Expected: %r\nFound: %r' % (expected_guard, guard_name))) |
Daniel Bratell | 8ba5272 | 2018-03-02 16:06:14 | [diff] [blame] | 3566 | else: |
| 3567 | # The line after #ifndef should have a #define of the same name. |
| 3568 | if line_number == guard_line_number + 1: |
| 3569 | expected_line = '#define %s' % guard_name |
| 3570 | if line != expected_line: |
| 3571 | errors.append(output_api.PresubmitPromptWarning( |
| 3572 | 'Missing "%s" for include guard' % expected_line, |
| 3573 | ['%s:%d' % (f.LocalPath(), line_number + 1)], |
| 3574 | 'Expected: %r\nGot: %r' % (expected_line, line))) |
| 3575 | |
| 3576 | if not seen_guard_end and line == '#endif // %s' % guard_name: |
| 3577 | seen_guard_end = True |
| 3578 | elif seen_guard_end: |
| 3579 | if line.strip() != '': |
| 3580 | errors.append(output_api.PresubmitPromptWarning( |
| 3581 | 'Include guard %s not covering the whole file' % ( |
| 3582 | guard_name), [f.LocalPath()])) |
| 3583 | break # Nothing else to check and enough to warn once. |
| 3584 | |
| 3585 | if guard_name is None: |
| 3586 | errors.append(output_api.PresubmitPromptWarning( |
| 3587 | 'Missing include guard %s' % expected_guard, |
| 3588 | [f.LocalPath()], |
| 3589 | 'Missing include guard in %s\n' |
| 3590 | 'Recommended name: %s\n' |
| 3591 | 'This check can be disabled by having the string\n' |
| 3592 | 'no-include-guard-because-multiply-included in the header.' % |
| 3593 | (f.LocalPath(), expected_guard))) |
| 3594 | |
| 3595 | return errors |
| 3596 | |
| 3597 | |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 3598 | def _CheckForWindowsLineEndings(input_api, output_api): |
| 3599 | """Check source code and known ascii text files for Windows style line |
| 3600 | endings. |
| 3601 | """ |
earthdok | 1b5e0ee | 2015-03-10 15:19:10 | [diff] [blame] | 3602 | known_text_files = r'.*\.(txt|html|htm|mhtml|py|gyp|gypi|gn|isolate)$' |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 3603 | |
| 3604 | file_inclusion_pattern = ( |
| 3605 | known_text_files, |
| 3606 | r'.+%s' % _IMPLEMENTATION_EXTENSIONS |
| 3607 | ) |
| 3608 | |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 3609 | problems = [] |
Andrew Grieve | 933d12e | 2017-10-30 20:22:53 | [diff] [blame] | 3610 | source_file_filter = lambda f: input_api.FilterSourceFile( |
| 3611 | f, white_list=file_inclusion_pattern, black_list=None) |
| 3612 | for f in input_api.AffectedSourceFiles(source_file_filter): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 3613 | include_file = False |
| 3614 | for _, line in f.ChangedContents(): |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 3615 | if line.endswith('\r\n'): |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 3616 | include_file = True |
| 3617 | if include_file: |
| 3618 | problems.append(f.LocalPath()) |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 3619 | |
| 3620 | if problems: |
| 3621 | return [output_api.PresubmitPromptWarning('Are you sure that you want ' |
| 3622 | 'these files to contain Windows style line endings?\n' + |
| 3623 | '\n'.join(problems))] |
| 3624 | |
| 3625 | return [] |
| 3626 | |
| 3627 | |
Vaclav Brozek | d5de76a | 2018-03-17 07:57:50 | [diff] [blame] | 3628 | def _CheckSyslogUseWarning(input_api, output_api, source_file_filter=None): |
pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 3629 | """Checks that all source files use SYSLOG properly.""" |
| 3630 | syslog_files = [] |
| 3631 | for f in input_api.AffectedSourceFiles(source_file_filter): |
pastarmovj | 032ba5bc | 2017-01-12 10:41:56 | [diff] [blame] | 3632 | for line_number, line in f.ChangedContents(): |
| 3633 | if 'SYSLOG' in line: |
| 3634 | syslog_files.append(f.LocalPath() + ':' + str(line_number)) |
| 3635 | |
pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 3636 | if syslog_files: |
| 3637 | return [output_api.PresubmitPromptWarning( |
| 3638 | 'Please make sure there are no privacy sensitive bits of data in SYSLOG' |
| 3639 | ' calls.\nFiles to check:\n', items=syslog_files)] |
| 3640 | return [] |
| 3641 | |
| 3642 | |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 3643 | def CheckChangeOnUpload(input_api, output_api): |
| 3644 | results = [] |
| 3645 | results.extend(_CommonChecks(input_api, output_api)) |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 3646 | results.extend(_CheckValidHostsInDEPS(input_api, output_api)) |
scottmg | 39b2995 | 2014-12-08 18:31:28 | [diff] [blame] | 3647 | results.extend( |
jam | 93a6ee79 | 2017-02-08 23:59:22 | [diff] [blame] | 3648 | input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 3649 | results.extend(_CheckUmaHistogramChanges(input_api, output_api)) |
dgn | aa68d5e | 2015-06-10 10:08:22 | [diff] [blame] | 3650 | results.extend(_AndroidSpecificOnUploadChecks(input_api, output_api)) |
pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 3651 | results.extend(_CheckSyslogUseWarning(input_api, output_api)) |
estade | e17314a0 | 2017-01-12 16:22:16 | [diff] [blame] | 3652 | results.extend(_CheckGoogleSupportAnswerUrl(input_api, output_api)) |
Vaclav Brozek | ea41ab2 | 2018-04-06 13:21:53 | [diff] [blame] | 3653 | results.extend(_CheckUniquePtr(input_api, output_api)) |
Wei-Yin Chen (陳威尹) | c0624d00 | 2018-07-30 18:22:19 | [diff] [blame] | 3654 | results.extend(_CheckNewHeaderWithoutGnChange(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 3655 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 3656 | |
| 3657 | |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 3658 | def GetTryServerMasterForBot(bot): |
| 3659 | """Returns the Try Server master for the given bot. |
| 3660 | |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 3661 | It tries to guess the master from the bot name, but may still fail |
| 3662 | and return None. There is no longer a default master. |
| 3663 | """ |
| 3664 | # Potentially ambiguous bot names are listed explicitly. |
| 3665 | master_map = { |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 3666 | 'chromium_presubmit': 'master.tryserver.chromium.linux', |
| 3667 | 'tools_build_presubmit': 'master.tryserver.chromium.linux', |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 3668 | } |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 3669 | master = master_map.get(bot) |
| 3670 | if not master: |
wnwen | 4fbaab8 | 2016-05-25 12:54:36 | [diff] [blame] | 3671 | if 'android' in bot: |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 3672 | master = 'master.tryserver.chromium.android' |
wnwen | 4fbaab8 | 2016-05-25 12:54:36 | [diff] [blame] | 3673 | elif 'linux' in bot or 'presubmit' in bot: |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 3674 | master = 'master.tryserver.chromium.linux' |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 3675 | elif 'win' in bot: |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 3676 | master = 'master.tryserver.chromium.win' |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 3677 | elif 'mac' in bot or 'ios' in bot: |
tandrii | e558779 | 2016-07-14 00:34:50 | [diff] [blame] | 3678 | master = 'master.tryserver.chromium.mac' |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 3679 | return master |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 3680 | |
| 3681 | |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 3682 | def CheckChangeOnCommit(input_api, output_api): |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 3683 | results = [] |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 3684 | results.extend(_CommonChecks(input_api, output_api)) |
Becky Zhou | 7c69b5099 | 2018-12-10 19:37:57 | [diff] [blame] | 3685 | results.extend(_AndroidSpecificOnCommitChecks(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 3686 | # Make sure the tree is 'open'. |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 3687 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
[email protected] | 7f23815 | 2009-08-12 19:00:34 | [diff] [blame] | 3688 | input_api, |
| 3689 | output_api, |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 3690 | json_url='http://chromium-status.appspot.com/current?format=json')) |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 3691 | |
jam | 93a6ee79 | 2017-02-08 23:59:22 | [diff] [blame] | 3692 | results.extend( |
| 3693 | input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 3694 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 3695 | input_api, output_api)) |
[email protected] | c4b4756 | 2011-12-05 23:39:41 | [diff] [blame] | 3696 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 3697 | input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 3698 | return results |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 3699 | |
| 3700 | |
| 3701 | def _CheckTranslationScreenshots(input_api, output_api): |
| 3702 | PART_FILE_TAG = "part" |
| 3703 | import os |
| 3704 | import sys |
| 3705 | from io import StringIO |
| 3706 | |
| 3707 | try: |
| 3708 | old_sys_path = sys.path |
| 3709 | sys.path = sys.path + [input_api.os_path.join( |
| 3710 | input_api.PresubmitLocalPath(), 'tools', 'grit')] |
| 3711 | import grit.grd_reader |
| 3712 | import grit.node.message |
| 3713 | import grit.util |
| 3714 | finally: |
| 3715 | sys.path = old_sys_path |
| 3716 | |
| 3717 | def _GetGrdMessages(grd_path_or_string, dir_path='.'): |
| 3718 | """Load the grd file and return a dict of message ids to messages. |
| 3719 | |
| 3720 | Ignores any nested grdp files pointed by <part> tag. |
| 3721 | """ |
| 3722 | doc = grit.grd_reader.Parse(grd_path_or_string, dir_path, |
| 3723 | stop_after=None, first_ids_file=None, |
| 3724 | debug=False, defines=None, |
| 3725 | tags_to_ignore=set([PART_FILE_TAG])) |
| 3726 | return { |
| 3727 | msg.attrs['name']:msg for msg in doc.GetChildrenOfType( |
| 3728 | grit.node.message.MessageNode) |
| 3729 | } |
| 3730 | |
| 3731 | def _GetGrdpMessagesFromString(grdp_string): |
| 3732 | """Parses the contents of a grdp file given in grdp_string. |
| 3733 | |
| 3734 | grd_reader can't parse grdp files directly. Instead, this creates a |
| 3735 | temporary directory with a grd file pointing to the grdp file, and loads the |
| 3736 | grd from there. Any nested grdp files (pointed by <part> tag) are ignored. |
| 3737 | """ |
| 3738 | WRAPPER = """<?xml version="1.0" encoding="utf-8"?> |
| 3739 | <grit latest_public_release="1" current_release="1"> |
| 3740 | <release seq="1"> |
| 3741 | <messages> |
| 3742 | <part file="sub.grdp" /> |
| 3743 | </messages> |
| 3744 | </release> |
| 3745 | </grit> |
| 3746 | """ |
| 3747 | with grit.util.TempDir({'main.grd': WRAPPER, |
| 3748 | 'sub.grdp': grdp_string}) as temp_dir: |
| 3749 | return _GetGrdMessages(temp_dir.GetPath('main.grd'), temp_dir.GetPath()) |
| 3750 | |
| 3751 | new_or_added_paths = set(f.LocalPath() |
| 3752 | for f in input_api.AffectedFiles() |
| 3753 | if (f.Action() == 'A' or f.Action() == 'M')) |
| 3754 | removed_paths = set(f.LocalPath() |
| 3755 | for f in input_api.AffectedFiles(include_deletes=True) |
| 3756 | if f.Action() == 'D') |
| 3757 | |
| 3758 | affected_grds = [f for f in input_api.AffectedFiles() |
| 3759 | if (f.LocalPath().endswith('.grd') or |
| 3760 | f.LocalPath().endswith('.grdp'))] |
| 3761 | affected_png_paths = [f.AbsoluteLocalPath() |
| 3762 | for f in input_api.AffectedFiles() |
| 3763 | if (f.LocalPath().endswith('.png'))] |
| 3764 | |
| 3765 | # Check for screenshots. Developers can upload screenshots using |
| 3766 | # tools/translation/upload_screenshots.py which finds and uploads |
| 3767 | # images associated with .grd files (e.g. test_grd/IDS_STRING.png for the |
| 3768 | # message named IDS_STRING in test.grd) and produces a .sha1 file (e.g. |
| 3769 | # test_grd/IDS_STRING.png.sha1) for each png when the upload is successful. |
| 3770 | # |
| 3771 | # The logic here is as follows: |
| 3772 | # |
| 3773 | # - If the CL has a .png file under the screenshots directory for a grd |
| 3774 | # file, warn the developer. Actual images should never be checked into the |
| 3775 | # Chrome repo. |
| 3776 | # |
| 3777 | # - If the CL contains modified or new messages in grd files and doesn't |
| 3778 | # contain the corresponding .sha1 files, warn the developer to add images |
| 3779 | # and upload them via tools/translation/upload_screenshots.py. |
| 3780 | # |
| 3781 | # - If the CL contains modified or new messages in grd files and the |
| 3782 | # corresponding .sha1 files, everything looks good. |
| 3783 | # |
| 3784 | # - If the CL contains removed messages in grd files but the corresponding |
| 3785 | # .sha1 files aren't removed, warn the developer to remove them. |
| 3786 | unnecessary_screenshots = [] |
| 3787 | missing_sha1 = [] |
| 3788 | unnecessary_sha1_files = [] |
| 3789 | |
| 3790 | |
| 3791 | def _CheckScreenshotAdded(screenshots_dir, message_id): |
| 3792 | sha1_path = input_api.os_path.join( |
| 3793 | screenshots_dir, message_id + '.png.sha1') |
| 3794 | if sha1_path not in new_or_added_paths: |
| 3795 | missing_sha1.append(sha1_path) |
| 3796 | |
| 3797 | |
| 3798 | def _CheckScreenshotRemoved(screenshots_dir, message_id): |
| 3799 | sha1_path = input_api.os_path.join( |
| 3800 | screenshots_dir, message_id + '.png.sha1') |
| 3801 | if sha1_path not in removed_paths: |
| 3802 | unnecessary_sha1_files.append(sha1_path) |
| 3803 | |
| 3804 | |
| 3805 | for f in affected_grds: |
| 3806 | file_path = f.LocalPath() |
| 3807 | old_id_to_msg_map = {} |
| 3808 | new_id_to_msg_map = {} |
| 3809 | if file_path.endswith('.grdp'): |
| 3810 | if f.OldContents(): |
| 3811 | old_id_to_msg_map = _GetGrdpMessagesFromString( |
Mustafa Emre Acer | c8a012d | 2018-07-31 00:00:39 | [diff] [blame] | 3812 | unicode('\n'.join(f.OldContents()))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 3813 | if f.NewContents(): |
| 3814 | new_id_to_msg_map = _GetGrdpMessagesFromString( |
Mustafa Emre Acer | c8a012d | 2018-07-31 00:00:39 | [diff] [blame] | 3815 | unicode('\n'.join(f.NewContents()))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 3816 | else: |
| 3817 | if f.OldContents(): |
| 3818 | old_id_to_msg_map = _GetGrdMessages( |
Mustafa Emre Acer | c8a012d | 2018-07-31 00:00:39 | [diff] [blame] | 3819 | StringIO(unicode('\n'.join(f.OldContents())))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 3820 | if f.NewContents(): |
| 3821 | new_id_to_msg_map = _GetGrdMessages( |
Mustafa Emre Acer | c8a012d | 2018-07-31 00:00:39 | [diff] [blame] | 3822 | StringIO(unicode('\n'.join(f.NewContents())))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 3823 | |
| 3824 | # Compute added, removed and modified message IDs. |
| 3825 | old_ids = set(old_id_to_msg_map) |
| 3826 | new_ids = set(new_id_to_msg_map) |
| 3827 | added_ids = new_ids - old_ids |
| 3828 | removed_ids = old_ids - new_ids |
| 3829 | modified_ids = set([]) |
| 3830 | for key in old_ids.intersection(new_ids): |
| 3831 | if (old_id_to_msg_map[key].FormatXml() |
| 3832 | != new_id_to_msg_map[key].FormatXml()): |
| 3833 | modified_ids.add(key) |
| 3834 | |
| 3835 | grd_name, ext = input_api.os_path.splitext( |
| 3836 | input_api.os_path.basename(file_path)) |
| 3837 | screenshots_dir = input_api.os_path.join( |
| 3838 | input_api.os_path.dirname(file_path), grd_name + ext.replace('.', '_')) |
| 3839 | |
| 3840 | # Check the screenshot directory for .png files. Warn if there is any. |
| 3841 | for png_path in affected_png_paths: |
| 3842 | if png_path.startswith(screenshots_dir): |
| 3843 | unnecessary_screenshots.append(png_path) |
| 3844 | |
| 3845 | for added_id in added_ids: |
| 3846 | _CheckScreenshotAdded(screenshots_dir, added_id) |
| 3847 | |
| 3848 | for modified_id in modified_ids: |
| 3849 | _CheckScreenshotAdded(screenshots_dir, modified_id) |
| 3850 | |
| 3851 | for removed_id in removed_ids: |
| 3852 | _CheckScreenshotRemoved(screenshots_dir, removed_id) |
| 3853 | |
| 3854 | results = [] |
| 3855 | if unnecessary_screenshots: |
| 3856 | results.append(output_api.PresubmitNotifyResult( |
Mustafa Emre Acer | c8a012d | 2018-07-31 00:00:39 | [diff] [blame] | 3857 | 'Do not include actual screenshots in the changelist. Run ' |
| 3858 | 'tools/translate/upload_screenshots.py to upload them instead:', |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 3859 | sorted(unnecessary_screenshots))) |
| 3860 | |
| 3861 | if missing_sha1: |
| 3862 | results.append(output_api.PresubmitNotifyResult( |
Mustafa Emre Acer | c8a012d | 2018-07-31 00:00:39 | [diff] [blame] | 3863 | 'You are adding or modifying UI strings.\n' |
| 3864 | 'To ensure the best translations, take screenshots of the relevant UI ' |
| 3865 | '(https://g.co/chrome/translation) and add these files to your ' |
| 3866 | 'changelist:', sorted(missing_sha1))) |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 3867 | |
| 3868 | if unnecessary_sha1_files: |
| 3869 | results.append(output_api.PresubmitNotifyResult( |
Mustafa Emre Acer | c8a012d | 2018-07-31 00:00:39 | [diff] [blame] | 3870 | 'You removed strings associated with these files. Remove:', |
Mustafa Emre Acer | 29bf6ac9 | 2018-07-30 21:42:14 | [diff] [blame] | 3871 | sorted(unnecessary_sha1_files))) |
| 3872 | |
| 3873 | return results |