telemetry: Wait for acknowledgement that tracing has started
[chromium-blink-merge.git] / PRESUBMIT.py
blobbd5283e4414d53f3bed599af5f5e71616d8bb4f6
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 random
13 import re
14 import subprocess
15 import sys
18 _EXCLUDED_PATHS = (
19 r"^breakpad[\\\/].*",
20 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py",
21 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py",
22 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk",
23 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*",
24 r"^skia[\\\/].*",
25 r"^v8[\\\/].*",
26 r".*MakeFile$",
27 r".+_autogen\.h$",
28 r".+[\\\/]pnacl_shim\.c$",
29 r"^gpu[\\\/]config[\\\/].*_list_json\.cc$",
32 # TestRunner library is temporarily excluded from pan-project checks until
33 # it's transitioned to chromium coding style.
34 _TESTRUNNER_PATHS = (
35 r"^content[\\\/]shell[\\\/]renderer[\\\/]test_runner[\\\/].*",
36 r"^content[\\\/]shell[\\\/]common[\\\/]test_runner[\\\/].*",
39 # Fragment of a regular expression that matches C++ and Objective-C++
40 # implementation files.
41 _IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
43 # Regular expression that matches code only used for test binaries
44 # (best effort).
45 _TEST_CODE_EXCLUDED_PATHS = (
46 r'.*[/\\](fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
47 r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
48 r'.+_(api|browser|perf|pixel|unit|ui)?test(_[a-z]+)?%s' %
49 _IMPLEMENTATION_EXTENSIONS,
50 r'.+profile_sync_service_harness%s' % _IMPLEMENTATION_EXTENSIONS,
51 r'.*[/\\](test|tool(s)?)[/\\].*',
52 # content_shell is used for running layout tests.
53 r'content[/\\]shell[/\\].*',
54 # At request of folks maintaining this folder.
55 r'chrome[/\\]browser[/\\]automation[/\\].*',
56 # Non-production example code.
57 r'mojo[/\\]examples[/\\].*',
60 _TEST_ONLY_WARNING = (
61 'You might be calling functions intended only for testing from\n'
62 'production code. It is OK to ignore this warning if you know what\n'
63 'you are doing, as the heuristics used to detect the situation are\n'
64 'not perfect. The commit queue will not block on this warning.\n'
65 'Email joi@chromium.org if you have questions.')
68 _INCLUDE_ORDER_WARNING = (
69 'Your #include order seems to be broken. Send mail to\n'
70 'marja@chromium.org if this is not the case.')
73 _BANNED_OBJC_FUNCTIONS = (
75 'addTrackingRect:',
77 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
78 'prohibited. Please use CrTrackingArea instead.',
79 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
81 False,
84 'NSTrackingArea',
86 'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
87 'instead.',
88 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
90 False,
93 'convertPointFromBase:',
95 'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
96 'Please use |convertPoint:(point) fromView:nil| instead.',
97 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
99 True,
102 'convertPointToBase:',
104 'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
105 'Please use |convertPoint:(point) toView:nil| instead.',
106 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
108 True,
111 'convertRectFromBase:',
113 'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
114 'Please use |convertRect:(point) fromView:nil| instead.',
115 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
117 True,
120 'convertRectToBase:',
122 'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
123 'Please use |convertRect:(point) toView:nil| instead.',
124 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
126 True,
129 'convertSizeFromBase:',
131 'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
132 'Please use |convertSize:(point) fromView:nil| instead.',
133 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
135 True,
138 'convertSizeToBase:',
140 'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
141 'Please use |convertSize:(point) toView:nil| instead.',
142 'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
144 True,
149 _BANNED_CPP_FUNCTIONS = (
150 # Make sure that gtest's FRIEND_TEST() macro is not used; the
151 # FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
152 # used instead since that allows for FLAKY_ and DISABLED_ prefixes.
154 'FRIEND_TEST(',
156 'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
157 'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
159 False,
163 'ScopedAllowIO',
165 'New code should not use ScopedAllowIO. Post a task to the blocking',
166 'pool or the FILE thread instead.',
168 True,
170 r"^components[\\\/]breakpad[\\\/]app[\\\/]breakpad_mac\.mm$",
171 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_browser_main\.cc$",
172 r"^content[\\\/]shell[\\\/]browser[\\\/]shell_message_filter\.cc$",
173 r"^net[\\\/]disk_cache[\\\/]cache_util\.cc$",
177 'SkRefPtr',
179 'The use of SkRefPtr is prohibited. ',
180 'Please use skia::RefPtr instead.'
182 True,
186 'SkAutoRef',
188 'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
189 'Please use skia::RefPtr instead.'
191 True,
195 'SkAutoTUnref',
197 'The use of SkAutoTUnref is dangerous because it implicitly ',
198 'converts to a raw pointer. Please use skia::RefPtr instead.'
200 True,
204 'SkAutoUnref',
206 'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
207 'because it implicitly converts to a raw pointer. ',
208 'Please use skia::RefPtr instead.'
210 True,
214 r'/HANDLE_EINTR\(.*close',
216 'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
217 'descriptor will be closed, and it is incorrect to retry the close.',
218 'Either call close directly and ignore its return value, or wrap close',
219 'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
221 True,
225 r'/IGNORE_EINTR\((?!.*close)',
227 'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
228 'calls, use HANDLE_EINTR. See http://crbug.com/269623',
230 True,
232 # Files that #define IGNORE_EINTR.
233 r'^base[\\\/]posix[\\\/]eintr_wrapper\.h$',
234 r'^ppapi[\\\/]tests[\\\/]test_broker\.cc$',
240 _VALID_OS_MACROS = (
241 # Please keep sorted.
242 'OS_ANDROID',
243 'OS_BSD',
244 'OS_CAT', # For testing.
245 'OS_CHROMEOS',
246 'OS_FREEBSD',
247 'OS_IOS',
248 'OS_LINUX',
249 'OS_MACOSX',
250 'OS_NACL',
251 'OS_OPENBSD',
252 'OS_POSIX',
253 'OS_SOLARIS',
254 'OS_WIN',
258 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
259 """Attempts to prevent use of functions intended only for testing in
260 non-testing code. For now this is just a best-effort implementation
261 that ignores header files and may have some false positives. A
262 better implementation would probably need a proper C++ parser.
264 # We only scan .cc files and the like, as the declaration of
265 # for-testing functions in header files are hard to distinguish from
266 # calls to such functions without a proper C++ parser.
267 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
269 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
270 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
271 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
272 exclusion_pattern = input_api.re.compile(
273 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
274 base_function_pattern, base_function_pattern))
276 def FilterFile(affected_file):
277 black_list = (_EXCLUDED_PATHS +
278 _TEST_CODE_EXCLUDED_PATHS +
279 input_api.DEFAULT_BLACK_LIST)
280 return input_api.FilterSourceFile(
281 affected_file,
282 white_list=(file_inclusion_pattern, ),
283 black_list=black_list)
285 problems = []
286 for f in input_api.AffectedSourceFiles(FilterFile):
287 local_path = f.LocalPath()
288 for line_number, line in f.ChangedContents():
289 if (inclusion_pattern.search(line) and
290 not comment_pattern.search(line) and
291 not exclusion_pattern.search(line)):
292 problems.append(
293 '%s:%d\n %s' % (local_path, line_number, line.strip()))
295 if problems:
296 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
297 else:
298 return []
301 def _CheckNoIOStreamInHeaders(input_api, output_api):
302 """Checks to make sure no .h files include <iostream>."""
303 files = []
304 pattern = input_api.re.compile(r'^#include\s*<iostream>',
305 input_api.re.MULTILINE)
306 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
307 if not f.LocalPath().endswith('.h'):
308 continue
309 contents = input_api.ReadFile(f)
310 if pattern.search(contents):
311 files.append(f)
313 if len(files):
314 return [ output_api.PresubmitError(
315 'Do not #include <iostream> in header files, since it inserts static '
316 'initialization into every file including the header. Instead, '
317 '#include <ostream>. See http://crbug.com/94794',
318 files) ]
319 return []
322 def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
323 """Checks to make sure no source files use UNIT_TEST"""
324 problems = []
325 for f in input_api.AffectedFiles():
326 if (not f.LocalPath().endswith(('.cc', '.mm'))):
327 continue
329 for line_num, line in f.ChangedContents():
330 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'):
331 problems.append(' %s:%d' % (f.LocalPath(), line_num))
333 if not problems:
334 return []
335 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' +
336 '\n'.join(problems))]
339 def _CheckNoNewWStrings(input_api, output_api):
340 """Checks to make sure we don't introduce use of wstrings."""
341 problems = []
342 for f in input_api.AffectedFiles():
343 if (not f.LocalPath().endswith(('.cc', '.h')) or
344 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h'))):
345 continue
347 allowWString = False
348 for line_num, line in f.ChangedContents():
349 if 'presubmit: allow wstring' in line:
350 allowWString = True
351 elif not allowWString and 'wstring' in line:
352 problems.append(' %s:%d' % (f.LocalPath(), line_num))
353 allowWString = False
354 else:
355 allowWString = False
357 if not problems:
358 return []
359 return [output_api.PresubmitPromptWarning('New code should not use wstrings.'
360 ' If you are calling a cross-platform API that accepts a wstring, '
361 'fix the API.\n' +
362 '\n'.join(problems))]
365 def _CheckNoDEPSGIT(input_api, output_api):
366 """Make sure .DEPS.git is never modified manually."""
367 if any(f.LocalPath().endswith('.DEPS.git') for f in
368 input_api.AffectedFiles()):
369 return [output_api.PresubmitError(
370 'Never commit changes to .DEPS.git. This file is maintained by an\n'
371 'automated system based on what\'s in DEPS and your changes will be\n'
372 'overwritten.\n'
373 'See http://code.google.com/p/chromium/wiki/UsingNewGit#Rolling_DEPS\n'
374 'for more information')]
375 return []
378 def _CheckNoBannedFunctions(input_api, output_api):
379 """Make sure that banned functions are not used."""
380 warnings = []
381 errors = []
383 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
384 for f in input_api.AffectedFiles(file_filter=file_filter):
385 for line_num, line in f.ChangedContents():
386 for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
387 if func_name in line:
388 problems = warnings;
389 if error:
390 problems = errors;
391 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
392 for message_line in message:
393 problems.append(' %s' % message_line)
395 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
396 for f in input_api.AffectedFiles(file_filter=file_filter):
397 for line_num, line in f.ChangedContents():
398 for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
399 def IsBlacklisted(affected_file, blacklist):
400 local_path = affected_file.LocalPath()
401 for item in blacklist:
402 if input_api.re.match(item, local_path):
403 return True
404 return False
405 if IsBlacklisted(f, excluded_paths):
406 continue
407 matched = False
408 if func_name[0:1] == '/':
409 regex = func_name[1:]
410 if input_api.re.search(regex, line):
411 matched = True
412 elif func_name in line:
413 matched = True
414 if matched:
415 problems = warnings;
416 if error:
417 problems = errors;
418 problems.append(' %s:%d:' % (f.LocalPath(), line_num))
419 for message_line in message:
420 problems.append(' %s' % message_line)
422 result = []
423 if (warnings):
424 result.append(output_api.PresubmitPromptWarning(
425 'Banned functions were used.\n' + '\n'.join(warnings)))
426 if (errors):
427 result.append(output_api.PresubmitError(
428 'Banned functions were used.\n' + '\n'.join(errors)))
429 return result
432 def _CheckNoPragmaOnce(input_api, output_api):
433 """Make sure that banned functions are not used."""
434 files = []
435 pattern = input_api.re.compile(r'^#pragma\s+once',
436 input_api.re.MULTILINE)
437 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
438 if not f.LocalPath().endswith('.h'):
439 continue
440 contents = input_api.ReadFile(f)
441 if pattern.search(contents):
442 files.append(f)
444 if files:
445 return [output_api.PresubmitError(
446 'Do not use #pragma once in header files.\n'
447 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
448 files)]
449 return []
452 def _CheckNoTrinaryTrueFalse(input_api, output_api):
453 """Checks to make sure we don't introduce use of foo ? true : false."""
454 problems = []
455 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
456 for f in input_api.AffectedFiles():
457 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
458 continue
460 for line_num, line in f.ChangedContents():
461 if pattern.match(line):
462 problems.append(' %s:%d' % (f.LocalPath(), line_num))
464 if not problems:
465 return []
466 return [output_api.PresubmitPromptWarning(
467 'Please consider avoiding the "? true : false" pattern if possible.\n' +
468 '\n'.join(problems))]
471 def _CheckUnwantedDependencies(input_api, output_api):
472 """Runs checkdeps on #include statements added in this
473 change. Breaking - rules is an error, breaking ! rules is a
474 warning.
476 # We need to wait until we have an input_api object and use this
477 # roundabout construct to import checkdeps because this file is
478 # eval-ed and thus doesn't have __file__.
479 original_sys_path = sys.path
480 try:
481 sys.path = sys.path + [input_api.os_path.join(
482 input_api.PresubmitLocalPath(), 'tools', 'checkdeps')]
483 import checkdeps
484 from cpp_checker import CppChecker
485 from rules import Rule
486 finally:
487 # Restore sys.path to what it was before.
488 sys.path = original_sys_path
490 added_includes = []
491 for f in input_api.AffectedFiles():
492 if not CppChecker.IsCppFile(f.LocalPath()):
493 continue
495 changed_lines = [line for line_num, line in f.ChangedContents()]
496 added_includes.append([f.LocalPath(), changed_lines])
498 deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
500 error_descriptions = []
501 warning_descriptions = []
502 for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
503 added_includes):
504 description_with_path = '%s\n %s' % (path, rule_description)
505 if rule_type == Rule.DISALLOW:
506 error_descriptions.append(description_with_path)
507 else:
508 warning_descriptions.append(description_with_path)
510 results = []
511 if error_descriptions:
512 results.append(output_api.PresubmitError(
513 'You added one or more #includes that violate checkdeps rules.',
514 error_descriptions))
515 if warning_descriptions:
516 results.append(output_api.PresubmitPromptOrNotify(
517 'You added one or more #includes of files that are temporarily\n'
518 'allowed but being removed. Can you avoid introducing the\n'
519 '#include? See relevant DEPS file(s) for details and contacts.',
520 warning_descriptions))
521 return results
524 def _CheckFilePermissions(input_api, output_api):
525 """Check that all files have their permissions properly set."""
526 args = [sys.executable, 'tools/checkperms/checkperms.py', '--root',
527 input_api.change.RepositoryRoot()]
528 for f in input_api.AffectedFiles():
529 args += ['--file', f.LocalPath()]
530 errors = []
531 (errors, stderrdata) = subprocess.Popen(args).communicate()
533 results = []
534 if errors:
535 results.append(output_api.PresubmitError('checkperms.py failed.',
536 errors))
537 return results
540 def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
541 """Makes sure we don't include ui/aura/window_property.h
542 in header files.
544 pattern = input_api.re.compile(r'^#include\s*"ui/aura/window_property.h"')
545 errors = []
546 for f in input_api.AffectedFiles():
547 if not f.LocalPath().endswith('.h'):
548 continue
549 for line_num, line in f.ChangedContents():
550 if pattern.match(line):
551 errors.append(' %s:%d' % (f.LocalPath(), line_num))
553 results = []
554 if errors:
555 results.append(output_api.PresubmitError(
556 'Header files should not include ui/aura/window_property.h', errors))
557 return results
560 def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums):
561 """Checks that the lines in scope occur in the right order.
563 1. C system files in alphabetical order
564 2. C++ system files in alphabetical order
565 3. Project's .h files
568 c_system_include_pattern = input_api.re.compile(r'\s*#include <.*\.h>')
569 cpp_system_include_pattern = input_api.re.compile(r'\s*#include <.*>')
570 custom_include_pattern = input_api.re.compile(r'\s*#include ".*')
572 C_SYSTEM_INCLUDES, CPP_SYSTEM_INCLUDES, CUSTOM_INCLUDES = range(3)
574 state = C_SYSTEM_INCLUDES
576 previous_line = ''
577 previous_line_num = 0
578 problem_linenums = []
579 for line_num, line in scope:
580 if c_system_include_pattern.match(line):
581 if state != C_SYSTEM_INCLUDES:
582 problem_linenums.append((line_num, previous_line_num))
583 elif previous_line and previous_line > line:
584 problem_linenums.append((line_num, previous_line_num))
585 elif cpp_system_include_pattern.match(line):
586 if state == C_SYSTEM_INCLUDES:
587 state = CPP_SYSTEM_INCLUDES
588 elif state == CUSTOM_INCLUDES:
589 problem_linenums.append((line_num, previous_line_num))
590 elif previous_line and previous_line > line:
591 problem_linenums.append((line_num, previous_line_num))
592 elif custom_include_pattern.match(line):
593 if state != CUSTOM_INCLUDES:
594 state = CUSTOM_INCLUDES
595 elif previous_line and previous_line > line:
596 problem_linenums.append((line_num, previous_line_num))
597 else:
598 problem_linenums.append(line_num)
599 previous_line = line
600 previous_line_num = line_num
602 warnings = []
603 for (line_num, previous_line_num) in problem_linenums:
604 if line_num in changed_linenums or previous_line_num in changed_linenums:
605 warnings.append(' %s:%d' % (file_path, line_num))
606 return warnings
609 def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
610 """Checks the #include order for the given file f."""
612 system_include_pattern = input_api.re.compile(r'\s*#include \<.*')
613 # Exclude the following includes from the check:
614 # 1) #include <.../...>, e.g., <sys/...> includes often need to appear in a
615 # specific order.
616 # 2) <atlbase.h>, "build/build_config.h"
617 excluded_include_pattern = input_api.re.compile(
618 r'\s*#include (\<.*/.*|\<atlbase\.h\>|"build/build_config.h")')
619 custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
620 # Match the final or penultimate token if it is xxxtest so we can ignore it
621 # when considering the special first include.
622 test_file_tag_pattern = input_api.re.compile(
623 r'_[a-z]+test(?=(_[a-zA-Z0-9]+)?\.)')
624 if_pattern = input_api.re.compile(
625 r'\s*#\s*(if|elif|else|endif|define|undef).*')
626 # Some files need specialized order of includes; exclude such files from this
627 # check.
628 uncheckable_includes_pattern = input_api.re.compile(
629 r'\s*#include '
630 '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
632 contents = f.NewContents()
633 warnings = []
634 line_num = 0
636 # Handle the special first include. If the first include file is
637 # some/path/file.h, the corresponding including file can be some/path/file.cc,
638 # some/other/path/file.cc, some/path/file_platform.cc, some/path/file-suffix.h
639 # etc. It's also possible that no special first include exists.
640 # If the included file is some/path/file_platform.h the including file could
641 # also be some/path/file_xxxtest_platform.h.
642 including_file_base_name = test_file_tag_pattern.sub(
643 '', input_api.os_path.basename(f.LocalPath()))
645 for line in contents:
646 line_num += 1
647 if system_include_pattern.match(line):
648 # No special first include -> process the line again along with normal
649 # includes.
650 line_num -= 1
651 break
652 match = custom_include_pattern.match(line)
653 if match:
654 match_dict = match.groupdict()
655 header_basename = test_file_tag_pattern.sub(
656 '', input_api.os_path.basename(match_dict['FILE'])).replace('.h', '')
658 if header_basename not in including_file_base_name:
659 # No special first include -> process the line again along with normal
660 # includes.
661 line_num -= 1
662 break
664 # Split into scopes: Each region between #if and #endif is its own scope.
665 scopes = []
666 current_scope = []
667 for line in contents[line_num:]:
668 line_num += 1
669 if uncheckable_includes_pattern.match(line):
670 continue
671 if if_pattern.match(line):
672 scopes.append(current_scope)
673 current_scope = []
674 elif ((system_include_pattern.match(line) or
675 custom_include_pattern.match(line)) and
676 not excluded_include_pattern.match(line)):
677 current_scope.append((line_num, line))
678 scopes.append(current_scope)
680 for scope in scopes:
681 warnings.extend(_CheckIncludeOrderForScope(scope, input_api, f.LocalPath(),
682 changed_linenums))
683 return warnings
686 def _CheckIncludeOrder(input_api, output_api):
687 """Checks that the #include order is correct.
689 1. The corresponding header for source files.
690 2. C system files in alphabetical order
691 3. C++ system files in alphabetical order
692 4. Project's .h files in alphabetical order
694 Each region separated by #if, #elif, #else, #endif, #define and #undef follows
695 these rules separately.
698 warnings = []
699 for f in input_api.AffectedFiles():
700 if f.LocalPath().endswith(('.cc', '.h')):
701 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
702 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
704 results = []
705 if warnings:
706 results.append(output_api.PresubmitPromptOrNotify(_INCLUDE_ORDER_WARNING,
707 warnings))
708 return results
711 def _CheckForVersionControlConflictsInFile(input_api, f):
712 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
713 errors = []
714 for line_num, line in f.ChangedContents():
715 if pattern.match(line):
716 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
717 return errors
720 def _CheckForVersionControlConflicts(input_api, output_api):
721 """Usually this is not intentional and will cause a compile failure."""
722 errors = []
723 for f in input_api.AffectedFiles():
724 errors.extend(_CheckForVersionControlConflictsInFile(input_api, f))
726 results = []
727 if errors:
728 results.append(output_api.PresubmitError(
729 'Version control conflict markers found, please resolve.', errors))
730 return results
733 def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api):
734 def FilterFile(affected_file):
735 """Filter function for use with input_api.AffectedSourceFiles,
736 below. This filters out everything except non-test files from
737 top-level directories that generally speaking should not hard-code
738 service URLs (e.g. src/android_webview/, src/content/ and others).
740 return input_api.FilterSourceFile(
741 affected_file,
742 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
743 black_list=(_EXCLUDED_PATHS +
744 _TEST_CODE_EXCLUDED_PATHS +
745 input_api.DEFAULT_BLACK_LIST))
747 base_pattern = '"[^"]*google\.com[^"]*"'
748 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
749 pattern = input_api.re.compile(base_pattern)
750 problems = [] # items are (filename, line_number, line)
751 for f in input_api.AffectedSourceFiles(FilterFile):
752 for line_num, line in f.ChangedContents():
753 if not comment_pattern.search(line) and pattern.search(line):
754 problems.append((f.LocalPath(), line_num, line))
756 if problems:
757 return [output_api.PresubmitPromptOrNotify(
758 'Most layers below src/chrome/ should not hardcode service URLs.\n'
759 'Are you sure this is correct? (Contact: joi@chromium.org)',
760 [' %s:%d: %s' % (
761 problem[0], problem[1], problem[2]) for problem in problems])]
762 else:
763 return []
766 def _CheckNoAbbreviationInPngFileName(input_api, output_api):
767 """Makes sure there are no abbreviations in the name of PNG files.
769 pattern = input_api.re.compile(r'.*_[a-z]_.*\.png$|.*_[a-z]\.png$')
770 errors = []
771 for f in input_api.AffectedFiles(include_deletes=False):
772 if pattern.match(f.LocalPath()):
773 errors.append(' %s' % f.LocalPath())
775 results = []
776 if errors:
777 results.append(output_api.PresubmitError(
778 'The name of PNG files should not have abbreviations. \n'
779 'Use _hover.png, _center.png, instead of _h.png, _c.png.\n'
780 'Contact oshima@chromium.org if you have questions.', errors))
781 return results
784 def _FilesToCheckForIncomingDeps(re, changed_lines):
785 """Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
786 a set of DEPS entries that we should look up.
788 For a directory (rather than a specific filename) we fake a path to
789 a specific filename by adding /DEPS. This is chosen as a file that
790 will seldom or never be subject to per-file include_rules.
792 # We ignore deps entries on auto-generated directories.
793 AUTO_GENERATED_DIRS = ['grit', 'jni']
795 # This pattern grabs the path without basename in the first
796 # parentheses, and the basename (if present) in the second. It
797 # relies on the simple heuristic that if there is a basename it will
798 # be a header file ending in ".h".
799 pattern = re.compile(
800 r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
801 results = set()
802 for changed_line in changed_lines:
803 m = pattern.match(changed_line)
804 if m:
805 path = m.group(1)
806 if path.split('/')[0] not in AUTO_GENERATED_DIRS:
807 if m.group(2):
808 results.add('%s%s' % (path, m.group(2)))
809 else:
810 results.add('%s/DEPS' % path)
811 return results
814 def _CheckAddedDepsHaveTargetApprovals(input_api, output_api):
815 """When a dependency prefixed with + is added to a DEPS file, we
816 want to make sure that the change is reviewed by an OWNER of the
817 target file or directory, to avoid layering violations from being
818 introduced. This check verifies that this happens.
820 changed_lines = set()
821 for f in input_api.AffectedFiles():
822 filename = input_api.os_path.basename(f.LocalPath())
823 if filename == 'DEPS':
824 changed_lines |= set(line.strip()
825 for line_num, line
826 in f.ChangedContents())
827 if not changed_lines:
828 return []
830 virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
831 changed_lines)
832 if not virtual_depended_on_files:
833 return []
835 if input_api.is_committing:
836 if input_api.tbr:
837 return [output_api.PresubmitNotifyResult(
838 '--tbr was specified, skipping OWNERS check for DEPS additions')]
839 if not input_api.change.issue:
840 return [output_api.PresubmitError(
841 "DEPS approval by OWNERS check failed: this change has "
842 "no Rietveld issue number, so we can't check it for approvals.")]
843 output = output_api.PresubmitError
844 else:
845 output = output_api.PresubmitNotifyResult
847 owners_db = input_api.owners_db
848 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
849 input_api,
850 owners_db.email_regexp,
851 approval_needed=input_api.is_committing)
853 owner_email = owner_email or input_api.change.author_email
855 reviewers_plus_owner = set(reviewers)
856 if owner_email:
857 reviewers_plus_owner.add(owner_email)
858 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
859 reviewers_plus_owner)
861 # We strip the /DEPS part that was added by
862 # _FilesToCheckForIncomingDeps to fake a path to a file in a
863 # directory.
864 def StripDeps(path):
865 start_deps = path.rfind('/DEPS')
866 if start_deps != -1:
867 return path[:start_deps]
868 else:
869 return path
870 unapproved_dependencies = ["'+%s'," % StripDeps(path)
871 for path in missing_files]
873 if unapproved_dependencies:
874 output_list = [
875 output('Missing LGTM from OWNERS of dependencies added to DEPS:\n %s' %
876 '\n '.join(sorted(unapproved_dependencies)))]
877 if not input_api.is_committing:
878 suggested_owners = owners_db.reviewers_for(missing_files, owner_email)
879 output_list.append(output(
880 'Suggested missing target path OWNERS:\n %s' %
881 '\n '.join(suggested_owners or [])))
882 return output_list
884 return []
887 def _CheckSpamLogging(input_api, output_api):
888 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
889 black_list = (_EXCLUDED_PATHS +
890 _TEST_CODE_EXCLUDED_PATHS +
891 input_api.DEFAULT_BLACK_LIST +
892 (r"^base[\\\/]logging\.h$",
893 r"^chrome[\\\/]app[\\\/]chrome_main_delegate\.cc$",
894 r"^chrome[\\\/]browser[\\\/]chrome_browser_main\.cc$",
895 r"^chrome[\\\/]browser[\\\/]ui[\\\/]startup[\\\/]"
896 r"startup_browser_creator\.cc$",
897 r"^chrome[\\\/]installer[\\\/]setup[\\\/].*",
898 r"^chrome[\\\/]renderer[\\\/]extensions[\\\/]"
899 r"logging_native_handler\.cc$",
900 r"^content[\\\/]common[\\\/]gpu[\\\/]client[\\\/]"
901 r"gl_helper_benchmark\.cc$",
902 r"^remoting[\\\/]base[\\\/]logging\.h$",
903 r"^remoting[\\\/]host[\\\/].*",
904 r"^sandbox[\\\/]linux[\\\/].*",
905 r"^ui[\\\/]aura[\\\/]bench[\\\/]bench_main\.cc$",))
906 source_file_filter = lambda x: input_api.FilterSourceFile(
907 x, white_list=(file_inclusion_pattern,), black_list=black_list)
909 log_info = []
910 printf = []
912 for f in input_api.AffectedSourceFiles(source_file_filter):
913 contents = input_api.ReadFile(f, 'rb')
914 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
915 log_info.append(f.LocalPath())
916 elif re.search(r"\bD?LOG_IF\s*\(\s*INFO\s*,", contents):
917 log_info.append(f.LocalPath())
919 if re.search(r"\bprintf\(", contents):
920 printf.append(f.LocalPath())
921 elif re.search(r"\bfprintf\((stdout|stderr)", contents):
922 printf.append(f.LocalPath())
924 if log_info:
925 return [output_api.PresubmitError(
926 'These files spam the console log with LOG(INFO):',
927 items=log_info)]
928 if printf:
929 return [output_api.PresubmitError(
930 'These files spam the console log with printf/fprintf:',
931 items=printf)]
932 return []
935 def _CheckForAnonymousVariables(input_api, output_api):
936 """These types are all expected to hold locks while in scope and
937 so should never be anonymous (which causes them to be immediately
938 destroyed)."""
939 they_who_must_be_named = [
940 'base::AutoLock',
941 'base::AutoReset',
942 'base::AutoUnlock',
943 'SkAutoAlphaRestore',
944 'SkAutoBitmapShaderInstall',
945 'SkAutoBlitterChoose',
946 'SkAutoBounderCommit',
947 'SkAutoCallProc',
948 'SkAutoCanvasRestore',
949 'SkAutoCommentBlock',
950 'SkAutoDescriptor',
951 'SkAutoDisableDirectionCheck',
952 'SkAutoDisableOvalCheck',
953 'SkAutoFree',
954 'SkAutoGlyphCache',
955 'SkAutoHDC',
956 'SkAutoLockColors',
957 'SkAutoLockPixels',
958 'SkAutoMalloc',
959 'SkAutoMaskFreeImage',
960 'SkAutoMutexAcquire',
961 'SkAutoPathBoundsUpdate',
962 'SkAutoPDFRelease',
963 'SkAutoRasterClipValidate',
964 'SkAutoRef',
965 'SkAutoTime',
966 'SkAutoTrace',
967 'SkAutoUnref',
969 anonymous = r'(%s)\s*[({]' % '|'.join(they_who_must_be_named)
970 # bad: base::AutoLock(lock.get());
971 # not bad: base::AutoLock lock(lock.get());
972 bad_pattern = input_api.re.compile(anonymous)
973 # good: new base::AutoLock(lock.get())
974 good_pattern = input_api.re.compile(r'\bnew\s*' + anonymous)
975 errors = []
977 for f in input_api.AffectedFiles():
978 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
979 continue
980 for linenum, line in f.ChangedContents():
981 if bad_pattern.search(line) and not good_pattern.search(line):
982 errors.append('%s:%d' % (f.LocalPath(), linenum))
984 if errors:
985 return [output_api.PresubmitError(
986 'These lines create anonymous variables that need to be named:',
987 items=errors)]
988 return []
991 def _CheckCygwinShell(input_api, output_api):
992 source_file_filter = lambda x: input_api.FilterSourceFile(
993 x, white_list=(r'.+\.(gyp|gypi)$',))
994 cygwin_shell = []
996 for f in input_api.AffectedSourceFiles(source_file_filter):
997 for linenum, line in f.ChangedContents():
998 if 'msvs_cygwin_shell' in line:
999 cygwin_shell.append(f.LocalPath())
1000 break
1002 if cygwin_shell:
1003 return [output_api.PresubmitError(
1004 'These files should not use msvs_cygwin_shell (the default is 0):',
1005 items=cygwin_shell)]
1006 return []
1009 def _CheckJavaStyle(input_api, output_api):
1010 """Runs checkstyle on changed java files and returns errors if any exist."""
1011 original_sys_path = sys.path
1012 try:
1013 sys.path = sys.path + [input_api.os_path.join(
1014 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1015 import checkstyle
1016 finally:
1017 # Restore sys.path to what it was before.
1018 sys.path = original_sys_path
1020 return checkstyle.RunCheckstyle(
1021 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1024 def _CommonChecks(input_api, output_api):
1025 """Checks common to both upload and commit."""
1026 results = []
1027 results.extend(input_api.canned_checks.PanProjectChecks(
1028 input_api, output_api,
1029 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
1030 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
1031 results.extend(
1032 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
1033 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
1034 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
1035 results.extend(_CheckNoNewWStrings(input_api, output_api))
1036 results.extend(_CheckNoDEPSGIT(input_api, output_api))
1037 results.extend(_CheckNoBannedFunctions(input_api, output_api))
1038 results.extend(_CheckNoPragmaOnce(input_api, output_api))
1039 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
1040 results.extend(_CheckUnwantedDependencies(input_api, output_api))
1041 results.extend(_CheckFilePermissions(input_api, output_api))
1042 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
1043 results.extend(_CheckIncludeOrder(input_api, output_api))
1044 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
1045 results.extend(_CheckPatchFiles(input_api, output_api))
1046 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
1047 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api))
1048 results.extend(_CheckForInvalidOSMacros(input_api, output_api))
1049 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
1050 results.extend(
1051 input_api.canned_checks.CheckChangeHasNoTabs(
1052 input_api,
1053 output_api,
1054 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
1055 results.extend(_CheckSpamLogging(input_api, output_api))
1056 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1057 results.extend(_CheckCygwinShell(input_api, output_api))
1058 results.extend(_CheckJavaStyle(input_api, output_api))
1060 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1061 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1062 input_api, output_api,
1063 input_api.PresubmitLocalPath(),
1064 whitelist=[r'^PRESUBMIT_test\.py$']))
1065 return results
1068 def _CheckSubversionConfig(input_api, output_api):
1069 """Verifies the subversion config file is correctly setup.
1071 Checks that autoprops are enabled, returns an error otherwise.
1073 join = input_api.os_path.join
1074 if input_api.platform == 'win32':
1075 appdata = input_api.environ.get('APPDATA', '')
1076 if not appdata:
1077 return [output_api.PresubmitError('%APPDATA% is not configured.')]
1078 path = join(appdata, 'Subversion', 'config')
1079 else:
1080 home = input_api.environ.get('HOME', '')
1081 if not home:
1082 return [output_api.PresubmitError('$HOME is not configured.')]
1083 path = join(home, '.subversion', 'config')
1085 error_msg = (
1086 'Please look at http://dev.chromium.org/developers/coding-style to\n'
1087 'configure your subversion configuration file. This enables automatic\n'
1088 'properties to simplify the project maintenance.\n'
1089 'Pro-tip: just download and install\n'
1090 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
1092 try:
1093 lines = open(path, 'r').read().splitlines()
1094 # Make sure auto-props is enabled and check for 2 Chromium standard
1095 # auto-prop.
1096 if (not '*.cc = svn:eol-style=LF' in lines or
1097 not '*.pdf = svn:mime-type=application/pdf' in lines or
1098 not 'enable-auto-props = yes' in lines):
1099 return [
1100 output_api.PresubmitNotifyResult(
1101 'It looks like you have not configured your subversion config '
1102 'file or it is not up-to-date.\n' + error_msg)
1104 except (OSError, IOError):
1105 return [
1106 output_api.PresubmitNotifyResult(
1107 'Can\'t find your subversion config file.\n' + error_msg)
1109 return []
1112 def _CheckAuthorizedAuthor(input_api, output_api):
1113 """For non-googler/chromites committers, verify the author's email address is
1114 in AUTHORS.
1116 # TODO(maruel): Add it to input_api?
1117 import fnmatch
1119 author = input_api.change.author_email
1120 if not author:
1121 input_api.logging.info('No author, skipping AUTHOR check')
1122 return []
1123 authors_path = input_api.os_path.join(
1124 input_api.PresubmitLocalPath(), 'AUTHORS')
1125 valid_authors = (
1126 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
1127 for line in open(authors_path))
1128 valid_authors = [item.group(1).lower() for item in valid_authors if item]
1129 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
1130 input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
1131 return [output_api.PresubmitPromptWarning(
1132 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
1133 '\n'
1134 'http://www.chromium.org/developers/contributing-code and read the '
1135 '"Legal" section\n'
1136 'If you are a chromite, verify the contributor signed the CLA.') %
1137 author)]
1138 return []
1141 def _CheckPatchFiles(input_api, output_api):
1142 problems = [f.LocalPath() for f in input_api.AffectedFiles()
1143 if f.LocalPath().endswith(('.orig', '.rej'))]
1144 if problems:
1145 return [output_api.PresubmitError(
1146 "Don't commit .rej and .orig files.", problems)]
1147 else:
1148 return []
1151 def _DidYouMeanOSMacro(bad_macro):
1152 try:
1153 return {'A': 'OS_ANDROID',
1154 'B': 'OS_BSD',
1155 'C': 'OS_CHROMEOS',
1156 'F': 'OS_FREEBSD',
1157 'L': 'OS_LINUX',
1158 'M': 'OS_MACOSX',
1159 'N': 'OS_NACL',
1160 'O': 'OS_OPENBSD',
1161 'P': 'OS_POSIX',
1162 'S': 'OS_SOLARIS',
1163 'W': 'OS_WIN'}[bad_macro[3].upper()]
1164 except KeyError:
1165 return ''
1168 def _CheckForInvalidOSMacrosInFile(input_api, f):
1169 """Check for sensible looking, totally invalid OS macros."""
1170 preprocessor_statement = input_api.re.compile(r'^\s*#')
1171 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)')
1172 results = []
1173 for lnum, line in f.ChangedContents():
1174 if preprocessor_statement.search(line):
1175 for match in os_macro.finditer(line):
1176 if not match.group(1) in _VALID_OS_MACROS:
1177 good = _DidYouMeanOSMacro(match.group(1))
1178 did_you_mean = ' (did you mean %s?)' % good if good else ''
1179 results.append(' %s:%d %s%s' % (f.LocalPath(),
1180 lnum,
1181 match.group(1),
1182 did_you_mean))
1183 return results
1186 def _CheckForInvalidOSMacros(input_api, output_api):
1187 """Check all affected files for invalid OS macros."""
1188 bad_macros = []
1189 for f in input_api.AffectedFiles():
1190 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')):
1191 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f))
1193 if not bad_macros:
1194 return []
1196 return [output_api.PresubmitError(
1197 'Possibly invalid OS macro[s] found. Please fix your code\n'
1198 'or add your macro to src/PRESUBMIT.py.', bad_macros)]
1201 def CheckChangeOnUpload(input_api, output_api):
1202 results = []
1203 results.extend(_CommonChecks(input_api, output_api))
1204 return results
1207 def GetDefaultTryConfigs(bots=None):
1208 """Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
1210 To add tests to this list, they MUST be in the the corresponding master's
1211 gatekeeper config. For example, anything on master.chromium would be closed by
1212 tools/build/masters/master.chromium/master_gatekeeper_cfg.py.
1214 If 'bots' is specified, will only return configurations for bots in that list.
1217 standard_tests = [
1218 'base_unittests',
1219 'browser_tests',
1220 'cacheinvalidation_unittests',
1221 'check_deps',
1222 'check_deps2git',
1223 'content_browsertests',
1224 'content_unittests',
1225 'crypto_unittests',
1226 #'gfx_unittests',
1227 'gpu_unittests',
1228 'interactive_ui_tests',
1229 'ipc_tests',
1230 'jingle_unittests',
1231 'media_unittests',
1232 'net_unittests',
1233 'ppapi_unittests',
1234 'printing_unittests',
1235 'sql_unittests',
1236 'sync_unit_tests',
1237 'unit_tests',
1238 # Broken in release.
1239 #'url_unittests',
1240 #'webkit_unit_tests',
1243 linux_aura_tests = [
1244 'app_list_unittests',
1245 'aura_unittests',
1246 'browser_tests',
1247 'compositor_unittests',
1248 'content_browsertests',
1249 'content_unittests',
1250 'events_unittests',
1251 'interactive_ui_tests',
1252 'unit_tests',
1254 builders_and_tests = {
1255 # TODO(maruel): Figure out a way to run 'sizes' where people can
1256 # effectively update the perf expectation correctly. This requires a
1257 # clobber=True build running 'sizes'. 'sizes' is not accurate with
1258 # incremental build. Reference:
1259 # http://chromium.org/developers/tree-sheriffs/perf-sheriffs.
1260 # TODO(maruel): An option would be to run 'sizes' but not count a failure
1261 # of this step as a try job failure.
1262 'android_aosp': ['compile'],
1263 'android_clang_dbg': ['slave_steps'],
1264 'android_dbg': ['slave_steps'],
1265 'cros_x86': ['defaulttests'],
1266 'ios_dbg_simulator': [
1267 'compile',
1268 'base_unittests',
1269 'content_unittests',
1270 'crypto_unittests',
1271 'url_unittests',
1272 'net_unittests',
1273 'sql_unittests',
1274 'ui_unittests',
1276 'ios_rel_device': ['compile'],
1277 'linux_asan': ['defaulttests'],
1278 #TODO(stip): Change the name of this builder to reflect that it's release.
1279 'linux_aura': linux_aura_tests,
1280 'linux_chromeos_asan': ['defaulttests'],
1281 'linux_chromeos_clang': ['compile'],
1282 # Note: It is a Release builder even if its name convey otherwise.
1283 'linux_chromeos': standard_tests + [
1284 'app_list_unittests',
1285 'aura_unittests',
1286 'ash_unittests',
1287 'chromeos_unittests',
1288 'components_unittests',
1289 'dbus_unittests',
1290 'device_unittests',
1291 'events_unittests',
1292 'google_apis_unittests',
1293 'sandbox_linux_unittests',
1295 'linux_chromium_dbg': ['defaulttests'],
1296 'linux_chromium_rel': ['defaulttests'],
1297 'linux_clang': ['compile'],
1298 'linux_nacl_sdk_build': ['compile'],
1299 'linux_rel': standard_tests + [
1300 'cc_unittests',
1301 'chromedriver_unittests',
1302 'components_unittests',
1303 'google_apis_unittests',
1304 'nacl_integration',
1305 'remoting_unittests',
1306 'sandbox_linux_unittests',
1307 'sync_integration_tests',
1309 'mac': ['compile'],
1310 'mac_chromium_dbg': ['defaulttests'],
1311 'mac_chromium_rel': ['defaulttests'],
1312 'mac_nacl_sdk_build': ['compile'],
1313 'mac_rel': standard_tests + [
1314 'app_list_unittests',
1315 'cc_unittests',
1316 'chromedriver_unittests',
1317 'components_unittests',
1318 'google_apis_unittests',
1319 'message_center_unittests',
1320 'nacl_integration',
1321 'remoting_unittests',
1322 'sync_integration_tests',
1323 'telemetry_unittests',
1325 'win': ['compile'],
1326 'win_nacl_sdk_build': ['compile'],
1327 'win_rel': standard_tests + [
1328 'app_list_unittests',
1329 'ash_unittests',
1330 'aura_unittests',
1331 'cc_unittests',
1332 'chrome_elf_unittests',
1333 'chromedriver_unittests',
1334 'components_unittests',
1335 'compositor_unittests',
1336 'events_unittests',
1337 'google_apis_unittests',
1338 'installer_util_unittests',
1339 'mini_installer_test',
1340 'nacl_integration',
1341 'remoting_unittests',
1342 'sync_integration_tests',
1343 'telemetry_unittests',
1344 'views_unittests',
1346 'win_x64_rel': [
1347 'base_unittests',
1351 swarm_enabled_builders = (
1352 'linux_rel',
1353 'mac_rel',
1354 'win_rel',
1357 swarm_enabled_tests = (
1358 'base_unittests',
1359 'browser_tests',
1360 'interactive_ui_tests',
1361 'net_unittests',
1362 'unit_tests',
1365 for bot in builders_and_tests:
1366 if bot in swarm_enabled_builders:
1367 builders_and_tests[bot] = [x + '_swarm' if x in swarm_enabled_tests else x
1368 for x in builders_and_tests[bot]]
1370 if bots:
1371 return [(bot, set(builders_and_tests[bot])) for bot in bots]
1372 else:
1373 return [(bot, set(tests)) for bot, tests in builders_and_tests.iteritems()]
1376 def CheckChangeOnCommit(input_api, output_api):
1377 results = []
1378 results.extend(_CommonChecks(input_api, output_api))
1379 # TODO(thestig) temporarily disabled, doesn't work in third_party/
1380 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
1381 # input_api, output_api, sources))
1382 # Make sure the tree is 'open'.
1383 results.extend(input_api.canned_checks.CheckTreeIsOpen(
1384 input_api,
1385 output_api,
1386 json_url='http://chromium-status.appspot.com/current?format=json'))
1387 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
1388 output_api, 'http://codereview.chromium.org',
1389 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
1390 'tryserver@chromium.org'))
1392 results.extend(input_api.canned_checks.CheckChangeHasBugField(
1393 input_api, output_api))
1394 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1395 input_api, output_api))
1396 results.extend(_CheckSubversionConfig(input_api, output_api))
1397 return results
1400 def GetPreferredTrySlaves(project, change):
1401 files = change.LocalPaths()
1403 if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
1404 return []
1406 if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
1407 return GetDefaultTryConfigs(['mac', 'mac_rel'])
1408 if all(re.search('(^|[/_])win[/_.]', f) for f in files):
1409 return GetDefaultTryConfigs(['win', 'win_rel'])
1410 if all(re.search('(^|[/_])android[/_.]', f) for f in files):
1411 return GetDefaultTryConfigs([
1412 'android_aosp',
1413 'android_clang_dbg',
1414 'android_dbg',
1416 if all(re.search('[/_]ios[/_.]', f) for f in files):
1417 return GetDefaultTryConfigs(['ios_rel_device', 'ios_dbg_simulator'])
1419 trybots = GetDefaultTryConfigs([
1420 'android_clang_dbg',
1421 'android_dbg',
1422 'ios_dbg_simulator',
1423 'ios_rel_device',
1424 'linux_aura',
1425 'linux_asan',
1426 'linux_chromeos',
1427 'linux_clang',
1428 'linux_nacl_sdk_build',
1429 'linux_rel',
1430 'mac',
1431 'mac_nacl_sdk_build',
1432 'mac_rel',
1433 'win',
1434 'win_nacl_sdk_build',
1435 'win_rel',
1436 'win_x64_rel',
1439 # Match things like path/aura/file.cc and path/file_aura.cc.
1440 # Same for chromeos.
1441 if any(re.search('[/_](aura|chromeos)', f) for f in files):
1442 trybots.extend(GetDefaultTryConfigs([
1443 'linux_chromeos_asan', 'linux_chromeos_clang']))
1445 # If there are gyp changes to base, build, or chromeos, run a full cros build
1446 # in addition to the shorter linux_chromeos build. Changes to high level gyp
1447 # files have a much higher chance of breaking the cros build, which is
1448 # differnt from the linux_chromeos build that most chrome developers test
1449 # with.
1450 if any(re.search('^(base|build|chromeos).*\.gypi?$', f) for f in files):
1451 trybots.extend(GetDefaultTryConfigs(['cros_x86']))
1453 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1454 # unless they're .gyp(i) files as changes to those files can break the gyp
1455 # step on that bot.
1456 if (not all(re.search('^chrome', f) for f in files) or
1457 any(re.search('\.gypi?$', f) for f in files)):
1458 trybots.extend(GetDefaultTryConfigs(['android_aosp']))
1460 # Experimental recipe-based Chromium trybots. To avoid possible capacity
1461 # problems, only enable for a small percentage of try runs.
1462 if random.random() < 0.25:
1463 trybots.extend(GetDefaultTryConfigs([
1464 'linux_chromium_dbg',
1465 'linux_chromium_rel',
1466 'mac_chromium_dbg',
1467 'mac_chromium_rel',
1470 return trybots