[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 = ( |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 13 | r"^breakpad[\\\/].*", |
[email protected] | 40d1dbb | 2012-10-26 07:18:00 | [diff] [blame] | 14 | r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py", |
| 15 | r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py", |
[email protected] | 8886ffcb | 2013-02-12 04:56:28 | [diff] [blame] | 16 | r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk", |
[email protected] | a18130a | 2012-01-03 17:52:08 | [diff] [blame] | 17 | r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 18 | r"^skia[\\\/].*", |
| 19 | r"^v8[\\\/].*", |
| 20 | r".*MakeFile$", |
[email protected] | 1084ccc | 2012-03-14 03:22:53 | [diff] [blame] | 21 | r".+_autogen\.h$", |
[email protected] | ce145c0 | 2012-09-06 09:49:34 | [diff] [blame] | 22 | r".+[\\\/]pnacl_shim\.c$", |
[email protected] | e07b6ac7 | 2013-08-20 00:30:42 | [diff] [blame] | 23 | r"^gpu[\\\/]config[\\\/].*_list_json\.cc$", |
[email protected] | d260060 | 2014-02-19 00:09:19 | [diff] [blame] | 24 | r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js" |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 25 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 26 | |
jochen | 9ea8fdbc | 2014-09-25 13:21:35 | [diff] [blame] | 27 | # The NetscapePlugIn library is excluded from pan-project as it will soon |
| 28 | # be deleted together with the rest of the NPAPI and it's not worthwhile to |
| 29 | # update the coding style until then. |
[email protected] | 3de922f | 2013-12-20 13:27:38 | [diff] [blame] | 30 | _TESTRUNNER_PATHS = ( |
[email protected] | de28fed2e | 2014-02-01 14:36:32 | [diff] [blame] | 31 | r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*", |
[email protected] | 3de922f | 2013-12-20 13:27:38 | [diff] [blame] | 32 | ) |
| 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 | |
| 38 | # Regular expression that matches code only used for test binaries |
| 39 | # (best effort). |
| 40 | _TEST_CODE_EXCLUDED_PATHS = ( |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 41 | r'.*[\\\/](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS, |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 42 | r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS, |
[email protected] | 6e04f8c | 2014-01-29 18:08:32 | [diff] [blame] | 43 | r'.+_(api|browser|kif|perf|pixel|unit|ui)?test(_[a-z]+)?%s' % |
[email protected] | e2d7e6f | 2013-04-23 12:57:12 | [diff] [blame] | 44 | _IMPLEMENTATION_EXTENSIONS, |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 45 | r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS, |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 46 | r'.*[\\\/](test|tool(s)?)[\\\/].*', |
[email protected] | ef070cc | 2013-05-03 11:53:05 | [diff] [blame] | 47 | # content_shell is used for running layout tests. |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 48 | r'content[\\\/]shell[\\\/].*', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 49 | # At request of folks maintaining this folder. |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 50 | r'chrome[\\\/]browser[\\\/]automation[\\\/].*', |
[email protected] | 7b05498 | 2013-11-27 00:44:47 | [diff] [blame] | 51 | # Non-production example code. |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 52 | r'mojo[\\\/]examples[\\\/].*', |
[email protected] | 8176de1 | 2014-06-20 19:07:08 | [diff] [blame] | 53 | # Launcher for running iOS tests on the simulator. |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 54 | r'testing[\\\/]iossim[\\\/]iossim\.mm$', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 55 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 56 | |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 57 | _TEST_ONLY_WARNING = ( |
| 58 | 'You might be calling functions intended only for testing from\n' |
| 59 | 'production code. It is OK to ignore this warning if you know what\n' |
| 60 | 'you are doing, as the heuristics used to detect the situation are\n' |
[email protected] | b014977 | 2014-03-27 16:47:58 | [diff] [blame] | 61 | 'not perfect. The commit queue will not block on this warning.') |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 62 | |
| 63 | |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 64 | _INCLUDE_ORDER_WARNING = ( |
marja | a017dc48 | 2015-03-09 17:13:40 | [diff] [blame] | 65 | 'Your #include order seems to be broken. Remember to use the right ' |
| 66 | 'collation (LC_COLLATE=C) and check https://google-styleguide.googlecode' |
| 67 | '.com/svn/trunk/cppguide.html#Names_and_Order_of_Includes') |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 68 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 69 | _BANNED_OBJC_FUNCTIONS = ( |
| 70 | ( |
| 71 | 'addTrackingRect:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 72 | ( |
| 73 | 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 74 | 'prohibited. Please use CrTrackingArea instead.', |
| 75 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 76 | ), |
| 77 | False, |
| 78 | ), |
| 79 | ( |
[email protected] | eaae197 | 2014-04-16 04:17:26 | [diff] [blame] | 80 | r'/NSTrackingArea\W', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 81 | ( |
| 82 | 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 83 | 'instead.', |
| 84 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 85 | ), |
| 86 | False, |
| 87 | ), |
| 88 | ( |
| 89 | 'convertPointFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 90 | ( |
| 91 | 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 92 | 'Please use |convertPoint:(point) fromView:nil| instead.', |
| 93 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 94 | ), |
| 95 | True, |
| 96 | ), |
| 97 | ( |
| 98 | 'convertPointToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 99 | ( |
| 100 | 'The use of -[NSView convertPointToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 101 | 'Please use |convertPoint:(point) toView:nil| instead.', |
| 102 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 103 | ), |
| 104 | True, |
| 105 | ), |
| 106 | ( |
| 107 | 'convertRectFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 108 | ( |
| 109 | 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 110 | 'Please use |convertRect:(point) fromView:nil| instead.', |
| 111 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 112 | ), |
| 113 | True, |
| 114 | ), |
| 115 | ( |
| 116 | 'convertRectToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 117 | ( |
| 118 | 'The use of -[NSView convertRectToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 119 | 'Please use |convertRect:(point) toView:nil| instead.', |
| 120 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 121 | ), |
| 122 | True, |
| 123 | ), |
| 124 | ( |
| 125 | 'convertSizeFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 126 | ( |
| 127 | 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 128 | 'Please use |convertSize:(point) fromView:nil| instead.', |
| 129 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 130 | ), |
| 131 | True, |
| 132 | ), |
| 133 | ( |
| 134 | 'convertSizeToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 135 | ( |
| 136 | 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 137 | 'Please use |convertSize:(point) toView:nil| instead.', |
| 138 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 139 | ), |
| 140 | True, |
| 141 | ), |
| 142 | ) |
| 143 | |
| 144 | |
| 145 | _BANNED_CPP_FUNCTIONS = ( |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 146 | # Make sure that gtest's FRIEND_TEST() macro is not used; the |
| 147 | # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be |
[email protected] | e00ccc9 | 2012-11-01 17:32:30 | [diff] [blame] | 148 | # used instead since that allows for FLAKY_ and DISABLED_ prefixes. |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 149 | ( |
| 150 | 'FRIEND_TEST(', |
| 151 | ( |
[email protected] | e3c94550 | 2012-06-26 20:01:49 | [diff] [blame] | 152 | 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 153 | 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.', |
| 154 | ), |
| 155 | False, |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 156 | (), |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 157 | ), |
| 158 | ( |
| 159 | 'ScopedAllowIO', |
| 160 | ( |
[email protected] | e3c94550 | 2012-06-26 20:01:49 | [diff] [blame] | 161 | 'New code should not use ScopedAllowIO. Post a task to the blocking', |
| 162 | 'pool or the FILE thread instead.', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 163 | ), |
[email protected] | e3c94550 | 2012-06-26 20:01:49 | [diff] [blame] | 164 | True, |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 165 | ( |
thestig | 75844fdb | 2014-09-09 19:47:10 | [diff] [blame] | 166 | r"^base[\\\/]process[\\\/]process_metrics_linux\.cc$", |
tfarina | 0923ac5 | 2015-01-07 03:21:22 | [diff] [blame] | 167 | r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]boot_times_recorder\.cc$", |
alemate | e4016bb | 2014-11-12 17:38:51 | [diff] [blame] | 168 | r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]" |
| 169 | "customization_document_browsertest\.cc$", |
philipj | 3f9d5bde | 2014-08-28 14:09:09 | [diff] [blame] | 170 | r"^components[\\\/]crash[\\\/]app[\\\/]breakpad_mac\.mm$", |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 171 | r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$", |
| 172 | r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$", |
jamesr | a03ae49 | 2014-10-03 04:26:48 | [diff] [blame] | 173 | r"^mojo[\\\/]edk[\\\/]embedder[\\\/]" + |
| 174 | r"simple_platform_shared_buffer_posix\.cc$", |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 175 | r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$", |
[email protected] | 1f52a57 | 2014-05-12 23:21:54 | [diff] [blame] | 176 | r"^net[\\\/]url_request[\\\/]test_url_fetcher_factory\.cc$", |
dnicoara | 171d8c8 | 2015-03-05 20:46:18 | [diff] [blame] | 177 | r"^ui[\\\/]ozone[\\\/]platform[\\\/]drm[\\\/]host[\\\/]" |
| 178 | "drm_native_display_delegate\.cc$", |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 179 | ), |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame] | 180 | ), |
[email protected] | 52657f6 | 2013-05-20 05:30:31 | [diff] [blame] | 181 | ( |
| 182 | 'SkRefPtr', |
| 183 | ( |
| 184 | 'The use of SkRefPtr is prohibited. ', |
| 185 | 'Please use skia::RefPtr instead.' |
| 186 | ), |
| 187 | True, |
| 188 | (), |
| 189 | ), |
| 190 | ( |
| 191 | 'SkAutoRef', |
| 192 | ( |
| 193 | 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ', |
| 194 | 'Please use skia::RefPtr instead.' |
| 195 | ), |
| 196 | True, |
| 197 | (), |
| 198 | ), |
| 199 | ( |
| 200 | 'SkAutoTUnref', |
| 201 | ( |
| 202 | 'The use of SkAutoTUnref is dangerous because it implicitly ', |
| 203 | 'converts to a raw pointer. Please use skia::RefPtr instead.' |
| 204 | ), |
| 205 | True, |
| 206 | (), |
| 207 | ), |
| 208 | ( |
| 209 | 'SkAutoUnref', |
| 210 | ( |
| 211 | 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ', |
| 212 | 'because it implicitly converts to a raw pointer. ', |
| 213 | 'Please use skia::RefPtr instead.' |
| 214 | ), |
| 215 | True, |
| 216 | (), |
| 217 | ), |
[email protected] | d89eec8 | 2013-12-03 14:10:59 | [diff] [blame] | 218 | ( |
| 219 | r'/HANDLE_EINTR\(.*close', |
| 220 | ( |
| 221 | 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file', |
| 222 | 'descriptor will be closed, and it is incorrect to retry the close.', |
| 223 | 'Either call close directly and ignore its return value, or wrap close', |
| 224 | 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623' |
| 225 | ), |
| 226 | True, |
| 227 | (), |
| 228 | ), |
| 229 | ( |
| 230 | r'/IGNORE_EINTR\((?!.*close)', |
| 231 | ( |
| 232 | 'IGNORE_EINTR is only valid when wrapping close. To wrap other system', |
| 233 | 'calls, use HANDLE_EINTR. See http://crbug.com/269623', |
| 234 | ), |
| 235 | True, |
| 236 | ( |
| 237 | # Files that #define IGNORE_EINTR. |
| 238 | r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$', |
| 239 | r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$', |
| 240 | ), |
| 241 | ), |
[email protected] | ec5b3f0 | 2014-04-04 18:43:43 | [diff] [blame] | 242 | ( |
| 243 | r'/v8::Extension\(', |
| 244 | ( |
| 245 | 'Do not introduce new v8::Extensions into the code base, use', |
| 246 | 'gin::Wrappable instead. See http://crbug.com/334679', |
| 247 | ), |
| 248 | True, |
[email protected] | f55c90ee6 | 2014-04-12 00:50:03 | [diff] [blame] | 249 | ( |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 250 | r'extensions[\\\/]renderer[\\\/]safe_builtins\.*', |
[email protected] | f55c90ee6 | 2014-04-12 00:50:03 | [diff] [blame] | 251 | ), |
[email protected] | ec5b3f0 | 2014-04-04 18:43:43 | [diff] [blame] | 252 | ), |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 253 | ) |
| 254 | |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 255 | _IPC_ENUM_TRAITS_DEPRECATED = ( |
| 256 | 'You are using IPC_ENUM_TRAITS() in your code. It has been deprecated.\n' |
| 257 | 'See http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc') |
| 258 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 259 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 260 | _VALID_OS_MACROS = ( |
| 261 | # Please keep sorted. |
| 262 | 'OS_ANDROID', |
[email protected] | f4440b4 | 2014-03-19 05:47:01 | [diff] [blame] | 263 | 'OS_ANDROID_HOST', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 264 | 'OS_BSD', |
| 265 | 'OS_CAT', # For testing. |
| 266 | 'OS_CHROMEOS', |
| 267 | 'OS_FREEBSD', |
| 268 | 'OS_IOS', |
| 269 | 'OS_LINUX', |
| 270 | 'OS_MACOSX', |
| 271 | 'OS_NACL', |
hidehiko | f7295f2 | 2014-10-28 11:57:21 | [diff] [blame] | 272 | 'OS_NACL_NONSFI', |
| 273 | 'OS_NACL_SFI', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 274 | 'OS_OPENBSD', |
| 275 | 'OS_POSIX', |
[email protected] | eda7afa1 | 2014-02-06 12:27:37 | [diff] [blame] | 276 | 'OS_QNX', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 277 | 'OS_SOLARIS', |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 278 | 'OS_WIN', |
| 279 | ) |
| 280 | |
| 281 | |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 282 | def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): |
| 283 | """Attempts to prevent use of functions intended only for testing in |
| 284 | non-testing code. For now this is just a best-effort implementation |
| 285 | that ignores header files and may have some false positives. A |
| 286 | better implementation would probably need a proper C++ parser. |
| 287 | """ |
| 288 | # We only scan .cc files and the like, as the declaration of |
| 289 | # for-testing functions in header files are hard to distinguish from |
| 290 | # calls to such functions without a proper C++ parser. |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 291 | file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 292 | |
[email protected] | 2350182 | 2014-05-14 02:06:09 | [diff] [blame] | 293 | base_function_pattern = r'[ :]test::[^\s]+|ForTest(ing)?|for_test(ing)?' |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 294 | inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern) |
[email protected] | 2350182 | 2014-05-14 02:06:09 | [diff] [blame] | 295 | comment_pattern = input_api.re.compile(r'//.*(%s)' % base_function_pattern) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 296 | exclusion_pattern = input_api.re.compile( |
| 297 | r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % ( |
| 298 | base_function_pattern, base_function_pattern)) |
| 299 | |
| 300 | def FilterFile(affected_file): |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 301 | black_list = (_EXCLUDED_PATHS + |
| 302 | _TEST_CODE_EXCLUDED_PATHS + |
| 303 | input_api.DEFAULT_BLACK_LIST) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 304 | return input_api.FilterSourceFile( |
| 305 | affected_file, |
| 306 | white_list=(file_inclusion_pattern, ), |
| 307 | black_list=black_list) |
| 308 | |
| 309 | problems = [] |
| 310 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 311 | local_path = f.LocalPath() |
[email protected] | 825d2718 | 2014-01-02 21:24:24 | [diff] [blame] | 312 | for line_number, line in f.ChangedContents(): |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 313 | if (inclusion_pattern.search(line) and |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 314 | not comment_pattern.search(line) and |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 315 | not exclusion_pattern.search(line)): |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 316 | problems.append( |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 317 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 318 | |
| 319 | if problems: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 320 | return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 321 | else: |
| 322 | return [] |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 323 | |
| 324 | |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 325 | def _CheckNoIOStreamInHeaders(input_api, output_api): |
| 326 | """Checks to make sure no .h files include <iostream>.""" |
| 327 | files = [] |
| 328 | pattern = input_api.re.compile(r'^#include\s*<iostream>', |
| 329 | input_api.re.MULTILINE) |
| 330 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 331 | if not f.LocalPath().endswith('.h'): |
| 332 | continue |
| 333 | contents = input_api.ReadFile(f) |
| 334 | if pattern.search(contents): |
| 335 | files.append(f) |
| 336 | |
| 337 | if len(files): |
| 338 | return [ output_api.PresubmitError( |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 339 | 'Do not #include <iostream> in header files, since it inserts static ' |
| 340 | 'initialization into every file including the header. Instead, ' |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 341 | '#include <ostream>. See http://crbug.com/94794', |
| 342 | files) ] |
| 343 | return [] |
| 344 | |
| 345 | |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 346 | def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api): |
| 347 | """Checks to make sure no source files use UNIT_TEST""" |
| 348 | problems = [] |
| 349 | for f in input_api.AffectedFiles(): |
| 350 | if (not f.LocalPath().endswith(('.cc', '.mm'))): |
| 351 | continue |
| 352 | |
| 353 | for line_num, line in f.ChangedContents(): |
[email protected] | 549f86a | 2013-11-19 13:00:04 | [diff] [blame] | 354 | if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 355 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 356 | |
| 357 | if not problems: |
| 358 | return [] |
| 359 | return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + |
| 360 | '\n'.join(problems))] |
| 361 | |
| 362 | |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 363 | def _FindHistogramNameInLine(histogram_name, line): |
| 364 | """Tries to find a histogram name or prefix in a line.""" |
| 365 | if not "affected-histogram" in line: |
| 366 | return histogram_name in line |
| 367 | # A histogram_suffixes tag type has an affected-histogram name as a prefix of |
| 368 | # the histogram_name. |
| 369 | if not '"' in line: |
| 370 | return False |
| 371 | histogram_prefix = line.split('\"')[1] |
| 372 | return histogram_prefix in histogram_name |
| 373 | |
| 374 | |
| 375 | def _CheckUmaHistogramChanges(input_api, output_api): |
| 376 | """Check that UMA histogram names in touched lines can still be found in other |
| 377 | lines of the patch or in histograms.xml. Note that this check would not catch |
| 378 | the reverse: changes in histograms.xml not matched in the code itself.""" |
| 379 | touched_histograms = [] |
| 380 | histograms_xml_modifications = [] |
| 381 | pattern = input_api.re.compile('UMA_HISTOGRAM.*\("(.*)"') |
| 382 | for f in input_api.AffectedFiles(): |
| 383 | # If histograms.xml itself is modified, keep the modified lines for later. |
| 384 | if f.LocalPath().endswith(('histograms.xml')): |
| 385 | histograms_xml_modifications = f.ChangedContents() |
| 386 | continue |
| 387 | if not f.LocalPath().endswith(('cc', 'mm', 'cpp')): |
| 388 | continue |
| 389 | for line_num, line in f.ChangedContents(): |
| 390 | found = pattern.search(line) |
| 391 | if found: |
| 392 | touched_histograms.append([found.group(1), f, line_num]) |
| 393 | |
| 394 | # Search for the touched histogram names in the local modifications to |
| 395 | # histograms.xml, and, if not found, on the base histograms.xml file. |
| 396 | unmatched_histograms = [] |
| 397 | for histogram_info in touched_histograms: |
| 398 | histogram_name_found = False |
| 399 | for line_num, line in histograms_xml_modifications: |
| 400 | histogram_name_found = _FindHistogramNameInLine(histogram_info[0], line) |
| 401 | if histogram_name_found: |
| 402 | break |
| 403 | if not histogram_name_found: |
| 404 | unmatched_histograms.append(histogram_info) |
| 405 | |
eroman | b90c82e7e3 | 2015-04-01 15:13:49 | [diff] [blame^] | 406 | histograms_xml_path = 'tools/metrics/histograms/histograms.xml' |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 407 | problems = [] |
| 408 | if unmatched_histograms: |
eroman | b90c82e7e3 | 2015-04-01 15:13:49 | [diff] [blame^] | 409 | with open(histograms_xml_path) as histograms_xml: |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 410 | for histogram_name, f, line_num in unmatched_histograms: |
mcasas | 39c1b8b | 2015-02-25 15:33:45 | [diff] [blame] | 411 | histograms_xml.seek(0) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 412 | histogram_name_found = False |
| 413 | for line in histograms_xml: |
| 414 | histogram_name_found = _FindHistogramNameInLine(histogram_name, line) |
| 415 | if histogram_name_found: |
| 416 | break |
| 417 | if not histogram_name_found: |
| 418 | problems.append(' [%s:%d] %s' % |
| 419 | (f.LocalPath(), line_num, histogram_name)) |
| 420 | |
| 421 | if not problems: |
| 422 | return [] |
| 423 | return [output_api.PresubmitPromptWarning('Some UMA_HISTOGRAM lines have ' |
| 424 | 'been modified and the associated histogram name has no match in either ' |
eroman | b90c82e7e3 | 2015-04-01 15:13:49 | [diff] [blame^] | 425 | '%s or the modifications of it:' % (histograms_xml_path), problems)] |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 426 | |
| 427 | |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 428 | def _CheckNoNewWStrings(input_api, output_api): |
| 429 | """Checks to make sure we don't introduce use of wstrings.""" |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 430 | problems = [] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 431 | for f in input_api.AffectedFiles(): |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 432 | if (not f.LocalPath().endswith(('.cc', '.h')) or |
scottmg | e6f0440 | 2014-11-05 01:59:57 | [diff] [blame] | 433 | f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or |
| 434 | '/win/' in f.LocalPath()): |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 435 | continue |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 436 | |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 437 | allowWString = False |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 438 | for line_num, line in f.ChangedContents(): |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 439 | if 'presubmit: allow wstring' in line: |
| 440 | allowWString = True |
| 441 | elif not allowWString and 'wstring' in line: |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 442 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 443 | allowWString = False |
| 444 | else: |
| 445 | allowWString = False |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 446 | |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 447 | if not problems: |
| 448 | return [] |
| 449 | return [output_api.PresubmitPromptWarning('New code should not use wstrings.' |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 450 | ' If you are calling a cross-platform API that accepts a wstring, ' |
| 451 | 'fix the API.\n' + |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 452 | '\n'.join(problems))] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 453 | |
| 454 | |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 455 | def _CheckNoDEPSGIT(input_api, output_api): |
| 456 | """Make sure .DEPS.git is never modified manually.""" |
| 457 | if any(f.LocalPath().endswith('.DEPS.git') for f in |
| 458 | input_api.AffectedFiles()): |
| 459 | return [output_api.PresubmitError( |
| 460 | 'Never commit changes to .DEPS.git. This file is maintained by an\n' |
| 461 | 'automated system based on what\'s in DEPS and your changes will be\n' |
| 462 | 'overwritten.\n' |
[email protected] | cb70691 | 2014-06-28 20:46:34 | [diff] [blame] | 463 | 'See https://sites.google.com/a/chromium.org/dev/developers/how-tos/get-the-code#Rolling_DEPS\n' |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 464 | 'for more information')] |
| 465 | return [] |
| 466 | |
| 467 | |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 468 | def _CheckValidHostsInDEPS(input_api, output_api): |
| 469 | """Checks that DEPS file deps are from allowed_hosts.""" |
| 470 | # Run only if DEPS file has been modified to annoy fewer bystanders. |
| 471 | if all(f.LocalPath() != 'DEPS' for f in input_api.AffectedFiles()): |
| 472 | return [] |
| 473 | # Outsource work to gclient verify |
| 474 | try: |
| 475 | input_api.subprocess.check_output(['gclient', 'verify']) |
| 476 | return [] |
| 477 | except input_api.subprocess.CalledProcessError, error: |
| 478 | return [output_api.PresubmitError( |
| 479 | 'DEPS file must have only git dependencies.', |
| 480 | long_text=error.output)] |
| 481 | |
| 482 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 483 | def _CheckNoBannedFunctions(input_api, output_api): |
| 484 | """Make sure that banned functions are not used.""" |
| 485 | warnings = [] |
| 486 | errors = [] |
| 487 | |
| 488 | file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) |
| 489 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 490 | for line_num, line in f.ChangedContents(): |
| 491 | for func_name, message, error in _BANNED_OBJC_FUNCTIONS: |
[email protected] | eaae197 | 2014-04-16 04:17:26 | [diff] [blame] | 492 | matched = False |
| 493 | if func_name[0:1] == '/': |
| 494 | regex = func_name[1:] |
| 495 | if input_api.re.search(regex, line): |
| 496 | matched = True |
| 497 | elif func_name in line: |
| 498 | matched = True |
| 499 | if matched: |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 500 | problems = warnings; |
| 501 | if error: |
| 502 | problems = errors; |
| 503 | problems.append(' %s:%d:' % (f.LocalPath(), line_num)) |
| 504 | for message_line in message: |
| 505 | problems.append(' %s' % message_line) |
| 506 | |
| 507 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h')) |
| 508 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 509 | for line_num, line in f.ChangedContents(): |
[email protected] | 7345da0 | 2012-11-27 14:31:49 | [diff] [blame] | 510 | for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS: |
| 511 | def IsBlacklisted(affected_file, blacklist): |
| 512 | local_path = affected_file.LocalPath() |
| 513 | for item in blacklist: |
| 514 | if input_api.re.match(item, local_path): |
| 515 | return True |
| 516 | return False |
| 517 | if IsBlacklisted(f, excluded_paths): |
| 518 | continue |
[email protected] | d89eec8 | 2013-12-03 14:10:59 | [diff] [blame] | 519 | matched = False |
| 520 | if func_name[0:1] == '/': |
| 521 | regex = func_name[1:] |
| 522 | if input_api.re.search(regex, line): |
| 523 | matched = True |
| 524 | elif func_name in line: |
| 525 | matched = True |
| 526 | if matched: |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 527 | problems = warnings; |
| 528 | if error: |
| 529 | problems = errors; |
| 530 | problems.append(' %s:%d:' % (f.LocalPath(), line_num)) |
| 531 | for message_line in message: |
| 532 | problems.append(' %s' % message_line) |
| 533 | |
| 534 | result = [] |
| 535 | if (warnings): |
| 536 | result.append(output_api.PresubmitPromptWarning( |
| 537 | 'Banned functions were used.\n' + '\n'.join(warnings))) |
| 538 | if (errors): |
| 539 | result.append(output_api.PresubmitError( |
| 540 | 'Banned functions were used.\n' + '\n'.join(errors))) |
| 541 | return result |
| 542 | |
| 543 | |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 544 | def _CheckNoPragmaOnce(input_api, output_api): |
| 545 | """Make sure that banned functions are not used.""" |
| 546 | files = [] |
| 547 | pattern = input_api.re.compile(r'^#pragma\s+once', |
| 548 | input_api.re.MULTILINE) |
| 549 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 550 | if not f.LocalPath().endswith('.h'): |
| 551 | continue |
| 552 | contents = input_api.ReadFile(f) |
| 553 | if pattern.search(contents): |
| 554 | files.append(f) |
| 555 | |
| 556 | if files: |
| 557 | return [output_api.PresubmitError( |
| 558 | 'Do not use #pragma once in header files.\n' |
| 559 | 'See http://www.chromium.org/developers/coding-style#TOC-File-headers', |
| 560 | files)] |
| 561 | return [] |
| 562 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 563 | |
[email protected] | e747905 | 2012-09-19 00:26:12 | [diff] [blame] | 564 | def _CheckNoTrinaryTrueFalse(input_api, output_api): |
| 565 | """Checks to make sure we don't introduce use of foo ? true : false.""" |
| 566 | problems = [] |
| 567 | pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)') |
| 568 | for f in input_api.AffectedFiles(): |
| 569 | if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')): |
| 570 | continue |
| 571 | |
| 572 | for line_num, line in f.ChangedContents(): |
| 573 | if pattern.match(line): |
| 574 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 575 | |
| 576 | if not problems: |
| 577 | return [] |
| 578 | return [output_api.PresubmitPromptWarning( |
| 579 | 'Please consider avoiding the "? true : false" pattern if possible.\n' + |
| 580 | '\n'.join(problems))] |
| 581 | |
| 582 | |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 583 | def _CheckUnwantedDependencies(input_api, output_api): |
| 584 | """Runs checkdeps on #include statements added in this |
| 585 | change. Breaking - rules is an error, breaking ! rules is a |
| 586 | warning. |
| 587 | """ |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 588 | import sys |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 589 | # We need to wait until we have an input_api object and use this |
| 590 | # roundabout construct to import checkdeps because this file is |
| 591 | # eval-ed and thus doesn't have __file__. |
| 592 | original_sys_path = sys.path |
| 593 | try: |
| 594 | sys.path = sys.path + [input_api.os_path.join( |
[email protected] | 5298cc98 | 2014-05-29 20:53:47 | [diff] [blame] | 595 | input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 596 | import checkdeps |
| 597 | from cpp_checker import CppChecker |
| 598 | from rules import Rule |
| 599 | finally: |
| 600 | # Restore sys.path to what it was before. |
| 601 | sys.path = original_sys_path |
| 602 | |
| 603 | added_includes = [] |
| 604 | for f in input_api.AffectedFiles(): |
| 605 | if not CppChecker.IsCppFile(f.LocalPath()): |
| 606 | continue |
| 607 | |
| 608 | changed_lines = [line for line_num, line in f.ChangedContents()] |
| 609 | added_includes.append([f.LocalPath(), changed_lines]) |
| 610 | |
[email protected] | 2638517 | 2013-05-09 23:11:35 | [diff] [blame] | 611 | deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 612 | |
| 613 | error_descriptions = [] |
| 614 | warning_descriptions = [] |
| 615 | for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes( |
| 616 | added_includes): |
| 617 | description_with_path = '%s\n %s' % (path, rule_description) |
| 618 | if rule_type == Rule.DISALLOW: |
| 619 | error_descriptions.append(description_with_path) |
| 620 | else: |
| 621 | warning_descriptions.append(description_with_path) |
| 622 | |
| 623 | results = [] |
| 624 | if error_descriptions: |
| 625 | results.append(output_api.PresubmitError( |
| 626 | 'You added one or more #includes that violate checkdeps rules.', |
| 627 | error_descriptions)) |
| 628 | if warning_descriptions: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 629 | results.append(output_api.PresubmitPromptOrNotify( |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 630 | 'You added one or more #includes of files that are temporarily\n' |
| 631 | 'allowed but being removed. Can you avoid introducing the\n' |
| 632 | '#include? See relevant DEPS file(s) for details and contacts.', |
| 633 | warning_descriptions)) |
| 634 | return results |
| 635 | |
| 636 | |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 637 | def _CheckFilePermissions(input_api, output_api): |
| 638 | """Check that all files have their permissions properly set.""" |
[email protected] | 79150720 | 2014-02-03 23:19:15 | [diff] [blame] | 639 | if input_api.platform == 'win32': |
| 640 | return [] |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 641 | args = [input_api.python_executable, 'tools/checkperms/checkperms.py', |
| 642 | '--root', input_api.change.RepositoryRoot()] |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 643 | for f in input_api.AffectedFiles(): |
| 644 | args += ['--file', f.LocalPath()] |
[email protected] | f0d330f | 2014-01-30 01:44:34 | [diff] [blame] | 645 | checkperms = input_api.subprocess.Popen(args, |
| 646 | stdout=input_api.subprocess.PIPE) |
| 647 | errors = checkperms.communicate()[0].strip() |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 648 | if errors: |
[email protected] | f0d330f | 2014-01-30 01:44:34 | [diff] [blame] | 649 | return [output_api.PresubmitError('checkperms.py failed.', |
| 650 | errors.splitlines())] |
| 651 | return [] |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 652 | |
| 653 | |
[email protected] | c8278b3 | 2012-10-30 20:35:49 | [diff] [blame] | 654 | def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api): |
| 655 | """Makes sure we don't include ui/aura/window_property.h |
| 656 | in header files. |
| 657 | """ |
| 658 | pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"') |
| 659 | errors = [] |
| 660 | for f in input_api.AffectedFiles(): |
| 661 | if not f.LocalPath().endswith('.h'): |
| 662 | continue |
| 663 | for line_num, line in f.ChangedContents(): |
| 664 | if pattern.match(line): |
| 665 | errors.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 666 | |
| 667 | results = [] |
| 668 | if errors: |
| 669 | results.append(output_api.PresubmitError( |
| 670 | 'Header files should not include ui/aura/window_property.h', errors)) |
| 671 | return results |
| 672 | |
| 673 | |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 674 | def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums): |
| 675 | """Checks that the lines in scope occur in the right order. |
| 676 | |
| 677 | 1. C system files in alphabetical order |
| 678 | 2. C++ system files in alphabetical order |
| 679 | 3. Project's .h files |
| 680 | """ |
| 681 | |
| 682 | c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>') |
| 683 | cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>') |
| 684 | custom_include_pattern = input_api.re.compile(r'\s*#include ".*') |
| 685 | |
| 686 | C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3) |
| 687 | |
| 688 | state = C_SYSTEM_INCLUDES |
| 689 | |
| 690 | previous_line = '' |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 691 | previous_line_num = 0 |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 692 | problem_linenums = [] |
| 693 | for line_num, line in scope: |
| 694 | if c_system_include_pattern.match(line): |
| 695 | if state != C_SYSTEM_INCLUDES: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 696 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 697 | elif previous_line and previous_line > line: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 698 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 699 | elif cpp_system_include_pattern.match(line): |
| 700 | if state == C_SYSTEM_INCLUDES: |
| 701 | state = CPP_SYSTEM_INCLUDES |
| 702 | elif state == CUSTOM_INCLUDES: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 703 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 704 | elif previous_line and previous_line > line: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 705 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 706 | elif custom_include_pattern.match(line): |
| 707 | if state != CUSTOM_INCLUDES: |
| 708 | state = CUSTOM_INCLUDES |
| 709 | elif previous_line and previous_line > line: |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 710 | problem_linenums.append((line_num, previous_line_num)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 711 | else: |
| 712 | problem_linenums.append(line_num) |
| 713 | previous_line = line |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 714 | previous_line_num = line_num |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 715 | |
| 716 | warnings = [] |
[email protected] | 728b9bb | 2012-11-14 20:38:57 | [diff] [blame] | 717 | for (line_num, previous_line_num) in problem_linenums: |
| 718 | if line_num in changed_linenums or previous_line_num in changed_linenums: |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 719 | warnings.append(' %s:%d' % (file_path, line_num)) |
| 720 | return warnings |
| 721 | |
| 722 | |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 723 | def _CheckIncludeOrderInFile(input_api, f, changed_linenums): |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 724 | """Checks the #include order for the given file f.""" |
| 725 | |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 726 | system_include_pattern = input_api.re.compile(r'\s*#include \<.*') |
[email protected] | 23093b6 | 2013-09-20 12:16:30 | [diff] [blame] | 727 | # Exclude the following includes from the check: |
| 728 | # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a |
| 729 | # specific order. |
| 730 | # 2) <atlbase.h>, "build/build_config.h" |
| 731 | excluded_include_pattern = input_api.re.compile( |
| 732 | r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")') |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 733 | custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"') |
[email protected] | 3e83618c | 2013-10-09 22:32:33 | [diff] [blame] | 734 | # Match the final or penultimate token if it is xxxtest so we can ignore it |
| 735 | # when considering the special first include. |
| 736 | test_file_tag_pattern = input_api.re.compile( |
| 737 | r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)') |
[email protected] | 0e5c185 | 2012-12-18 20:17:11 | [diff] [blame] | 738 | if_pattern = input_api.re.compile( |
| 739 | r'\s*#\s*(if|elif|else|endif|define|undef).*') |
| 740 | # Some files need specialized order of includes; exclude such files from this |
| 741 | # check. |
| 742 | uncheckable_includes_pattern = input_api.re.compile( |
| 743 | r'\s*#include ' |
| 744 | '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*') |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 745 | |
| 746 | contents = f.NewContents() |
| 747 | warnings = [] |
| 748 | line_num = 0 |
| 749 | |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 750 | # Handle the special first include. If the first include file is |
| 751 | # some/path/file.h, the corresponding including file can be some/path/file.cc, |
| 752 | # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h |
| 753 | # etc. It's also possible that no special first include exists. |
[email protected] | 3e83618c | 2013-10-09 22:32:33 | [diff] [blame] | 754 | # If the included file is some/path/file_platform.h the including file could |
| 755 | # also be some/path/file_xxxtest_platform.h. |
| 756 | including_file_base_name = test_file_tag_pattern.sub( |
| 757 | '', input_api.os_path.basename(f.LocalPath())) |
| 758 | |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 759 | for line in contents: |
| 760 | line_num += 1 |
| 761 | if system_include_pattern.match(line): |
| 762 | # No special first include -> process the line again along with normal |
| 763 | # includes. |
| 764 | line_num -= 1 |
| 765 | break |
| 766 | match = custom_include_pattern.match(line) |
| 767 | if match: |
| 768 | match_dict = match.groupdict() |
[email protected] | 3e83618c | 2013-10-09 22:32:33 | [diff] [blame] | 769 | header_basename = test_file_tag_pattern.sub( |
| 770 | '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '') |
| 771 | |
| 772 | if header_basename not in including_file_base_name: |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 773 | # No special first include -> process the line again along with normal |
| 774 | # includes. |
| 775 | line_num -= 1 |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 776 | break |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 777 | |
| 778 | # Split into scopes: Each region between #if and #endif is its own scope. |
| 779 | scopes = [] |
| 780 | current_scope = [] |
| 781 | for line in contents[line_num:]: |
| 782 | line_num += 1 |
[email protected] | 0e5c185 | 2012-12-18 20:17:11 | [diff] [blame] | 783 | if uncheckable_includes_pattern.match(line): |
[email protected] | 4436c9e | 2014-01-07 23:19:54 | [diff] [blame] | 784 | continue |
[email protected] | 2309b0fa0 | 2012-11-16 12:18:27 | [diff] [blame] | 785 | if if_pattern.match(line): |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 786 | scopes.append(current_scope) |
| 787 | current_scope = [] |
[email protected] | 962f117e | 2012-11-22 18:11:56 | [diff] [blame] | 788 | elif ((system_include_pattern.match(line) or |
| 789 | custom_include_pattern.match(line)) and |
| 790 | not excluded_include_pattern.match(line)): |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 791 | current_scope.append((line_num, line)) |
| 792 | scopes.append(current_scope) |
| 793 | |
| 794 | for scope in scopes: |
| 795 | warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(), |
| 796 | changed_linenums)) |
| 797 | return warnings |
| 798 | |
| 799 | |
| 800 | def _CheckIncludeOrder(input_api, output_api): |
| 801 | """Checks that the #include order is correct. |
| 802 | |
| 803 | 1. The corresponding header for source files. |
| 804 | 2. C system files in alphabetical order |
| 805 | 3. C++ system files in alphabetical order |
| 806 | 4. Project's .h files in alphabetical order |
| 807 | |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 808 | Each region separated by #if, #elif, #else, #endif, #define and #undef follows |
| 809 | these rules separately. |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 810 | """ |
[email protected] | e120b01 | 2014-08-15 19:08:35 | [diff] [blame] | 811 | def FileFilterIncludeOrder(affected_file): |
| 812 | black_list = (_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) |
| 813 | return input_api.FilterSourceFile(affected_file, black_list=black_list) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 814 | |
| 815 | warnings = [] |
[email protected] | e120b01 | 2014-08-15 19:08:35 | [diff] [blame] | 816 | for f in input_api.AffectedFiles(file_filter=FileFilterIncludeOrder): |
[email protected] | ac294a1 | 2012-12-06 16:38:43 | [diff] [blame] | 817 | if f.LocalPath().endswith(('.cc', '.h')): |
| 818 | changed_linenums = set(line_num for line_num, _ in f.ChangedContents()) |
| 819 | warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 820 | |
| 821 | results = [] |
| 822 | if warnings: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 823 | results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING, |
[email protected] | 120cf540d | 2012-12-10 17:55:53 | [diff] [blame] | 824 | warnings)) |
[email protected] | cf9b78f | 2012-11-14 11:40:28 | [diff] [blame] | 825 | return results |
| 826 | |
| 827 | |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 828 | def _CheckForVersionControlConflictsInFile(input_api, f): |
| 829 | pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$') |
| 830 | errors = [] |
| 831 | for line_num, line in f.ChangedContents(): |
| 832 | if pattern.match(line): |
| 833 | errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) |
| 834 | return errors |
| 835 | |
| 836 | |
| 837 | def _CheckForVersionControlConflicts(input_api, output_api): |
| 838 | """Usually this is not intentional and will cause a compile failure.""" |
| 839 | errors = [] |
| 840 | for f in input_api.AffectedFiles(): |
| 841 | errors.extend(_CheckForVersionControlConflictsInFile(input_api, f)) |
| 842 | |
| 843 | results = [] |
| 844 | if errors: |
| 845 | results.append(output_api.PresubmitError( |
| 846 | 'Version control conflict markers found, please resolve.', errors)) |
| 847 | return results |
| 848 | |
| 849 | |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 850 | def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api): |
| 851 | def FilterFile(affected_file): |
| 852 | """Filter function for use with input_api.AffectedSourceFiles, |
| 853 | below. This filters out everything except non-test files from |
| 854 | top-level directories that generally speaking should not hard-code |
| 855 | service URLs (e.g. src/android_webview/, src/content/ and others). |
| 856 | """ |
| 857 | return input_api.FilterSourceFile( |
| 858 | affected_file, |
[email protected] | 78bb39d6 | 2012-12-11 15:11:56 | [diff] [blame] | 859 | white_list=(r'^(android_webview|base|content|net)[\\\/].*', ), |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 860 | black_list=(_EXCLUDED_PATHS + |
| 861 | _TEST_CODE_EXCLUDED_PATHS + |
| 862 | input_api.DEFAULT_BLACK_LIST)) |
| 863 | |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 864 | base_pattern = '"[^"]*google\.com[^"]*"' |
| 865 | comment_pattern = input_api.re.compile('//.*%s' % base_pattern) |
| 866 | pattern = input_api.re.compile(base_pattern) |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 867 | problems = [] # items are (filename, line_number, line) |
| 868 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 869 | for line_num, line in f.ChangedContents(): |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 870 | if not comment_pattern.search(line) and pattern.search(line): |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 871 | problems.append((f.LocalPath(), line_num, line)) |
| 872 | |
| 873 | if problems: |
[email protected] | f7051d5 | 2013-04-02 18:31:42 | [diff] [blame] | 874 | return [output_api.PresubmitPromptOrNotify( |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 875 | 'Most layers below src/chrome/ should not hardcode service URLs.\n' |
[email protected] | b014977 | 2014-03-27 16:47:58 | [diff] [blame] | 876 | 'Are you sure this is correct?', |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 877 | [' %s:%d: %s' % ( |
| 878 | problem[0], problem[1], problem[2]) for problem in problems])] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 879 | else: |
| 880 | return [] |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 881 | |
| 882 | |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 883 | def _CheckNoAbbreviationInPngFileName(input_api, output_api): |
| 884 | """Makes sure there are no abbreviations in the name of PNG files. |
binji | 0dcdf34 | 2014-12-12 18:32:31 | [diff] [blame] | 885 | The native_client_sdk directory is excluded because it has auto-generated PNG |
| 886 | files for documentation. |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 887 | """ |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 888 | errors = [] |
binji | 0dcdf34 | 2014-12-12 18:32:31 | [diff] [blame] | 889 | white_list = (r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$',) |
| 890 | black_list = (r'^native_client_sdk[\\\/]',) |
| 891 | file_filter = lambda f: input_api.FilterSourceFile( |
| 892 | f, white_list=white_list, black_list=black_list) |
| 893 | for f in input_api.AffectedFiles(include_deletes=False, |
| 894 | file_filter=file_filter): |
| 895 | errors.append(' %s' % f.LocalPath()) |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 896 | |
| 897 | results = [] |
| 898 | if errors: |
| 899 | results.append(output_api.PresubmitError( |
| 900 | 'The name of PNG files should not have abbreviations. \n' |
| 901 | 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n' |
| 902 | 'Contact [email protected] if you have questions.', errors)) |
| 903 | return results |
| 904 | |
| 905 | |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 906 | def _FilesToCheckForIncomingDeps(re, changed_lines): |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 907 | """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 908 | a set of DEPS entries that we should look up. |
| 909 | |
| 910 | For a directory (rather than a specific filename) we fake a path to |
| 911 | a specific filename by adding /DEPS. This is chosen as a file that |
| 912 | will seldom or never be subject to per-file include_rules. |
| 913 | """ |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 914 | # We ignore deps entries on auto-generated directories. |
| 915 | AUTO_GENERATED_DIRS = ['grit', 'jni'] |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 916 | |
| 917 | # This pattern grabs the path without basename in the first |
| 918 | # parentheses, and the basename (if present) in the second. It |
| 919 | # relies on the simple heuristic that if there is a basename it will |
| 920 | # be a header file ending in ".h". |
| 921 | pattern = re.compile( |
| 922 | r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""") |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 923 | results = set() |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 924 | for changed_line in changed_lines: |
| 925 | m = pattern.match(changed_line) |
| 926 | if m: |
| 927 | path = m.group(1) |
[email protected] | 2b438d6 | 2013-11-14 17:54:14 | [diff] [blame] | 928 | if path.split('/')[0] not in AUTO_GENERATED_DIRS: |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 929 | if m.group(2): |
| 930 | results.add('%s%s' % (path, m.group(2))) |
| 931 | else: |
| 932 | results.add('%s/DEPS' % path) |
[email protected] | f32e2d1e | 2013-07-26 21:39:08 | [diff] [blame] | 933 | return results |
| 934 | |
| 935 | |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 936 | def _CheckAddedDepsHaveTargetApprovals(input_api, output_api): |
| 937 | """When a dependency prefixed with + is added to a DEPS file, we |
| 938 | want to make sure that the change is reviewed by an OWNER of the |
| 939 | target file or directory, to avoid layering violations from being |
| 940 | introduced. This check verifies that this happens. |
| 941 | """ |
| 942 | changed_lines = set() |
| 943 | for f in input_api.AffectedFiles(): |
| 944 | filename = input_api.os_path.basename(f.LocalPath()) |
| 945 | if filename == 'DEPS': |
| 946 | changed_lines |= set(line.strip() |
| 947 | for line_num, line |
| 948 | in f.ChangedContents()) |
| 949 | if not changed_lines: |
| 950 | return [] |
| 951 | |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 952 | virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re, |
| 953 | changed_lines) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 954 | if not virtual_depended_on_files: |
| 955 | return [] |
| 956 | |
| 957 | if input_api.is_committing: |
| 958 | if input_api.tbr: |
| 959 | return [output_api.PresubmitNotifyResult( |
| 960 | '--tbr was specified, skipping OWNERS check for DEPS additions')] |
| 961 | if not input_api.change.issue: |
| 962 | return [output_api.PresubmitError( |
| 963 | "DEPS approval by OWNERS check failed: this change has " |
| 964 | "no Rietveld issue number, so we can't check it for approvals.")] |
| 965 | output = output_api.PresubmitError |
| 966 | else: |
| 967 | output = output_api.PresubmitNotifyResult |
| 968 | |
| 969 | owners_db = input_api.owners_db |
| 970 | owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers( |
| 971 | input_api, |
| 972 | owners_db.email_regexp, |
| 973 | approval_needed=input_api.is_committing) |
| 974 | |
| 975 | owner_email = owner_email or input_api.change.author_email |
| 976 | |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 977 | reviewers_plus_owner = set(reviewers) |
[email protected] | e71c608 | 2013-05-22 02:28:51 | [diff] [blame] | 978 | if owner_email: |
[email protected] | de4f7d2 | 2013-05-23 14:27:46 | [diff] [blame] | 979 | reviewers_plus_owner.add(owner_email) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 980 | missing_files = owners_db.files_not_covered_by(virtual_depended_on_files, |
| 981 | reviewers_plus_owner) |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 982 | |
| 983 | # We strip the /DEPS part that was added by |
| 984 | # _FilesToCheckForIncomingDeps to fake a path to a file in a |
| 985 | # directory. |
| 986 | def StripDeps(path): |
| 987 | start_deps = path.rfind('/DEPS') |
| 988 | if start_deps != -1: |
| 989 | return path[:start_deps] |
| 990 | else: |
| 991 | return path |
| 992 | unapproved_dependencies = ["'+%s'," % StripDeps(path) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 993 | for path in missing_files] |
| 994 | |
| 995 | if unapproved_dependencies: |
| 996 | output_list = [ |
[email protected] | 14a6131c | 2014-01-08 01:15:41 | [diff] [blame] | 997 | output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' % |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 998 | '\n '.join(sorted(unapproved_dependencies)))] |
| 999 | if not input_api.is_committing: |
| 1000 | suggested_owners = owners_db.reviewers_for(missing_files, owner_email) |
| 1001 | output_list.append(output( |
| 1002 | 'Suggested missing target path OWNERS:\n %s' % |
| 1003 | '\n '.join(suggested_owners or []))) |
| 1004 | return output_list |
| 1005 | |
| 1006 | return [] |
| 1007 | |
| 1008 | |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1009 | def _CheckSpamLogging(input_api, output_api): |
| 1010 | file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS |
| 1011 | black_list = (_EXCLUDED_PATHS + |
| 1012 | _TEST_CODE_EXCLUDED_PATHS + |
| 1013 | input_api.DEFAULT_BLACK_LIST + |
[email protected] | 6f742dd0 | 2013-11-26 23:19:50 | [diff] [blame] | 1014 | (r"^base[\\\/]logging\.h$", |
[email protected] | 80f360a | 2014-01-23 01:36:19 | [diff] [blame] | 1015 | r"^base[\\\/]logging\.cc$", |
[email protected] | 8dc338c | 2013-12-09 16:28:48 | [diff] [blame] | 1016 | r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$", |
[email protected] | 6e268db | 2013-12-04 01:41:46 | [diff] [blame] | 1017 | r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$", |
[email protected] | 4de7526 | 2013-12-18 23:16:12 | [diff] [blame] | 1018 | r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]" |
| 1019 | r"startup_browser_creator\.cc$", |
[email protected] | fe0e6e1 | 2013-12-04 05:52:58 | [diff] [blame] | 1020 | r"^chrome[\\\/]installer[\\\/]setup[\\\/].*", |
[email protected] | 8cf6f84 | 2014-08-08 21:33:16 | [diff] [blame] | 1021 | r"chrome[\\\/]browser[\\\/]diagnostics[\\\/]" + |
[email protected] | f5b9a3f34 | 2014-08-08 22:06:03 | [diff] [blame] | 1022 | r"diagnostics_writer\.cc$", |
[email protected] | 9f13b60 | 2014-08-07 02:59:15 | [diff] [blame] | 1023 | r"^chrome_elf[\\\/]dll_hash[\\\/]dll_hash_main\.cc$", |
| 1024 | r"^chromecast[\\\/]", |
| 1025 | r"^cloud_print[\\\/]", |
[email protected] | 9056e73 | 2014-01-08 06:25:25 | [diff] [blame] | 1026 | r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]" |
| 1027 | r"gl_helper_benchmark\.cc$", |
thestig | c9e38a2 | 2014-09-13 01:02:11 | [diff] [blame] | 1028 | r"^courgette[\\\/]courgette_tool\.cc$", |
[email protected] | 9f13b60 | 2014-08-07 02:59:15 | [diff] [blame] | 1029 | r"^extensions[\\\/]renderer[\\\/]logging_native_handler\.cc$", |
prashant.n | b0252f6 | 2014-11-08 05:02:11 | [diff] [blame] | 1030 | r"^ipc[\\\/]ipc_logging\.cc$", |
[email protected] | 9c36d92 | 2014-03-24 16:47:52 | [diff] [blame] | 1031 | r"^native_client_sdk[\\\/]", |
[email protected] | cdbdced | 2013-11-27 21:35:50 | [diff] [blame] | 1032 | r"^remoting[\\\/]base[\\\/]logging\.h$", |
[email protected] | 67c96ab | 2013-12-17 02:05:36 | [diff] [blame] | 1033 | r"^remoting[\\\/]host[\\\/].*", |
[email protected] | 8232f8fd | 2013-12-14 00:52:31 | [diff] [blame] | 1034 | r"^sandbox[\\\/]linux[\\\/].*", |
[email protected] | 0b7a21e | 2014-02-11 18:38:13 | [diff] [blame] | 1035 | r"^tools[\\\/]", |
thestig | 22dfc401 | 2014-09-05 08:29:44 | [diff] [blame] | 1036 | r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$", |
vchigrin | 1425149 | 2015-01-12 08:09:02 | [diff] [blame] | 1037 | r"^storage[\\\/]browser[\\\/]fileapi[\\\/]" + |
thestig | 22dfc401 | 2014-09-05 08:29:44 | [diff] [blame] | 1038 | r"dump_file_system.cc$",)) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1039 | source_file_filter = lambda x: input_api.FilterSourceFile( |
| 1040 | x, white_list=(file_inclusion_pattern,), black_list=black_list) |
| 1041 | |
| 1042 | log_info = [] |
| 1043 | printf = [] |
| 1044 | |
| 1045 | for f in input_api.AffectedSourceFiles(source_file_filter): |
| 1046 | contents = input_api.ReadFile(f, 'rb') |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1047 | if input_api.re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1048 | log_info.append(f.LocalPath()) |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1049 | elif input_api.re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents): |
[email protected] | 8521065 | 2013-11-28 05:50:13 | [diff] [blame] | 1050 | log_info.append(f.LocalPath()) |
[email protected] | 18b466b | 2013-12-02 22:01:37 | [diff] [blame] | 1051 | |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1052 | if input_api.re.search(r"\bprintf\(", contents): |
[email protected] | 18b466b | 2013-12-02 22:01:37 | [diff] [blame] | 1053 | printf.append(f.LocalPath()) |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1054 | elif input_api.re.search(r"\bfprintf\((stdout|stderr)", contents): |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1055 | printf.append(f.LocalPath()) |
| 1056 | |
| 1057 | if log_info: |
| 1058 | return [output_api.PresubmitError( |
| 1059 | 'These files spam the console log with LOG(INFO):', |
| 1060 | items=log_info)] |
| 1061 | if printf: |
| 1062 | return [output_api.PresubmitError( |
| 1063 | 'These files spam the console log with printf/fprintf:', |
| 1064 | items=printf)] |
| 1065 | return [] |
| 1066 | |
| 1067 | |
[email protected] | 49aa76a | 2013-12-04 06:59:16 | [diff] [blame] | 1068 | def _CheckForAnonymousVariables(input_api, output_api): |
| 1069 | """These types are all expected to hold locks while in scope and |
| 1070 | so should never be anonymous (which causes them to be immediately |
| 1071 | destroyed).""" |
| 1072 | they_who_must_be_named = [ |
| 1073 | 'base::AutoLock', |
| 1074 | 'base::AutoReset', |
| 1075 | 'base::AutoUnlock', |
| 1076 | 'SkAutoAlphaRestore', |
| 1077 | 'SkAutoBitmapShaderInstall', |
| 1078 | 'SkAutoBlitterChoose', |
| 1079 | 'SkAutoBounderCommit', |
| 1080 | 'SkAutoCallProc', |
| 1081 | 'SkAutoCanvasRestore', |
| 1082 | 'SkAutoCommentBlock', |
| 1083 | 'SkAutoDescriptor', |
| 1084 | 'SkAutoDisableDirectionCheck', |
| 1085 | 'SkAutoDisableOvalCheck', |
| 1086 | 'SkAutoFree', |
| 1087 | 'SkAutoGlyphCache', |
| 1088 | 'SkAutoHDC', |
| 1089 | 'SkAutoLockColors', |
| 1090 | 'SkAutoLockPixels', |
| 1091 | 'SkAutoMalloc', |
| 1092 | 'SkAutoMaskFreeImage', |
| 1093 | 'SkAutoMutexAcquire', |
| 1094 | 'SkAutoPathBoundsUpdate', |
| 1095 | 'SkAutoPDFRelease', |
| 1096 | 'SkAutoRasterClipValidate', |
| 1097 | 'SkAutoRef', |
| 1098 | 'SkAutoTime', |
| 1099 | 'SkAutoTrace', |
| 1100 | 'SkAutoUnref', |
| 1101 | ] |
| 1102 | anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named) |
| 1103 | # bad: base::AutoLock(lock.get()); |
| 1104 | # not bad: base::AutoLock lock(lock.get()); |
| 1105 | bad_pattern = input_api.re.compile(anonymous) |
| 1106 | # good: new base::AutoLock(lock.get()) |
| 1107 | good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous) |
| 1108 | errors = [] |
| 1109 | |
| 1110 | for f in input_api.AffectedFiles(): |
| 1111 | if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')): |
| 1112 | continue |
| 1113 | for linenum, line in f.ChangedContents(): |
| 1114 | if bad_pattern.search(line) and not good_pattern.search(line): |
| 1115 | errors.append('%s:%d' % (f.LocalPath(), linenum)) |
| 1116 | |
| 1117 | if errors: |
| 1118 | return [output_api.PresubmitError( |
| 1119 | 'These lines create anonymous variables that need to be named:', |
| 1120 | items=errors)] |
| 1121 | return [] |
| 1122 | |
| 1123 | |
[email protected] | 5fe0f874 | 2013-11-29 01:04:59 | [diff] [blame] | 1124 | def _CheckCygwinShell(input_api, output_api): |
| 1125 | source_file_filter = lambda x: input_api.FilterSourceFile( |
| 1126 | x, white_list=(r'.+\.(gyp|gypi)$',)) |
| 1127 | cygwin_shell = [] |
| 1128 | |
| 1129 | for f in input_api.AffectedSourceFiles(source_file_filter): |
| 1130 | for linenum, line in f.ChangedContents(): |
| 1131 | if 'msvs_cygwin_shell' in line: |
| 1132 | cygwin_shell.append(f.LocalPath()) |
| 1133 | break |
| 1134 | |
| 1135 | if cygwin_shell: |
| 1136 | return [output_api.PresubmitError( |
| 1137 | 'These files should not use msvs_cygwin_shell (the default is 0):', |
| 1138 | items=cygwin_shell)] |
| 1139 | return [] |
| 1140 | |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1141 | |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1142 | def _CheckUserActionUpdate(input_api, output_api): |
| 1143 | """Checks if any new user action has been added.""" |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1144 | if any('actions.xml' == input_api.os_path.basename(f) for f in |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1145 | input_api.LocalPaths()): |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1146 | # If actions.xml is already included in the changelist, the PRESUBMIT |
| 1147 | # for actions.xml will do a more complete presubmit check. |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1148 | return [] |
| 1149 | |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1150 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm')) |
| 1151 | action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)' |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1152 | current_actions = None |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1153 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1154 | for line_num, line in f.ChangedContents(): |
| 1155 | match = input_api.re.search(action_re, line) |
| 1156 | if match: |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1157 | # Loads contents in tools/metrics/actions/actions.xml to memory. It's |
| 1158 | # loaded only once. |
| 1159 | if not current_actions: |
| 1160 | with open('tools/metrics/actions/actions.xml') as actions_f: |
| 1161 | current_actions = actions_f.read() |
| 1162 | # Search for the matched user action name in |current_actions|. |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1163 | for action_name in match.groups(): |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1164 | action = 'name="{0}"'.format(action_name) |
| 1165 | if action not in current_actions: |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1166 | return [output_api.PresubmitPromptWarning( |
| 1167 | 'File %s line %d: %s is missing in ' |
[email protected] | 2f92dec | 2014-03-07 19:21:52 | [diff] [blame] | 1168 | 'tools/metrics/actions/actions.xml. Please run ' |
| 1169 | 'tools/metrics/actions/extract_actions.py to update.' |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1170 | % (f.LocalPath(), line_num, action_name))] |
| 1171 | return [] |
| 1172 | |
| 1173 | |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 1174 | def _GetJSONParseError(input_api, filename, eat_comments=True): |
| 1175 | try: |
| 1176 | contents = input_api.ReadFile(filename) |
| 1177 | if eat_comments: |
| 1178 | json_comment_eater = input_api.os_path.join( |
| 1179 | input_api.PresubmitLocalPath(), |
| 1180 | 'tools', 'json_comment_eater', 'json_comment_eater.py') |
| 1181 | process = input_api.subprocess.Popen( |
| 1182 | [input_api.python_executable, json_comment_eater], |
| 1183 | stdin=input_api.subprocess.PIPE, |
| 1184 | stdout=input_api.subprocess.PIPE, |
| 1185 | universal_newlines=True) |
| 1186 | (contents, _) = process.communicate(input=contents) |
| 1187 | |
| 1188 | input_api.json.loads(contents) |
| 1189 | except ValueError as e: |
| 1190 | return e |
| 1191 | return None |
| 1192 | |
| 1193 | |
| 1194 | def _GetIDLParseError(input_api, filename): |
| 1195 | try: |
| 1196 | contents = input_api.ReadFile(filename) |
| 1197 | idl_schema = input_api.os_path.join( |
| 1198 | input_api.PresubmitLocalPath(), |
| 1199 | 'tools', 'json_schema_compiler', 'idl_schema.py') |
| 1200 | process = input_api.subprocess.Popen( |
| 1201 | [input_api.python_executable, idl_schema], |
| 1202 | stdin=input_api.subprocess.PIPE, |
| 1203 | stdout=input_api.subprocess.PIPE, |
| 1204 | stderr=input_api.subprocess.PIPE, |
| 1205 | universal_newlines=True) |
| 1206 | (_, error) = process.communicate(input=contents) |
| 1207 | return error or None |
| 1208 | except ValueError as e: |
| 1209 | return e |
| 1210 | |
| 1211 | |
| 1212 | def _CheckParseErrors(input_api, output_api): |
| 1213 | """Check that IDL and JSON files do not contain syntax errors.""" |
| 1214 | actions = { |
| 1215 | '.idl': _GetIDLParseError, |
| 1216 | '.json': _GetJSONParseError, |
| 1217 | } |
| 1218 | # These paths contain test data and other known invalid JSON files. |
| 1219 | excluded_patterns = [ |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 1220 | r'test[\\\/]data[\\\/]', |
| 1221 | r'^components[\\\/]policy[\\\/]resources[\\\/]policy_templates\.json$', |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 1222 | ] |
| 1223 | # Most JSON files are preprocessed and support comments, but these do not. |
| 1224 | json_no_comments_patterns = [ |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 1225 | r'^testing[\\\/]', |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 1226 | ] |
| 1227 | # Only run IDL checker on files in these directories. |
| 1228 | idl_included_patterns = [ |
joaodasilva | 718f8767 | 2014-08-30 09:25:49 | [diff] [blame] | 1229 | r'^chrome[\\\/]common[\\\/]extensions[\\\/]api[\\\/]', |
| 1230 | r'^extensions[\\\/]common[\\\/]api[\\\/]', |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 1231 | ] |
| 1232 | |
| 1233 | def get_action(affected_file): |
| 1234 | filename = affected_file.LocalPath() |
| 1235 | return actions.get(input_api.os_path.splitext(filename)[1]) |
| 1236 | |
| 1237 | def MatchesFile(patterns, path): |
| 1238 | for pattern in patterns: |
| 1239 | if input_api.re.search(pattern, path): |
| 1240 | return True |
| 1241 | return False |
| 1242 | |
| 1243 | def FilterFile(affected_file): |
| 1244 | action = get_action(affected_file) |
| 1245 | if not action: |
| 1246 | return False |
| 1247 | path = affected_file.LocalPath() |
| 1248 | |
| 1249 | if MatchesFile(excluded_patterns, path): |
| 1250 | return False |
| 1251 | |
| 1252 | if (action == _GetIDLParseError and |
| 1253 | not MatchesFile(idl_included_patterns, path)): |
| 1254 | return False |
| 1255 | return True |
| 1256 | |
| 1257 | results = [] |
| 1258 | for affected_file in input_api.AffectedFiles( |
| 1259 | file_filter=FilterFile, include_deletes=False): |
| 1260 | action = get_action(affected_file) |
| 1261 | kwargs = {} |
| 1262 | if (action == _GetJSONParseError and |
| 1263 | MatchesFile(json_no_comments_patterns, affected_file.LocalPath())): |
| 1264 | kwargs['eat_comments'] = False |
| 1265 | parse_error = action(input_api, |
| 1266 | affected_file.AbsoluteLocalPath(), |
| 1267 | **kwargs) |
| 1268 | if parse_error: |
| 1269 | results.append(output_api.PresubmitError('%s could not be parsed: %s' % |
| 1270 | (affected_file.LocalPath(), parse_error))) |
| 1271 | return results |
| 1272 | |
| 1273 | |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 1274 | def _CheckJavaStyle(input_api, output_api): |
| 1275 | """Runs checkstyle on changed java files and returns errors if any exist.""" |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1276 | import sys |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 1277 | original_sys_path = sys.path |
| 1278 | try: |
| 1279 | sys.path = sys.path + [input_api.os_path.join( |
| 1280 | input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] |
| 1281 | import checkstyle |
| 1282 | finally: |
| 1283 | # Restore sys.path to what it was before. |
| 1284 | sys.path = original_sys_path |
| 1285 | |
| 1286 | return checkstyle.RunCheckstyle( |
davileen | 72d7653 | 2015-01-20 22:30:09 | [diff] [blame] | 1287 | input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml', |
newt | d8b7d30e9 | 2015-01-23 18:10:51 | [diff] [blame] | 1288 | black_list=_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 1289 | |
| 1290 | |
mnaganov | 9b9b1fe8 | 2014-12-11 16:30:36 | [diff] [blame] | 1291 | def _CheckForCopyrightedCode(input_api, output_api): |
| 1292 | """Verifies that newly added code doesn't contain copyrighted material |
| 1293 | and is properly licensed under the standard Chromium license. |
| 1294 | |
| 1295 | As there can be false positives, we maintain a whitelist file. This check |
| 1296 | also verifies that the whitelist file is up to date. |
| 1297 | """ |
| 1298 | import sys |
| 1299 | original_sys_path = sys.path |
| 1300 | try: |
| 1301 | sys.path = sys.path + [input_api.os_path.join( |
| 1302 | input_api.PresubmitLocalPath(), 'android_webview', 'tools')] |
| 1303 | import copyright_scanner |
| 1304 | finally: |
| 1305 | # Restore sys.path to what it was before. |
| 1306 | sys.path = original_sys_path |
| 1307 | |
| 1308 | return copyright_scanner.ScanAtPresubmit(input_api, output_api) |
| 1309 | |
| 1310 | |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 1311 | def _CheckSingletonInHeaders(input_api, output_api): |
| 1312 | """Checks to make sure no header files have |Singleton<|.""" |
| 1313 | def FileFilter(affected_file): |
| 1314 | # It's ok for base/memory/singleton.h to have |Singleton<|. |
| 1315 | black_list = (_EXCLUDED_PATHS + |
| 1316 | input_api.DEFAULT_BLACK_LIST + |
| 1317 | (r"^base[\\\/]memory[\\\/]singleton\.h$",)) |
| 1318 | return input_api.FilterSourceFile(affected_file, black_list=black_list) |
| 1319 | |
| 1320 | pattern = input_api.re.compile(r'(?<!class\s)Singleton\s*<') |
| 1321 | files = [] |
| 1322 | for f in input_api.AffectedSourceFiles(FileFilter): |
| 1323 | if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or |
| 1324 | f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): |
| 1325 | contents = input_api.ReadFile(f) |
| 1326 | for line in contents.splitlines(False): |
| 1327 | if (not input_api.re.match(r'//', line) and # Strip C++ comment. |
| 1328 | pattern.search(line)): |
| 1329 | files.append(f) |
| 1330 | break |
| 1331 | |
| 1332 | if files: |
| 1333 | return [ output_api.PresubmitError( |
| 1334 | 'Found Singleton<T> in the following header files.\n' + |
| 1335 | 'Please move them to an appropriate source file so that the ' + |
| 1336 | 'template gets instantiated in a single compilation unit.', |
| 1337 | files) ] |
| 1338 | return [] |
| 1339 | |
| 1340 | |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 1341 | _DEPRECATED_CSS = [ |
| 1342 | # Values |
| 1343 | ( "-webkit-box", "flex" ), |
| 1344 | ( "-webkit-inline-box", "inline-flex" ), |
| 1345 | ( "-webkit-flex", "flex" ), |
| 1346 | ( "-webkit-inline-flex", "inline-flex" ), |
| 1347 | ( "-webkit-min-content", "min-content" ), |
| 1348 | ( "-webkit-max-content", "max-content" ), |
| 1349 | |
| 1350 | # Properties |
| 1351 | ( "-webkit-background-clip", "background-clip" ), |
| 1352 | ( "-webkit-background-origin", "background-origin" ), |
| 1353 | ( "-webkit-background-size", "background-size" ), |
| 1354 | ( "-webkit-box-shadow", "box-shadow" ), |
| 1355 | |
| 1356 | # Functions |
| 1357 | ( "-webkit-gradient", "gradient" ), |
| 1358 | ( "-webkit-repeating-gradient", "repeating-gradient" ), |
| 1359 | ( "-webkit-linear-gradient", "linear-gradient" ), |
| 1360 | ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ), |
| 1361 | ( "-webkit-radial-gradient", "radial-gradient" ), |
| 1362 | ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ), |
| 1363 | ] |
| 1364 | |
| 1365 | def _CheckNoDeprecatedCSS(input_api, output_api): |
| 1366 | """ Make sure that we don't use deprecated CSS |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 1367 | properties, functions or values. Our external |
| 1368 | documentation is ignored by the hooks as it |
| 1369 | needs to be consumed by WebKit. """ |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 1370 | results = [] |
dbeam | 070cfe6 | 2014-10-22 06:44:02 | [diff] [blame] | 1371 | file_inclusion_pattern = (r".+\.css$",) |
[email protected] | 9a48e3f8 | 2014-05-22 00:06:25 | [diff] [blame] | 1372 | black_list = (_EXCLUDED_PATHS + |
| 1373 | _TEST_CODE_EXCLUDED_PATHS + |
| 1374 | input_api.DEFAULT_BLACK_LIST + |
| 1375 | (r"^chrome/common/extensions/docs", |
| 1376 | r"^chrome/docs", |
| 1377 | r"^native_client_sdk")) |
| 1378 | file_filter = lambda f: input_api.FilterSourceFile( |
| 1379 | f, white_list=file_inclusion_pattern, black_list=black_list) |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 1380 | for fpath in input_api.AffectedFiles(file_filter=file_filter): |
| 1381 | for line_num, line in fpath.ChangedContents(): |
| 1382 | for (deprecated_value, value) in _DEPRECATED_CSS: |
dbeam | 070cfe6 | 2014-10-22 06:44:02 | [diff] [blame] | 1383 | if deprecated_value in line: |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 1384 | results.append(output_api.PresubmitError( |
| 1385 | "%s:%d: Use of deprecated CSS %s, use %s instead" % |
| 1386 | (fpath.LocalPath(), line_num, deprecated_value, value))) |
| 1387 | return results |
| 1388 | |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1389 | |
dbeam | 070cfe6 | 2014-10-22 06:44:02 | [diff] [blame] | 1390 | _DEPRECATED_JS = [ |
| 1391 | ( "__lookupGetter__", "Object.getOwnPropertyDescriptor" ), |
| 1392 | ( "__defineGetter__", "Object.defineProperty" ), |
| 1393 | ( "__defineSetter__", "Object.defineProperty" ), |
| 1394 | ] |
| 1395 | |
| 1396 | def _CheckNoDeprecatedJS(input_api, output_api): |
| 1397 | """Make sure that we don't use deprecated JS in Chrome code.""" |
| 1398 | results = [] |
| 1399 | file_inclusion_pattern = (r".+\.js$",) # TODO(dbeam): .html? |
| 1400 | black_list = (_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS + |
| 1401 | input_api.DEFAULT_BLACK_LIST) |
| 1402 | file_filter = lambda f: input_api.FilterSourceFile( |
| 1403 | f, white_list=file_inclusion_pattern, black_list=black_list) |
| 1404 | for fpath in input_api.AffectedFiles(file_filter=file_filter): |
| 1405 | for lnum, line in fpath.ChangedContents(): |
| 1406 | for (deprecated, replacement) in _DEPRECATED_JS: |
| 1407 | if deprecated in line: |
| 1408 | results.append(output_api.PresubmitError( |
| 1409 | "%s:%d: Use of deprecated JS %s, use %s instead" % |
| 1410 | (fpath.LocalPath(), lnum, deprecated, replacement))) |
| 1411 | return results |
| 1412 | |
| 1413 | |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 1414 | def _CommonChecks(input_api, output_api): |
| 1415 | """Checks common to both upload and commit.""" |
| 1416 | results = [] |
| 1417 | results.extend(input_api.canned_checks.PanProjectChecks( |
[email protected] | 3de922f | 2013-12-20 13:27:38 | [diff] [blame] | 1418 | input_api, output_api, |
| 1419 | excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1420 | results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 1421 | results.extend( |
[email protected] | 760deea | 2013-12-10 19:33:49 | [diff] [blame] | 1422 | _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 1423 | results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
[email protected] | 72df4e78 | 2012-06-21 16:28:18 | [diff] [blame] | 1424 | results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 1425 | results.extend(_CheckNoNewWStrings(input_api, output_api)) |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 1426 | results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 1427 | results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
[email protected] | 6c063c6 | 2012-07-11 19:11:06 | [diff] [blame] | 1428 | results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
[email protected] | e747905 | 2012-09-19 00:26:12 | [diff] [blame] | 1429 | results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) |
[email protected] | 55f9f38 | 2012-07-31 11:02:18 | [diff] [blame] | 1430 | results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
[email protected] | fbcafe5a | 2012-08-08 15:31:22 | [diff] [blame] | 1431 | results.extend(_CheckFilePermissions(input_api, output_api)) |
[email protected] | c8278b3 | 2012-10-30 20:35:49 | [diff] [blame] | 1432 | results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) |
[email protected] | 2309b0fa0 | 2012-11-16 12:18:27 | [diff] [blame] | 1433 | results.extend(_CheckIncludeOrder(input_api, output_api)) |
[email protected] | 70ca7775 | 2012-11-20 03:45:03 | [diff] [blame] | 1434 | results.extend(_CheckForVersionControlConflicts(input_api, output_api)) |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 1435 | results.extend(_CheckPatchFiles(input_api, output_api)) |
[email protected] | 06e6d0ff | 2012-12-11 01:36:44 | [diff] [blame] | 1436 | results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) |
[email protected] | d253001 | 2013-01-25 16:39:27 | [diff] [blame] | 1437 | results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1438 | results.extend(_CheckForInvalidOSMacros(input_api, output_api)) |
lliabraa | 35bab393 | 2014-10-01 12:16:44 | [diff] [blame] | 1439 | results.extend(_CheckForInvalidIfDefinedMacros(input_api, output_api)) |
danakj | 3c84d0c | 2014-10-06 15:35:46 | [diff] [blame] | 1440 | # TODO(danakj): Remove this when base/move.h is removed. |
| 1441 | results.extend(_CheckForUsingSideEffectsOfPass(input_api, output_api)) |
[email protected] | e871964c | 2013-05-13 14:14:55 | [diff] [blame] | 1442 | results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) |
[email protected] | 9f919cc | 2013-07-31 03:04:04 | [diff] [blame] | 1443 | results.extend( |
| 1444 | input_api.canned_checks.CheckChangeHasNoTabs( |
| 1445 | input_api, |
| 1446 | output_api, |
| 1447 | source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
[email protected] | 8521856 | 2013-11-22 07:41:40 | [diff] [blame] | 1448 | results.extend(_CheckSpamLogging(input_api, output_api)) |
[email protected] | 49aa76a | 2013-12-04 06:59:16 | [diff] [blame] | 1449 | results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
[email protected] | 5fe0f874 | 2013-11-29 01:04:59 | [diff] [blame] | 1450 | results.extend(_CheckCygwinShell(input_api, output_api)) |
[email protected] | 999261d | 2014-03-03 20:08:08 | [diff] [blame] | 1451 | results.extend(_CheckUserActionUpdate(input_api, output_api)) |
[email protected] | fd20b90 | 2014-05-09 02:14:53 | [diff] [blame] | 1452 | results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) |
dbeam | 070cfe6 | 2014-10-22 06:44:02 | [diff] [blame] | 1453 | results.extend(_CheckNoDeprecatedJS(input_api, output_api)) |
[email protected] | 99171a9 | 2014-06-03 08:44:47 | [diff] [blame] | 1454 | results.extend(_CheckParseErrors(input_api, output_api)) |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 1455 | results.extend(_CheckForIPCRules(input_api, output_api)) |
mnaganov | 9b9b1fe8 | 2014-12-11 16:30:36 | [diff] [blame] | 1456 | results.extend(_CheckForCopyrightedCode(input_api, output_api)) |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 1457 | results.extend(_CheckForWindowsLineEndings(input_api, output_api)) |
glider | e61efad | 2015-02-18 17:39:43 | [diff] [blame] | 1458 | results.extend(_CheckSingletonInHeaders(input_api, output_api)) |
[email protected] | 2299dcf | 2012-11-15 19:56:24 | [diff] [blame] | 1459 | |
| 1460 | if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
| 1461 | results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 1462 | input_api, output_api, |
| 1463 | input_api.PresubmitLocalPath(), |
[email protected] | 6be6338 | 2013-01-21 15:42:38 | [diff] [blame] | 1464 | whitelist=[r'^PRESUBMIT_test\.py$'])) |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 1465 | return results |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 1466 | |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 1467 | |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1468 | def _CheckAuthorizedAuthor(input_api, output_api): |
| 1469 | """For non-googler/chromites committers, verify the author's email address is |
| 1470 | in AUTHORS. |
| 1471 | """ |
[email protected] | 9bb9cb8 | 2011-06-13 20:43:01 | [diff] [blame] | 1472 | # TODO(maruel): Add it to input_api? |
| 1473 | import fnmatch |
| 1474 | |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1475 | author = input_api.change.author_email |
[email protected] | 9bb9cb8 | 2011-06-13 20:43:01 | [diff] [blame] | 1476 | if not author: |
| 1477 | input_api.logging.info('No author, skipping AUTHOR check') |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1478 | return [] |
[email protected] | c9966329 | 2011-05-31 19:46:08 | [diff] [blame] | 1479 | authors_path = input_api.os_path.join( |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1480 | input_api.PresubmitLocalPath(), 'AUTHORS') |
| 1481 | valid_authors = ( |
| 1482 | input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line) |
| 1483 | for line in open(authors_path)) |
[email protected] | ac54b13 | 2011-06-06 18:11:18 | [diff] [blame] | 1484 | valid_authors = [item.group(1).lower() for item in valid_authors if item] |
[email protected] | d8b50be | 2011-06-15 14:19:44 | [diff] [blame] | 1485 | if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors): |
[email protected] | 5861efb | 2013-01-07 18:33:23 | [diff] [blame] | 1486 | input_api.logging.info('Valid authors are %s', ', '.join(valid_authors)) |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 1487 | return [output_api.PresubmitPromptWarning( |
| 1488 | ('%s is not in AUTHORS file. If you are a new contributor, please visit' |
| 1489 | '\n' |
| 1490 | 'http://www.chromium.org/developers/contributing-code and read the ' |
| 1491 | '"Legal" section\n' |
| 1492 | 'If you are a chromite, verify the contributor signed the CLA.') % |
| 1493 | author)] |
| 1494 | return [] |
| 1495 | |
| 1496 | |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 1497 | def _CheckPatchFiles(input_api, output_api): |
| 1498 | problems = [f.LocalPath() for f in input_api.AffectedFiles() |
| 1499 | if f.LocalPath().endswith(('.orig', '.rej'))] |
| 1500 | if problems: |
| 1501 | return [output_api.PresubmitError( |
| 1502 | "Don't commit .rej and .orig files.", problems)] |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 1503 | else: |
| 1504 | return [] |
[email protected] | b8079ae4a | 2012-12-05 19:56:49 | [diff] [blame] | 1505 | |
| 1506 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1507 | def _DidYouMeanOSMacro(bad_macro): |
| 1508 | try: |
| 1509 | return {'A': 'OS_ANDROID', |
| 1510 | 'B': 'OS_BSD', |
| 1511 | 'C': 'OS_CHROMEOS', |
| 1512 | 'F': 'OS_FREEBSD', |
| 1513 | 'L': 'OS_LINUX', |
| 1514 | 'M': 'OS_MACOSX', |
| 1515 | 'N': 'OS_NACL', |
| 1516 | 'O': 'OS_OPENBSD', |
| 1517 | 'P': 'OS_POSIX', |
| 1518 | 'S': 'OS_SOLARIS', |
| 1519 | 'W': 'OS_WIN'}[bad_macro[3].upper()] |
| 1520 | except KeyError: |
| 1521 | return '' |
| 1522 | |
| 1523 | |
| 1524 | def _CheckForInvalidOSMacrosInFile(input_api, f): |
| 1525 | """Check for sensible looking, totally invalid OS macros.""" |
| 1526 | preprocessor_statement = input_api.re.compile(r'^\s*#') |
| 1527 | os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)') |
| 1528 | results = [] |
| 1529 | for lnum, line in f.ChangedContents(): |
| 1530 | if preprocessor_statement.search(line): |
| 1531 | for match in os_macro.finditer(line): |
| 1532 | if not match.group(1) in _VALID_OS_MACROS: |
| 1533 | good = _DidYouMeanOSMacro(match.group(1)) |
| 1534 | did_you_mean = ' (did you mean %s?)' % good if good else '' |
| 1535 | results.append(' %s:%d %s%s' % (f.LocalPath(), |
| 1536 | lnum, |
| 1537 | match.group(1), |
| 1538 | did_you_mean)) |
| 1539 | return results |
| 1540 | |
| 1541 | |
| 1542 | def _CheckForInvalidOSMacros(input_api, output_api): |
| 1543 | """Check all affected files for invalid OS macros.""" |
| 1544 | bad_macros = [] |
| 1545 | for f in input_api.AffectedFiles(): |
| 1546 | if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')): |
| 1547 | bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f)) |
| 1548 | |
| 1549 | if not bad_macros: |
| 1550 | return [] |
| 1551 | |
| 1552 | return [output_api.PresubmitError( |
| 1553 | 'Possibly invalid OS macro[s] found. Please fix your code\n' |
| 1554 | 'or add your macro to src/PRESUBMIT.py.', bad_macros)] |
| 1555 | |
lliabraa | 35bab393 | 2014-10-01 12:16:44 | [diff] [blame] | 1556 | |
| 1557 | def _CheckForInvalidIfDefinedMacrosInFile(input_api, f): |
| 1558 | """Check all affected files for invalid "if defined" macros.""" |
| 1559 | ALWAYS_DEFINED_MACROS = ( |
| 1560 | "TARGET_CPU_PPC", |
| 1561 | "TARGET_CPU_PPC64", |
| 1562 | "TARGET_CPU_68K", |
| 1563 | "TARGET_CPU_X86", |
| 1564 | "TARGET_CPU_ARM", |
| 1565 | "TARGET_CPU_MIPS", |
| 1566 | "TARGET_CPU_SPARC", |
| 1567 | "TARGET_CPU_ALPHA", |
| 1568 | "TARGET_IPHONE_SIMULATOR", |
| 1569 | "TARGET_OS_EMBEDDED", |
| 1570 | "TARGET_OS_IPHONE", |
| 1571 | "TARGET_OS_MAC", |
| 1572 | "TARGET_OS_UNIX", |
| 1573 | "TARGET_OS_WIN32", |
| 1574 | ) |
| 1575 | ifdef_macro = input_api.re.compile(r'^\s*#.*(?:ifdef\s|defined\()([^\s\)]+)') |
| 1576 | results = [] |
| 1577 | for lnum, line in f.ChangedContents(): |
| 1578 | for match in ifdef_macro.finditer(line): |
| 1579 | if match.group(1) in ALWAYS_DEFINED_MACROS: |
| 1580 | always_defined = ' %s is always defined. ' % match.group(1) |
| 1581 | did_you_mean = 'Did you mean \'#if %s\'?' % match.group(1) |
| 1582 | results.append(' %s:%d %s\n\t%s' % (f.LocalPath(), |
| 1583 | lnum, |
| 1584 | always_defined, |
| 1585 | did_you_mean)) |
| 1586 | return results |
| 1587 | |
| 1588 | |
| 1589 | def _CheckForInvalidIfDefinedMacros(input_api, output_api): |
| 1590 | """Check all affected files for invalid "if defined" macros.""" |
| 1591 | bad_macros = [] |
| 1592 | for f in input_api.AffectedFiles(): |
| 1593 | if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): |
| 1594 | bad_macros.extend(_CheckForInvalidIfDefinedMacrosInFile(input_api, f)) |
| 1595 | |
| 1596 | if not bad_macros: |
| 1597 | return [] |
| 1598 | |
| 1599 | return [output_api.PresubmitError( |
| 1600 | 'Found ifdef check on always-defined macro[s]. Please fix your code\n' |
| 1601 | 'or check the list of ALWAYS_DEFINED_MACROS in src/PRESUBMIT.py.', |
| 1602 | bad_macros)] |
| 1603 | |
| 1604 | |
danakj | 3c84d0c | 2014-10-06 15:35:46 | [diff] [blame] | 1605 | def _CheckForUsingSideEffectsOfPass(input_api, output_api): |
| 1606 | """Check all affected files for using side effects of Pass.""" |
| 1607 | errors = [] |
| 1608 | for f in input_api.AffectedFiles(): |
| 1609 | if f.LocalPath().endswith(('.h', '.c', '.cc', '.m', '.mm')): |
| 1610 | for lnum, line in f.ChangedContents(): |
| 1611 | # Disallow Foo(*my_scoped_thing.Pass()); See crbug.com/418297. |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1612 | if input_api.re.search(r'\*[a-zA-Z0-9_]+\.Pass\(\)', line): |
danakj | 3c84d0c | 2014-10-06 15:35:46 | [diff] [blame] | 1613 | errors.append(output_api.PresubmitError( |
| 1614 | ('%s:%d uses *foo.Pass() to delete the contents of scoped_ptr. ' + |
| 1615 | 'See crbug.com/418297.') % (f.LocalPath(), lnum))) |
| 1616 | return errors |
| 1617 | |
| 1618 | |
mlamouri | a8227262 | 2014-09-16 18:45:04 | [diff] [blame] | 1619 | def _CheckForIPCRules(input_api, output_api): |
| 1620 | """Check for same IPC rules described in |
| 1621 | http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc |
| 1622 | """ |
| 1623 | base_pattern = r'IPC_ENUM_TRAITS\(' |
| 1624 | inclusion_pattern = input_api.re.compile(r'(%s)' % base_pattern) |
| 1625 | comment_pattern = input_api.re.compile(r'//.*(%s)' % base_pattern) |
| 1626 | |
| 1627 | problems = [] |
| 1628 | for f in input_api.AffectedSourceFiles(None): |
| 1629 | local_path = f.LocalPath() |
| 1630 | if not local_path.endswith('.h'): |
| 1631 | continue |
| 1632 | for line_number, line in f.ChangedContents(): |
| 1633 | if inclusion_pattern.search(line) and not comment_pattern.search(line): |
| 1634 | problems.append( |
| 1635 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
| 1636 | |
| 1637 | if problems: |
| 1638 | return [output_api.PresubmitPromptWarning( |
| 1639 | _IPC_ENUM_TRAITS_DEPRECATED, problems)] |
| 1640 | else: |
| 1641 | return [] |
| 1642 | |
[email protected] | b00342e7f | 2013-03-26 16:21:54 | [diff] [blame] | 1643 | |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 1644 | def _CheckForWindowsLineEndings(input_api, output_api): |
| 1645 | """Check source code and known ascii text files for Windows style line |
| 1646 | endings. |
| 1647 | """ |
earthdok | 1b5e0ee | 2015-03-10 15:19:10 | [diff] [blame] | 1648 | known_text_files = r'.*\.(txt|html|htm|mhtml|py|gyp|gypi|gn|isolate)$' |
mostynb | b639aca5 | 2015-01-07 20:31:23 | [diff] [blame] | 1649 | |
| 1650 | file_inclusion_pattern = ( |
| 1651 | known_text_files, |
| 1652 | r'.+%s' % _IMPLEMENTATION_EXTENSIONS |
| 1653 | ) |
| 1654 | |
| 1655 | filter = lambda f: input_api.FilterSourceFile( |
| 1656 | f, white_list=file_inclusion_pattern, black_list=None) |
| 1657 | files = [f.LocalPath() for f in |
| 1658 | input_api.AffectedSourceFiles(filter)] |
| 1659 | |
| 1660 | problems = [] |
| 1661 | |
| 1662 | for file in files: |
| 1663 | fp = open(file, 'r') |
| 1664 | for line in fp: |
| 1665 | if line.endswith('\r\n'): |
| 1666 | problems.append(file) |
| 1667 | break |
| 1668 | fp.close() |
| 1669 | |
| 1670 | if problems: |
| 1671 | return [output_api.PresubmitPromptWarning('Are you sure that you want ' |
| 1672 | 'these files to contain Windows style line endings?\n' + |
| 1673 | '\n'.join(problems))] |
| 1674 | |
| 1675 | return [] |
| 1676 | |
| 1677 | |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 1678 | def CheckChangeOnUpload(input_api, output_api): |
| 1679 | results = [] |
| 1680 | results.extend(_CommonChecks(input_api, output_api)) |
tandrii | ef66469 | 2014-09-23 14:51:47 | [diff] [blame] | 1681 | results.extend(_CheckValidHostsInDEPS(input_api, output_api)) |
aurimas | 8d3bc1c5 | 2014-10-15 01:02:17 | [diff] [blame] | 1682 | results.extend(_CheckJavaStyle(input_api, output_api)) |
scottmg | 39b2995 | 2014-12-08 18:31:28 | [diff] [blame] | 1683 | results.extend( |
| 1684 | input_api.canned_checks.CheckGNFormatted(input_api, output_api)) |
mcasas | b7440c28 | 2015-02-04 14:52:19 | [diff] [blame] | 1685 | results.extend(_CheckUmaHistogramChanges(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 1686 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 1687 | |
| 1688 | |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1689 | def GetTryServerMasterForBot(bot): |
| 1690 | """Returns the Try Server master for the given bot. |
| 1691 | |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 1692 | It tries to guess the master from the bot name, but may still fail |
| 1693 | and return None. There is no longer a default master. |
| 1694 | """ |
| 1695 | # Potentially ambiguous bot names are listed explicitly. |
| 1696 | master_map = { |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 1697 | 'chromium_presubmit': 'tryserver.chromium.linux', |
| 1698 | 'blink_presubmit': 'tryserver.chromium.linux', |
| 1699 | 'tools_build_presubmit': 'tryserver.chromium.linux', |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1700 | } |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 1701 | master = master_map.get(bot) |
| 1702 | if not master: |
sergiyb | 37fd293f | 2015-02-26 06:55:01 | [diff] [blame] | 1703 | if 'linux' in bot or 'android' in bot or 'presubmit' in bot: |
[email protected] | 0bb11236 | 2014-07-26 04:38:32 | [diff] [blame] | 1704 | master = 'tryserver.chromium.linux' |
| 1705 | elif 'win' in bot: |
| 1706 | master = 'tryserver.chromium.win' |
| 1707 | elif 'mac' in bot or 'ios' in bot: |
| 1708 | master = 'tryserver.chromium.mac' |
| 1709 | return master |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1710 | |
| 1711 | |
Paweł Hajdan, Jr | 5508378 | 2014-12-19 20:32:56 | [diff] [blame] | 1712 | def GetDefaultTryConfigs(bots): |
| 1713 | """Returns a list of ('bot', set(['tests']), filtered by [bots]. |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1714 | """ |
| 1715 | |
Paweł Hajdan, Jr | 5508378 | 2014-12-19 20:32:56 | [diff] [blame] | 1716 | builders_and_tests = dict((bot, set(['defaulttests'])) for bot in bots) |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1717 | |
| 1718 | # Build up the mapping from tryserver master to bot/test. |
| 1719 | out = dict() |
Paweł Hajdan, Jr | 5508378 | 2014-12-19 20:32:56 | [diff] [blame] | 1720 | for bot, tests in builders_and_tests.iteritems(): |
[email protected] | 1bfb832 | 2014-04-23 01:02:41 | [diff] [blame] | 1721 | out.setdefault(GetTryServerMasterForBot(bot), {})[bot] = tests |
| 1722 | return out |
[email protected] | 38c6a51 | 2013-12-18 23:48:01 | [diff] [blame] | 1723 | |
| 1724 | |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 1725 | def CheckChangeOnCommit(input_api, output_api): |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 1726 | results = [] |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 1727 | results.extend(_CommonChecks(input_api, output_api)) |
[email protected] | dd805fe | 2009-10-01 08:11:51 | [diff] [blame] | 1728 | # TODO(thestig) temporarily disabled, doesn't work in third_party/ |
| 1729 | #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories( |
| 1730 | # input_api, output_api, sources)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 1731 | # Make sure the tree is 'open'. |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 1732 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
[email protected] | 7f23815 | 2009-08-12 19:00:34 | [diff] [blame] | 1733 | input_api, |
| 1734 | output_api, |
[email protected] | 2fdd1f36 | 2013-01-16 03:56:03 | [diff] [blame] | 1735 | json_url='http://chromium-status.appspot.com/current?format=json')) |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 1736 | |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 1737 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 1738 | input_api, output_api)) |
[email protected] | c4b4756 | 2011-12-05 23:39:41 | [diff] [blame] | 1739 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 1740 | input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 1741 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 1742 | |
| 1743 | |
[email protected] | 7468ac52 | 2014-03-12 23:35:57 | [diff] [blame] | 1744 | def GetPreferredTryMasters(project, change): |
mohan.reddy | f21db96 | 2014-10-16 12:26:47 | [diff] [blame] | 1745 | import re |
[email protected] | 4ce995ea | 2012-06-27 02:13:10 | [diff] [blame] | 1746 | files = change.LocalPaths() |
| 1747 | |
Paweł Hajdan, Jr | ef2afd4 | 2015-01-07 15:59:52 | [diff] [blame] | 1748 | import os |
| 1749 | import json |
| 1750 | with open(os.path.join( |
| 1751 | change.RepositoryRoot(), 'testing', 'commit_queue', 'config.json')) as f: |
| 1752 | cq_config = json.load(f) |
smut | 3ef206e1 | 2015-03-20 09:30:00 | [diff] [blame] | 1753 | cq_verifiers = cq_config.get('verifiers_no_patch', {}) |
| 1754 | cq_try_jobs = cq_verifiers.get('try_job_verifier', {}) |
| 1755 | builders = cq_try_jobs.get('launched', {}) |
| 1756 | |
| 1757 | for master, master_config in cq_try_jobs.get('triggered', {}).iteritems(): |
Paweł Hajdan, Jr | ef2afd4 | 2015-01-07 15:59:52 | [diff] [blame] | 1758 | for triggered_bot in master_config: |
| 1759 | builders.get(master, {}).pop(triggered_bot, None) |
[email protected] | 911753b | 2012-08-02 12:11:54 | [diff] [blame] | 1760 | |
Paweł Hajdan, Jr | 4026dbc | 2015-01-14 09:22:32 | [diff] [blame] | 1761 | # Explicitly iterate over copies of dicts since we mutate them. |
| 1762 | for master in builders.keys(): |
| 1763 | for builder in builders[master].keys(): |
| 1764 | # Do not trigger presubmit builders, since they're likely to fail |
| 1765 | # (e.g. OWNERS checks before finished code review), and we're |
| 1766 | # running local presubmit anyway. |
| 1767 | if 'presubmit' in builder: |
| 1768 | builders[master].pop(builder) |
| 1769 | |
Paweł Hajdan, Jr | ef2afd4 | 2015-01-07 15:59:52 | [diff] [blame] | 1770 | return builders |