[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 |
[email protected] | 50d7d721e | 2009-11-15 17:56:18 | [diff] [blame] | 8 | for more details about the presubmit API built into gcl. |
[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] | 9d16ad1 | 2011-12-14 20:49:47 | [diff] [blame] | 12 | import re |
| 13 | |
| 14 | |
[email protected] | 379e7dd | 2010-01-28 17:39:21 | [diff] [blame] | 15 | _EXCLUDED_PATHS = ( |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 16 | r"^breakpad[\\\/].*", |
[email protected] | a18130a | 2012-01-03 17:52:08 | [diff] [blame] | 17 | r"^native_client_sdk[\\\/].*", |
| 18 | r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 19 | r"^skia[\\\/].*", |
| 20 | r"^v8[\\\/].*", |
| 21 | r".*MakeFile$", |
[email protected] | 1084ccc | 2012-03-14 03:22:53 | [diff] [blame] | 22 | r".+_autogen\.h$", |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 23 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 24 | |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 25 | |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 26 | _TEST_ONLY_WARNING = ( |
| 27 | 'You might be calling functions intended only for testing from\n' |
| 28 | 'production code. It is OK to ignore this warning if you know what\n' |
| 29 | 'you are doing, as the heuristics used to detect the situation are\n' |
| 30 | 'not perfect. The commit queue will not block on this warning.\n' |
| 31 | 'Email [email protected] if you have questions.') |
| 32 | |
| 33 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 34 | _BANNED_OBJC_FUNCTIONS = ( |
| 35 | ( |
| 36 | 'addTrackingRect:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame^] | 37 | ( |
| 38 | 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 39 | 'prohibited. Please use CrTrackingArea instead.', |
| 40 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 41 | ), |
| 42 | False, |
| 43 | ), |
| 44 | ( |
| 45 | 'NSTrackingArea', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame^] | 46 | ( |
| 47 | 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 48 | 'instead.', |
| 49 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 50 | ), |
| 51 | False, |
| 52 | ), |
| 53 | ( |
| 54 | 'convertPointFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame^] | 55 | ( |
| 56 | 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 57 | 'Please use |convertPoint:(point) fromView:nil| instead.', |
| 58 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 59 | ), |
| 60 | True, |
| 61 | ), |
| 62 | ( |
| 63 | 'convertPointToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame^] | 64 | ( |
| 65 | 'The use of -[NSView convertPointToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 66 | 'Please use |convertPoint:(point) toView:nil| instead.', |
| 67 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 68 | ), |
| 69 | True, |
| 70 | ), |
| 71 | ( |
| 72 | 'convertRectFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame^] | 73 | ( |
| 74 | 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 75 | 'Please use |convertRect:(point) fromView:nil| instead.', |
| 76 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 77 | ), |
| 78 | True, |
| 79 | ), |
| 80 | ( |
| 81 | 'convertRectToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame^] | 82 | ( |
| 83 | 'The use of -[NSView convertRectToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 84 | 'Please use |convertRect:(point) toView:nil| instead.', |
| 85 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 86 | ), |
| 87 | True, |
| 88 | ), |
| 89 | ( |
| 90 | 'convertSizeFromBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame^] | 91 | ( |
| 92 | 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 93 | 'Please use |convertSize:(point) fromView:nil| instead.', |
| 94 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 95 | ), |
| 96 | True, |
| 97 | ), |
| 98 | ( |
| 99 | 'convertSizeToBase:', |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame^] | 100 | ( |
| 101 | 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.', |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 102 | 'Please use |convertSize:(point) toView:nil| instead.', |
| 103 | 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts', |
| 104 | ), |
| 105 | True, |
| 106 | ), |
| 107 | ) |
| 108 | |
| 109 | |
| 110 | _BANNED_CPP_FUNCTIONS = ( |
[email protected] | 23e6cbc | 2012-06-16 18:51:20 | [diff] [blame^] | 111 | # Make sure that gtest's FRIEND_TEST() macro is not used; the |
| 112 | # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be |
| 113 | # used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes. |
| 114 | ( |
| 115 | 'FRIEND_TEST(', |
| 116 | ( |
| 117 | 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include' |
| 118 | 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.', |
| 119 | ), |
| 120 | False, |
| 121 | ), |
| 122 | ( |
| 123 | 'ScopedAllowIO', |
| 124 | ( |
| 125 | 'New code should not use ScopedAllowIO. Post a task to the blocking pool' |
| 126 | 'or the FILE thread instead.', |
| 127 | ), |
| 128 | False, |
| 129 | ), |
| 130 | ( |
| 131 | 'FilePathWatcher::Delegate', |
| 132 | ( |
| 133 | 'New code should not use FilePathWatcher::Delegate. Use the callback' |
| 134 | 'interface instead.', |
| 135 | ), |
| 136 | False, |
| 137 | ), |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 138 | ) |
| 139 | |
| 140 | |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 141 | |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 142 | def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): |
| 143 | """Attempts to prevent use of functions intended only for testing in |
| 144 | non-testing code. For now this is just a best-effort implementation |
| 145 | that ignores header files and may have some false positives. A |
| 146 | better implementation would probably need a proper C++ parser. |
| 147 | """ |
| 148 | # We only scan .cc files and the like, as the declaration of |
| 149 | # for-testing functions in header files are hard to distinguish from |
| 150 | # calls to such functions without a proper C++ parser. |
[email protected] | 403bfbc9 | 2012-06-11 23:30:09 | [diff] [blame] | 151 | platform_specifiers = r'(_(android|chromeos|gtk|mac|posix|win))?' |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 152 | source_extensions = r'\.(cc|cpp|cxx|mm)$' |
| 153 | file_inclusion_pattern = r'.+%s' % source_extensions |
[email protected] | 19e77fd | 2011-10-20 05:24:05 | [diff] [blame] | 154 | file_exclusion_patterns = ( |
[email protected] | e21ce38 | 2012-01-04 18:48:25 | [diff] [blame] | 155 | r'.*[/\\](test_|mock_).+%s' % source_extensions, |
[email protected] | c762d25 | 2012-02-28 02:07:24 | [diff] [blame] | 156 | r'.+_test_(base|support|util)%s' % source_extensions, |
[email protected] | 403bfbc9 | 2012-06-11 23:30:09 | [diff] [blame] | 157 | r'.+_(api|browser|perf|unit|ui)?test%s%s' % (platform_specifiers, |
| 158 | source_extensions), |
[email protected] | 19e77fd | 2011-10-20 05:24:05 | [diff] [blame] | 159 | r'.+profile_sync_service_harness%s' % source_extensions, |
| 160 | ) |
| 161 | path_exclusion_patterns = ( |
| 162 | r'.*[/\\](test|tool(s)?)[/\\].*', |
| 163 | # At request of folks maintaining this folder. |
| 164 | r'chrome[/\\]browser[/\\]automation[/\\].*', |
| 165 | ) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 166 | |
| 167 | base_function_pattern = r'ForTest(ing)?|for_test(ing)?' |
| 168 | inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern) |
| 169 | exclusion_pattern = input_api.re.compile( |
| 170 | r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % ( |
| 171 | base_function_pattern, base_function_pattern)) |
| 172 | |
| 173 | def FilterFile(affected_file): |
[email protected] | 19e77fd | 2011-10-20 05:24:05 | [diff] [blame] | 174 | black_list = (file_exclusion_patterns + path_exclusion_patterns + |
[email protected] | 3afb12a4 | 2011-08-15 13:48:33 | [diff] [blame] | 175 | _EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 176 | return input_api.FilterSourceFile( |
| 177 | affected_file, |
| 178 | white_list=(file_inclusion_pattern, ), |
| 179 | black_list=black_list) |
| 180 | |
| 181 | problems = [] |
| 182 | for f in input_api.AffectedSourceFiles(FilterFile): |
| 183 | local_path = f.LocalPath() |
| 184 | lines = input_api.ReadFile(f).splitlines() |
| 185 | line_number = 0 |
| 186 | for line in lines: |
| 187 | if (inclusion_pattern.search(line) and |
| 188 | not exclusion_pattern.search(line)): |
| 189 | problems.append( |
| 190 | '%s:%d\n %s' % (local_path, line_number, line.strip())) |
| 191 | line_number += 1 |
| 192 | |
| 193 | if problems: |
[email protected] | eea609a | 2011-11-18 13:10:12 | [diff] [blame] | 194 | if not input_api.is_committing: |
| 195 | return [output_api.PresubmitPromptWarning(_TEST_ONLY_WARNING, problems)] |
| 196 | else: |
| 197 | # We don't warn on commit, to avoid stopping commits going through CQ. |
| 198 | return [output_api.PresubmitNotifyResult(_TEST_ONLY_WARNING, problems)] |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 199 | else: |
| 200 | return [] |
| 201 | |
| 202 | |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 203 | def _CheckNoIOStreamInHeaders(input_api, output_api): |
| 204 | """Checks to make sure no .h files include <iostream>.""" |
| 205 | files = [] |
| 206 | pattern = input_api.re.compile(r'^#include\s*<iostream>', |
| 207 | input_api.re.MULTILINE) |
| 208 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 209 | if not f.LocalPath().endswith('.h'): |
| 210 | continue |
| 211 | contents = input_api.ReadFile(f) |
| 212 | if pattern.search(contents): |
| 213 | files.append(f) |
| 214 | |
| 215 | if len(files): |
| 216 | return [ output_api.PresubmitError( |
| 217 | 'Do not #include <iostream> in header files, since it inserts static ' + |
| 218 | 'initialization into every file including the header. Instead, ' + |
| 219 | '#include <ostream>. See http://crbug.com/94794', |
| 220 | files) ] |
| 221 | return [] |
| 222 | |
| 223 | |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 224 | def _CheckNoNewWStrings(input_api, output_api): |
| 225 | """Checks to make sure we don't introduce use of wstrings.""" |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 226 | problems = [] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 227 | for f in input_api.AffectedFiles(): |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 228 | if (not f.LocalPath().endswith(('.cc', '.h')) or |
| 229 | f.LocalPath().endswith('test.cc')): |
| 230 | continue |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 231 | |
[email protected] | b5c2429 | 2011-11-28 14:38:20 | [diff] [blame] | 232 | for line_num, line in f.ChangedContents(): |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 233 | if 'wstring' in line: |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 234 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 235 | |
[email protected] | 55463aa6 | 2011-10-12 00:48:27 | [diff] [blame] | 236 | if not problems: |
| 237 | return [] |
| 238 | return [output_api.PresubmitPromptWarning('New code should not use wstrings.' |
| 239 | ' If you are calling an API that accepts a wstring, fix the API.\n' + |
| 240 | '\n'.join(problems))] |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 241 | |
| 242 | |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 243 | def _CheckNoDEPSGIT(input_api, output_api): |
| 244 | """Make sure .DEPS.git is never modified manually.""" |
| 245 | if any(f.LocalPath().endswith('.DEPS.git') for f in |
| 246 | input_api.AffectedFiles()): |
| 247 | return [output_api.PresubmitError( |
| 248 | 'Never commit changes to .DEPS.git. This file is maintained by an\n' |
| 249 | 'automated system based on what\'s in DEPS and your changes will be\n' |
| 250 | 'overwritten.\n' |
| 251 | 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n' |
| 252 | 'for more information')] |
| 253 | return [] |
| 254 | |
| 255 | |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 256 | def _CheckNoBannedFunctions(input_api, output_api): |
| 257 | """Make sure that banned functions are not used.""" |
| 258 | warnings = [] |
| 259 | errors = [] |
| 260 | |
| 261 | file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) |
| 262 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 263 | for line_num, line in f.ChangedContents(): |
| 264 | for func_name, message, error in _BANNED_OBJC_FUNCTIONS: |
| 265 | if func_name in line: |
| 266 | problems = warnings; |
| 267 | if error: |
| 268 | problems = errors; |
| 269 | problems.append(' %s:%d:' % (f.LocalPath(), line_num)) |
| 270 | for message_line in message: |
| 271 | problems.append(' %s' % message_line) |
| 272 | |
| 273 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h')) |
| 274 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 275 | for line_num, line in f.ChangedContents(): |
| 276 | for func_name, message, error in _BANNED_CPP_FUNCTIONS: |
| 277 | if func_name in line: |
| 278 | problems = warnings; |
| 279 | if error: |
| 280 | problems = errors; |
| 281 | problems.append(' %s:%d:' % (f.LocalPath(), line_num)) |
| 282 | for message_line in message: |
| 283 | problems.append(' %s' % message_line) |
| 284 | |
| 285 | result = [] |
| 286 | if (warnings): |
| 287 | result.append(output_api.PresubmitPromptWarning( |
| 288 | 'Banned functions were used.\n' + '\n'.join(warnings))) |
| 289 | if (errors): |
| 290 | result.append(output_api.PresubmitError( |
| 291 | 'Banned functions were used.\n' + '\n'.join(errors))) |
| 292 | return result |
| 293 | |
| 294 | |
| 295 | |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 296 | def _CommonChecks(input_api, output_api): |
| 297 | """Checks common to both upload and commit.""" |
| 298 | results = [] |
| 299 | results.extend(input_api.canned_checks.PanProjectChecks( |
| 300 | input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 301 | results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
[email protected] | 5545985 | 2011-08-10 15:17:19 | [diff] [blame] | 302 | results.extend( |
| 303 | _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
[email protected] | 10689ca | 2011-09-02 02:31:54 | [diff] [blame] | 304 | results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
[email protected] | 8ea5d4b | 2011-09-13 21:49:22 | [diff] [blame] | 305 | results.extend(_CheckNoNewWStrings(input_api, output_api)) |
[email protected] | 2a8ac9c | 2011-10-19 17:20:44 | [diff] [blame] | 306 | results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
[email protected] | 127f18ec | 2012-06-16 05:05:59 | [diff] [blame] | 307 | results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 308 | return results |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 309 | |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 310 | |
| 311 | def _CheckSubversionConfig(input_api, output_api): |
| 312 | """Verifies the subversion config file is correctly setup. |
| 313 | |
| 314 | Checks that autoprops are enabled, returns an error otherwise. |
| 315 | """ |
| 316 | join = input_api.os_path.join |
| 317 | if input_api.platform == 'win32': |
| 318 | appdata = input_api.environ.get('APPDATA', '') |
| 319 | if not appdata: |
| 320 | return [output_api.PresubmitError('%APPDATA% is not configured.')] |
| 321 | path = join(appdata, 'Subversion', 'config') |
| 322 | else: |
| 323 | home = input_api.environ.get('HOME', '') |
| 324 | if not home: |
| 325 | return [output_api.PresubmitError('$HOME is not configured.')] |
| 326 | path = join(home, '.subversion', 'config') |
| 327 | |
| 328 | error_msg = ( |
| 329 | 'Please look at http://dev.chromium.org/developers/coding-style to\n' |
| 330 | 'configure your subversion configuration file. This enables automatic\n' |
[email protected] | c6a3c10b | 2011-01-24 16:14:20 | [diff] [blame] | 331 | 'properties to simplify the project maintenance.\n' |
| 332 | 'Pro-tip: just download and install\n' |
| 333 | 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n') |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 334 | |
| 335 | try: |
| 336 | lines = open(path, 'r').read().splitlines() |
| 337 | # Make sure auto-props is enabled and check for 2 Chromium standard |
| 338 | # auto-prop. |
| 339 | if (not '*.cc = svn:eol-style=LF' in lines or |
| 340 | not '*.pdf = svn:mime-type=application/pdf' in lines or |
| 341 | not 'enable-auto-props = yes' in lines): |
| 342 | return [ |
[email protected] | 79ed7e6 | 2011-02-21 21:08:53 | [diff] [blame] | 343 | output_api.PresubmitNotifyResult( |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 344 | 'It looks like you have not configured your subversion config ' |
[email protected] | b5359c0 | 2011-02-01 20:29:56 | [diff] [blame] | 345 | 'file or it is not up-to-date.\n' + error_msg) |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 346 | ] |
| 347 | except (OSError, IOError): |
| 348 | return [ |
[email protected] | 79ed7e6 | 2011-02-21 21:08:53 | [diff] [blame] | 349 | output_api.PresubmitNotifyResult( |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 350 | 'Can\'t find your subversion config file.\n' + error_msg) |
| 351 | ] |
| 352 | return [] |
| 353 | |
| 354 | |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 355 | def _CheckAuthorizedAuthor(input_api, output_api): |
| 356 | """For non-googler/chromites committers, verify the author's email address is |
| 357 | in AUTHORS. |
| 358 | """ |
[email protected] | 9bb9cb8 | 2011-06-13 20:43:01 | [diff] [blame] | 359 | # TODO(maruel): Add it to input_api? |
| 360 | import fnmatch |
| 361 | |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 362 | author = input_api.change.author_email |
[email protected] | 9bb9cb8 | 2011-06-13 20:43:01 | [diff] [blame] | 363 | if not author: |
| 364 | input_api.logging.info('No author, skipping AUTHOR check') |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 365 | return [] |
[email protected] | c9966329 | 2011-05-31 19:46:08 | [diff] [blame] | 366 | authors_path = input_api.os_path.join( |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 367 | input_api.PresubmitLocalPath(), 'AUTHORS') |
| 368 | valid_authors = ( |
| 369 | input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line) |
| 370 | for line in open(authors_path)) |
[email protected] | ac54b13 | 2011-06-06 18:11:18 | [diff] [blame] | 371 | valid_authors = [item.group(1).lower() for item in valid_authors if item] |
[email protected] | 9bb9cb8 | 2011-06-13 20:43:01 | [diff] [blame] | 372 | if input_api.verbose: |
| 373 | print 'Valid authors are %s' % ', '.join(valid_authors) |
[email protected] | d8b50be | 2011-06-15 14:19:44 | [diff] [blame] | 374 | if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors): |
[email protected] | 66daa70 | 2011-05-28 14:41:46 | [diff] [blame] | 375 | return [output_api.PresubmitPromptWarning( |
| 376 | ('%s is not in AUTHORS file. If you are a new contributor, please visit' |
| 377 | '\n' |
| 378 | 'http://www.chromium.org/developers/contributing-code and read the ' |
| 379 | '"Legal" section\n' |
| 380 | 'If you are a chromite, verify the contributor signed the CLA.') % |
| 381 | author)] |
| 382 | return [] |
| 383 | |
| 384 | |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 385 | def CheckChangeOnUpload(input_api, output_api): |
| 386 | results = [] |
| 387 | results.extend(_CommonChecks(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 388 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 389 | |
| 390 | |
| 391 | def CheckChangeOnCommit(input_api, output_api): |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 392 | results = [] |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 393 | results.extend(_CommonChecks(input_api, output_api)) |
[email protected] | dd805fe | 2009-10-01 08:11:51 | [diff] [blame] | 394 | # TODO(thestig) temporarily disabled, doesn't work in third_party/ |
| 395 | #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories( |
| 396 | # input_api, output_api, sources)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 397 | # Make sure the tree is 'open'. |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 398 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
[email protected] | 7f23815 | 2009-08-12 19:00:34 | [diff] [blame] | 399 | input_api, |
| 400 | output_api, |
[email protected] | 4efa4214 | 2010-08-26 01:29:26 | [diff] [blame] | 401 | json_url='http://chromium-status.appspot.com/current?format=json')) |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 402 | results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api, |
[email protected] | 4ddc5df | 2011-12-12 03:05:04 | [diff] [blame] | 403 | output_api, 'http://codereview.chromium.org', |
[email protected] | c1ba4c5 | 2012-03-09 14:23:28 | [diff] [blame] | 404 | ('win_rel', 'linux_rel', 'mac_rel, win:compile'), |
| 405 | '[email protected]')) |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 406 | |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 407 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 408 | input_api, output_api)) |
| 409 | results.extend(input_api.canned_checks.CheckChangeHasTestField( |
| 410 | input_api, output_api)) |
[email protected] | c4b4756 | 2011-12-05 23:39:41 | [diff] [blame] | 411 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 412 | input_api, output_api)) |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 413 | results.extend(_CheckSubversionConfig(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 414 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 415 | |
| 416 | |
[email protected] | 5efb2a82 | 2011-09-27 23:06:13 | [diff] [blame] | 417 | def GetPreferredTrySlaves(project, change): |
[email protected] | 50c3009 | 2012-02-15 04:21:36 | [diff] [blame] | 418 | affected_files = change.LocalPaths() |
| 419 | only_objc_files = all(f.endswith(('.mm', '.m')) for f in affected_files) |
[email protected] | 5efb2a82 | 2011-09-27 23:06:13 | [diff] [blame] | 420 | if only_objc_files: |
[email protected] | 4ddc5df | 2011-12-12 03:05:04 | [diff] [blame] | 421 | return ['mac_rel'] |
[email protected] | 1f262989 | 2012-05-07 19:23:12 | [diff] [blame] | 422 | preferred = ['win_rel', 'linux_rel', 'mac_rel', 'linux_clang:compile'] |
[email protected] | 9d16ad1 | 2011-12-14 20:49:47 | [diff] [blame] | 423 | aura_re = '_aura[^/]*[.][^/]*' |
[email protected] | 50c3009 | 2012-02-15 04:21:36 | [diff] [blame] | 424 | if any(re.search(aura_re, f) for f in affected_files): |
[email protected] | e9b2388 | 2012-02-03 01:05:49 | [diff] [blame] | 425 | preferred.append('linux_chromeos') |
[email protected] | d3b7e7cca | 2012-03-01 21:25:06 | [diff] [blame] | 426 | # Nothing in chrome/ |
| 427 | android_re_list = ('^base/', |
| 428 | '^build/common.gypi$', |
| 429 | '^content/', |
| 430 | '^ipc/', |
| 431 | '^jingle/', |
| 432 | '^media/', |
| 433 | '^net/', |
| 434 | '^sql/') |
| 435 | # Nothing that looks like win-only or aura-only |
| 436 | win_re = '_win\.(cc|h)$' |
| 437 | possibly_android = True |
| 438 | for non_android_re in (aura_re, win_re): |
| 439 | if all(re.search(non_android_re, f) for f in affected_files): |
| 440 | possibly_android = False |
| 441 | break |
| 442 | if possibly_android: |
| 443 | for f in change.AffectedFiles(): |
| 444 | if any(re.search(r, f.LocalPath()) for r in android_re_list): |
| 445 | preferred.append('android') |
| 446 | break |
[email protected] | 9d16ad1 | 2011-12-14 20:49:47 | [diff] [blame] | 447 | return preferred |