Correctly show disabled Flash versions in chrome://flash.
[chromium-blink-merge.git] / PRESUBMIT.py
blob0bb6e3dc27384758667977b726a10ddc0c12719c
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Top-level presubmit script for Chromium.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl.
9 """
12 import re
13 import subprocess
14 import sys
17 _EXCLUDED_PATHS = (
18 r"^breakpad[\\\/].*",
19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
20 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
21 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
22 r"^skia[\\\/].*",
23 r"^v8[\\\/].*",
24 r".*MakeFile$",
25 r".+_autogen\.h$",
26 r"^cc[\\\/].*",
27 r"^webkit[\\\/]compositor_bindings[\\\/].*",
28 r".+[\\\/]pnacl_shim\.c$",
32 _TEST_ONLY_WARNING = (
33 'You might be calling functions intended only for testing from\n'
34 'production code. It is OK to ignore this warning if you know what\n'
35 'you are doing, as the heuristics used to detect the situation are\n'
36 'not perfect. The commit queue will not block on this warning.\n'
37 'Email joi@chromium.org if you have questions.')
40 _INCLUDE_ORDER_WARNING = (
41 'Your #include order seems to be broken. Send mail to\n'
42 'marja@chromium.org if this is not the case.')
45 _BANNED_OBJC_FUNCTIONS = (
47 'addTrackingRect:',
49 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
50 'prohibited. Please use CrTrackingArea instead.',
51 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
53 False,
56 'NSTrackingArea',
58 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
59 'instead.',
60 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
62 False,
65 'convertPointFromBase:',
67 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
68 'Please use |convertPoint:(point) fromView:nil| instead.',
69 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
71 True,
74 'convertPointToBase:',
76 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
77 'Please use |convertPoint:(point) toView:nil| instead.',
78 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
80 True,
83 'convertRectFromBase:',
85 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
86 'Please use |convertRect:(point) fromView:nil| instead.',
87 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
89 True,
92 'convertRectToBase:',
94 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
95 'Please use |convertRect:(point) toView:nil| instead.',
96 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
98 True,
101 'convertSizeFromBase:',
103 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
104 'Please use |convertSize:(point) fromView:nil| instead.',
105 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
107 True,
110 'convertSizeToBase:',
112 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
113 'Please use |convertSize:(point) toView:nil| instead.',
114 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
116 True,
121 _BANNED_CPP_FUNCTIONS = (
122 # Make sure that gtest's FRIEND_TEST() macro is not used; the
123 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
124 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
126 'FRIEND_TEST(',
128 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
129 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
131 False,
135 'ScopedAllowIO',
137 'New code should not use ScopedAllowIO. Post a task to the blocking',
138 'pool or the FILE thread instead.',
140 True,
142 r"^content[\\\/]shell[\\\/]shell_browser_main\.cc$",
146 'FilePathWatcher::Delegate',
148 'New code should not use FilePathWatcher::Delegate. Use the callback',
149 'interface instead.',
151 False,
155 'browser::FindAnyBrowser',
157 'This function is deprecated and we\'re working on removing it. Pass',
158 'more context to get a Browser*, like a WebContents, window, or session',
159 'id. Talk to robertshield@ for more information.',
161 True,
165 'browser::FindOrCreateTabbedBrowser',
167 'This function is deprecated and we\'re working on removing it. Pass',
168 'more context to get a Browser*, like a WebContents, window, or session',
169 'id. Talk to robertshield@ for more information.',
171 True,
175 'RunAllPending()',
177 'This function is deprecated and we\'re working on removing it. Rename',
178 'to RunUntilIdle',
180 True,
187 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
188 """Attempts to prevent use of functions intended only for testing in
189 non-testing code. For now this is just a best-effort implementation
190 that ignores header files and may have some false positives. A
191 better implementation would probably need a proper C++ parser.
193 # We only scan .cc files and the like, as the declaration of
194 # for-testing functions in header files are hard to distinguish from
195 # calls to such functions without a proper C++ parser.
196 platform_specifiers = r'(_(android|chromeos|gtk|mac|posix|win))?'
197 source_extensions = r'\.(cc|cpp|cxx|mm)$'
198 file_inclusion_pattern = r'.+%s' % source_extensions
199 file_exclusion_patterns = (
200 r'.*[/\\](fake_|test_|mock_).+%s' % source_extensions,
201 r'.+_test_(base|support|util)%s' % source_extensions,
202 r'.+_(api|browser|perf|unit|ui)?test%s%s' % (platform_specifiers,
203 source_extensions),
204 r'.+profile_sync_service_harness%s' % source_extensions,
206 path_exclusion_patterns = (
207 r'.*[/\\](test|tool(s)?)[/\\].*',
208 # At request of folks maintaining this folder.
209 r'chrome[/\\]browser[/\\]automation[/\\].*',
212 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
213 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
214 exclusion_pattern = input_api.re.compile(
215 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
216 base_function_pattern, base_function_pattern))
218 def FilterFile(affected_file):
219 black_list = (file_exclusion_patterns + path_exclusion_patterns +
220 _EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)
221 return input_api.FilterSourceFile(
222 affected_file,
223 white_list=(file_inclusion_pattern, ),
224 black_list=black_list)
226 problems = []
227 for f in input_api.AffectedSourceFiles(FilterFile):
228 local_path = f.LocalPath()
229 lines = input_api.ReadFile(f).splitlines()
230 line_number = 0
231 for line in lines:
232 if (inclusion_pattern.search(line) and
233 not exclusion_pattern.search(line)):
234 problems.append(
235 '%s:%d\n %s' % (local_path, line_number, line.strip()))
236 line_number += 1
238 if problems:
239 if not input_api.is_committing:
240 return [output_api.PresubmitPromptWarning(_TEST_ONLY_WARNING, problems)]
241 else:
242 # We don't warn on commit, to avoid stopping commits going through CQ.
243 return [output_api.PresubmitNotifyResult(_TEST_ONLY_WARNING, problems)]
244 else:
245 return []
248 def _CheckNoIOStreamInHeaders(input_api, output_api):
249 """Checks to make sure no .h files include <iostream>."""
250 files = []
251 pattern = input_api.re.compile(r'^#include\s*<iostream>',
252 input_api.re.MULTILINE)
253 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
254 if not f.LocalPath().endswith('.h'):
255 continue
256 contents = input_api.ReadFile(f)
257 if pattern.search(contents):
258 files.append(f)
260 if len(files):
261 return [ output_api.PresubmitError(
262 'Do not #include <iostream> in header files, since it inserts static '
263 'initialization into every file including the header. Instead, '
264 '#include <ostream>. See http://crbug.com/94794',
265 files) ]
266 return []
269 def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
270 """Checks to make sure no source files use UNIT_TEST"""
271 problems = []
272 for f in input_api.AffectedFiles():
273 if (not f.LocalPath().endswith(('.cc', '.mm'))):
274 continue
276 for line_num, line in f.ChangedContents():
277 if 'UNIT_TEST' in line:
278 problems.append(' %s:%d' % (f.LocalPath(), line_num))
280 if not problems:
281 return []
282 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
283 '\n'.join(problems))]
286 def _CheckNoNewWStrings(input_api, output_api):
287 """Checks to make sure we don't introduce use of wstrings."""
288 problems = []
289 for f in input_api.AffectedFiles():
290 if (not f.LocalPath().endswith(('.cc', '.h')) or
291 f.LocalPath().endswith('test.cc')):
292 continue
294 allowWString = False
295 for line_num, line in f.ChangedContents():
296 if 'presubmit: allow wstring' in line:
297 allowWString = True
298 elif not allowWString and 'wstring' in line:
299 problems.append(' %s:%d' % (f.LocalPath(), line_num))
300 allowWString = False
301 else:
302 allowWString = False
304 if not problems:
305 return []
306 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
307 ' If you are calling a cross-platform API that accepts a wstring, '
308 'fix the API.\n' +
309 '\n'.join(problems))]
312 def _CheckNoDEPSGIT(input_api, output_api):
313 """Make sure .DEPS.git is never modified manually."""
314 if any(f.LocalPath().endswith('.DEPS.git') for f in
315 input_api.AffectedFiles()):
316 return [output_api.PresubmitError(
317 'Never commit changes to .DEPS.git. This file is maintained by an\n'
318 'automated system based on what\'s in DEPS and your changes will be\n'
319 'overwritten.\n'
320 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
321 'for more information')]
322 return []
325 def _CheckNoBannedFunctions(input_api, output_api):
326 """Make sure that banned functions are not used."""
327 warnings = []
328 errors = []
330 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
331 for f in input_api.AffectedFiles(file_filter=file_filter):
332 for line_num, line in f.ChangedContents():
333 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
334 if func_name in line:
335 problems = warnings;
336 if error:
337 problems = errors;
338 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
339 for message_line in message:
340 problems.append(' %s' % message_line)
342 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
343 for f in input_api.AffectedFiles(file_filter=file_filter):
344 for line_num, line in f.ChangedContents():
345 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
346 def IsBlacklisted(affected_file, blacklist):
347 local_path = affected_file.LocalPath()
348 for item in blacklist:
349 if input_api.re.match(item, local_path):
350 return True
351 return False
352 if IsBlacklisted(f, excluded_paths):
353 continue
354 if func_name in line:
355 problems = warnings;
356 if error:
357 problems = errors;
358 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
359 for message_line in message:
360 problems.append(' %s' % message_line)
362 result = []
363 if (warnings):
364 result.append(output_api.PresubmitPromptWarning(
365 'Banned functions were used.\n' + '\n'.join(warnings)))
366 if (errors):
367 result.append(output_api.PresubmitError(
368 'Banned functions were used.\n' + '\n'.join(errors)))
369 return result
372 def _CheckNoPragmaOnce(input_api, output_api):
373 """Make sure that banned functions are not used."""
374 files = []
375 pattern = input_api.re.compile(r'^#pragma\s+once',
376 input_api.re.MULTILINE)
377 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
378 if not f.LocalPath().endswith('.h'):
379 continue
380 contents = input_api.ReadFile(f)
381 if pattern.search(contents):
382 files.append(f)
384 if files:
385 return [output_api.PresubmitError(
386 'Do not use #pragma once in header files.\n'
387 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
388 files)]
389 return []
392 def _CheckNoTrinaryTrueFalse(input_api, output_api):
393 """Checks to make sure we don't introduce use of foo ? true : false."""
394 problems = []
395 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
396 for f in input_api.AffectedFiles():
397 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
398 continue
400 for line_num, line in f.ChangedContents():
401 if pattern.match(line):
402 problems.append(' %s:%d' % (f.LocalPath(), line_num))
404 if not problems:
405 return []
406 return [output_api.PresubmitPromptWarning(
407 'Please consider avoiding the "? true : false" pattern if possible.\n' +
408 '\n'.join(problems))]
411 def _CheckUnwantedDependencies(input_api, output_api):
412 """Runs checkdeps on #include statements added in this
413 change. Breaking - rules is an error, breaking ! rules is a
414 warning.
416 # We need to wait until we have an input_api object and use this
417 # roundabout construct to import checkdeps because this file is
418 # eval-ed and thus doesn't have __file__.
419 original_sys_path = sys.path
420 try:
421 sys.path = sys.path + [input_api.os_path.join(
422 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
423 import checkdeps
424 from cpp_checker import CppChecker
425 from rules import Rule
426 finally:
427 # Restore sys.path to what it was before.
428 sys.path = original_sys_path
430 added_includes = []
431 for f in input_api.AffectedFiles():
432 if not CppChecker.IsCppFile(f.LocalPath()):
433 continue
435 changed_lines = [line for line_num, line in f.ChangedContents()]
436 added_includes.append([f.LocalPath(), changed_lines])
438 deps_checker = checkdeps.DepsChecker()
440 error_descriptions = []
441 warning_descriptions = []
442 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
443 added_includes):
444 description_with_path = '%s\n %s' % (path, rule_description)
445 if rule_type == Rule.DISALLOW:
446 error_descriptions.append(description_with_path)
447 else:
448 warning_descriptions.append(description_with_path)
450 results = []
451 if error_descriptions:
452 results.append(output_api.PresubmitError(
453 'You added one or more #includes that violate checkdeps rules.',
454 error_descriptions))
455 if warning_descriptions:
456 if not input_api.is_committing:
457 warning_factory = output_api.PresubmitPromptWarning
458 else:
459 # We don't want to block use of the CQ when there is a warning
460 # of this kind, so we only show a message when committing.
461 warning_factory = output_api.PresubmitNotifyResult
462 results.append(warning_factory(
463 'You added one or more #includes of files that are temporarily\n'
464 'allowed but being removed. Can you avoid introducing the\n'
465 '#include? See relevant DEPS file(s) for details and contacts.',
466 warning_descriptions))
467 return results
470 def _CheckFilePermissions(input_api, output_api):
471 """Check that all files have their permissions properly set."""
472 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
473 input_api.change.RepositoryRoot()]
474 for f in input_api.AffectedFiles():
475 args += ['--file', f.LocalPath()]
476 errors = []
477 (errors, stderrdata) = subprocess.Popen(args).communicate()
479 results = []
480 if errors:
481 results.append(output_api.PresubmitError('checkperms.py failed.',
482 errors))
483 return results
486 def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
487 """Makes sure we don't include ui/aura/window_property.h
488 in header files.
490 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
491 errors = []
492 for f in input_api.AffectedFiles():
493 if not f.LocalPath().endswith('.h'):
494 continue
495 for line_num, line in f.ChangedContents():
496 if pattern.match(line):
497 errors.append(' %s:%d' % (f.LocalPath(), line_num))
499 results = []
500 if errors:
501 results.append(output_api.PresubmitError(
502 'Header files should not include ui/aura/window_property.h', errors))
503 return results
506 def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
507 """Checks that the lines in scope occur in the right order.
509 1. C system files in alphabetical order
510 2. C++ system files in alphabetical order
511 3. Project's .h files
514 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
515 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
516 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
518 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
520 state = C_SYSTEM_INCLUDES
522 previous_line = ''
523 previous_line_num = 0
524 problem_linenums = []
525 for line_num, line in scope:
526 if c_system_include_pattern.match(line):
527 if state != C_SYSTEM_INCLUDES:
528 problem_linenums.append((line_num, previous_line_num))
529 elif previous_line and previous_line > line:
530 problem_linenums.append((line_num, previous_line_num))
531 elif cpp_system_include_pattern.match(line):
532 if state == C_SYSTEM_INCLUDES:
533 state = CPP_SYSTEM_INCLUDES
534 elif state == CUSTOM_INCLUDES:
535 problem_linenums.append((line_num, previous_line_num))
536 elif previous_line and previous_line > line:
537 problem_linenums.append((line_num, previous_line_num))
538 elif custom_include_pattern.match(line):
539 if state != CUSTOM_INCLUDES:
540 state = CUSTOM_INCLUDES
541 elif previous_line and previous_line > line:
542 problem_linenums.append((line_num, previous_line_num))
543 else:
544 problem_linenums.append(line_num)
545 previous_line = line
546 previous_line_num = line_num
548 warnings = []
549 for (line_num, previous_line_num) in problem_linenums:
550 if line_num in changed_linenums or previous_line_num in changed_linenums:
551 warnings.append(' %s:%d' % (file_path, line_num))
552 return warnings
555 def _CheckIncludeOrderInFile(input_api, f, is_source, changed_linenums):
556 """Checks the #include order for the given file f."""
558 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
559 # Exclude #include <.../...> includes from the check; e.g., <sys/...> includes
560 # often need to appear in a specific order.
561 excluded_include_pattern = input_api.re.compile(r'\s*#include \<.*/.*')
562 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
563 if_pattern = input_api.re.compile(r'\s*#\s*(if|elif|else|endif).*')
565 contents = f.NewContents()
566 warnings = []
567 line_num = 0
569 # Handle the special first include for source files. If the header file is
570 # some/path/file.h, the corresponding source file can be some/path/file.cc,
571 # some/other/path/file.cc, some/path/file_platform.cc etc. It's also possible
572 # that no special first include exists.
573 if is_source:
574 for line in contents:
575 line_num += 1
576 if system_include_pattern.match(line):
577 # No special first include -> process the line again along with normal
578 # includes.
579 line_num -= 1
580 break
581 match = custom_include_pattern.match(line)
582 if match:
583 match_dict = match.groupdict()
584 header_basename = input_api.os_path.basename(
585 match_dict['FILE']).replace('.h', '')
586 if header_basename not in input_api.os_path.basename(f.LocalPath()):
587 # No special first include -> process the line again along with normal
588 # includes.
589 line_num -= 1
590 break
592 # Split into scopes: Each region between #if and #endif is its own scope.
593 scopes = []
594 current_scope = []
595 for line in contents[line_num:]:
596 line_num += 1
597 if if_pattern.match(line):
598 scopes.append(current_scope)
599 current_scope = []
600 elif ((system_include_pattern.match(line) or
601 custom_include_pattern.match(line)) and
602 not excluded_include_pattern.match(line)):
603 current_scope.append((line_num, line))
604 scopes.append(current_scope)
606 for scope in scopes:
607 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
608 changed_linenums))
609 return warnings
612 def _CheckIncludeOrder(input_api, output_api):
613 """Checks that the #include order is correct.
615 1. The corresponding header for source files.
616 2. C system files in alphabetical order
617 3. C++ system files in alphabetical order
618 4. Project's .h files in alphabetical order
620 Each region between #if and #endif follows these rules separately.
623 warnings = []
624 for f in input_api.AffectedFiles():
625 changed_linenums = set([line_num for line_num, _ in f.ChangedContents()])
626 if f.LocalPath().endswith('.cc'):
627 warnings.extend(_CheckIncludeOrderInFile(input_api, f, True,
628 changed_linenums))
629 elif f.LocalPath().endswith('.h'):
630 warnings.extend(_CheckIncludeOrderInFile(input_api, f, False,
631 changed_linenums))
633 results = []
634 if warnings:
635 results.append(output_api.PresubmitPromptWarning(_INCLUDE_ORDER_WARNING,
636 warnings))
637 return results
640 def _CheckForVersionControlConflictsInFile(input_api, f):
641 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
642 errors = []
643 for line_num, line in f.ChangedContents():
644 if pattern.match(line):
645 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
646 return errors
649 def _CheckForVersionControlConflicts(input_api, output_api):
650 """Usually this is not intentional and will cause a compile failure."""
651 errors = []
652 for f in input_api.AffectedFiles():
653 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
655 results = []
656 if errors:
657 results.append(output_api.PresubmitError(
658 'Version control conflict markers found, please resolve.', errors))
659 return results
662 def _CommonChecks(input_api, output_api):
663 """Checks common to both upload and commit."""
664 results = []
665 results.extend(input_api.canned_checks.PanProjectChecks(
666 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
667 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
668 results.extend(
669 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
670 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
671 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
672 results.extend(_CheckNoNewWStrings(input_api, output_api))
673 results.extend(_CheckNoDEPSGIT(input_api, output_api))
674 results.extend(_CheckNoBannedFunctions(input_api, output_api))
675 results.extend(_CheckNoPragmaOnce(input_api, output_api))
676 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
677 results.extend(_CheckUnwantedDependencies(input_api, output_api))
678 results.extend(_CheckFilePermissions(input_api, output_api))
679 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
680 results.extend(_CheckIncludeOrder(input_api, output_api))
681 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
683 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
684 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
685 input_api, output_api,
686 input_api.PresubmitLocalPath(),
687 whitelist=[r'.+_test\.py$']))
688 return results
691 def _CheckSubversionConfig(input_api, output_api):
692 """Verifies the subversion config file is correctly setup.
694 Checks that autoprops are enabled, returns an error otherwise.
696 join = input_api.os_path.join
697 if input_api.platform == 'win32':
698 appdata = input_api.environ.get('APPDATA', '')
699 if not appdata:
700 return [output_api.PresubmitError('%APPDATA% is not configured.')]
701 path = join(appdata, 'Subversion', 'config')
702 else:
703 home = input_api.environ.get('HOME', '')
704 if not home:
705 return [output_api.PresubmitError('$HOME is not configured.')]
706 path = join(home, '.subversion', 'config')
708 error_msg = (
709 'Please look at http://dev.chromium.org/developers/coding-style to\n'
710 'configure your subversion configuration file. This enables automatic\n'
711 'properties to simplify the project maintenance.\n'
712 'Pro-tip: just download and install\n'
713 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
715 try:
716 lines = open(path, 'r').read().splitlines()
717 # Make sure auto-props is enabled and check for 2 Chromium standard
718 # auto-prop.
719 if (not '*.cc = svn:eol-style=LF' in lines or
720 not '*.pdf = svn:mime-type=application/pdf' in lines or
721 not 'enable-auto-props = yes' in lines):
722 return [
723 output_api.PresubmitNotifyResult(
724 'It looks like you have not configured your subversion config '
725 'file or it is not up-to-date.\n' + error_msg)
727 except (OSError, IOError):
728 return [
729 output_api.PresubmitNotifyResult(
730 'Can\'t find your subversion config file.\n' + error_msg)
732 return []
735 def _CheckAuthorizedAuthor(input_api, output_api):
736 """For non-googler/chromites committers, verify the author's email address is
737 in AUTHORS.
739 # TODO(maruel): Add it to input_api?
740 import fnmatch
742 author = input_api.change.author_email
743 if not author:
744 input_api.logging.info('No author, skipping AUTHOR check')
745 return []
746 authors_path = input_api.os_path.join(
747 input_api.PresubmitLocalPath(), 'AUTHORS')
748 valid_authors = (
749 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
750 for line in open(authors_path))
751 valid_authors = [item.group(1).lower() for item in valid_authors if item]
752 if input_api.verbose:
753 print 'Valid authors are %s' % ', '.join(valid_authors)
754 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
755 return [output_api.PresubmitPromptWarning(
756 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
757 '\n'
758 'http://www.chromium.org/developers/contributing-code and read the '
759 '"Legal" section\n'
760 'If you are a chromite, verify the contributor signed the CLA.') %
761 author)]
762 return []
765 def CheckChangeOnUpload(input_api, output_api):
766 results = []
767 results.extend(_CommonChecks(input_api, output_api))
768 return results
771 def CheckChangeOnCommit(input_api, output_api):
772 results = []
773 results.extend(_CommonChecks(input_api, output_api))
774 # TODO(thestig) temporarily disabled, doesn't work in third_party/
775 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
776 # input_api, output_api, sources))
777 # Make sure the tree is 'open'.
778 results.extend(input_api.canned_checks.CheckTreeIsOpen(
779 input_api,
780 output_api,
781 json_url='http://chromium-status.appspot.com/current?format=json'))
782 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
783 output_api, 'http://codereview.chromium.org',
784 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
785 'tryserver@chromium.org'))
787 results.extend(input_api.canned_checks.CheckChangeHasBugField(
788 input_api, output_api))
789 results.extend(input_api.canned_checks.CheckChangeHasDescription(
790 input_api, output_api))
791 results.extend(_CheckSubversionConfig(input_api, output_api))
792 return results
795 def GetPreferredTrySlaves(project, change):
796 files = change.LocalPaths()
798 if not files:
799 return []
801 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
802 return ['mac_rel', 'mac_asan']
803 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
804 return ['win_rel']
805 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
806 return ['android_dbg', 'android_clang_dbg']
807 if all(re.search('^native_client_sdk', f) for f in files):
808 return ['linux_nacl_sdk', 'win_nacl_sdk', 'mac_nacl_sdk']
809 if all(re.search('[/_]ios[/_.]', f) for f in files):
810 return ['ios_rel_device', 'ios_dbg_simulator']
812 trybots = [
813 'android_clang_dbg',
814 'android_dbg',
815 'ios_dbg_simulator',
816 'ios_rel_device',
817 'linux_asan',
818 'linux_aura',
819 'linux_chromeos',
820 'linux_clang:compile',
821 'linux_rel',
822 'mac_asan',
823 'mac_rel',
824 'win_aura',
825 'win_rel',
828 # Match things like path/aura/file.cc and path/file_aura.cc.
829 # Same for chromeos.
830 if any(re.search('[/_](aura|chromeos)', f) for f in files):
831 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan']
833 return trybots