Fix Java indentation issues.
[chromium-blink-merge.git] / base / PRESUBMIT.py
blob758a79053ae57eaeff62d1f39a468991817829d0
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 """Chromium presubmit script for src/base.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details on the presubmit API built into gcl.
9 """
11 import re
13 BASE_SOURCE_FILES=(r'^base/.*\.(cc|h|mm)$',)
15 def _CheckNoInterfacesInBase(input_api, output_api):
16 """Checks to make sure no files in libbase.a have |@interface|."""
17 pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE)
18 files = []
19 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
20 if (f.LocalPath().startswith('base/') and
21 not "/test/" in f.LocalPath() and
22 not f.LocalPath().endswith('_unittest.mm') and
23 not f.LocalPath().endswith('mac/sdk_forward_declarations.h')):
24 contents = input_api.ReadFile(f)
25 if pattern.search(contents):
26 files.append(f)
28 if len(files):
29 return [ output_api.PresubmitError(
30 'Objective-C interfaces or categories are forbidden in libbase. ' +
31 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
32 'browse_thread/thread/efb28c10435987fd',
33 files) ]
34 return []
37 def _CommonChecks(input_api, output_api):
38 """Checks common to both upload and commit."""
39 results = []
40 results.extend(_CheckNoInterfacesInBase(input_api, output_api))
41 return results
43 def _CheckOverrideFinal(input_api, output_api,
44 whitelist=BASE_SOURCE_FILES, blacklist=None):
45 """Make sure new lines of code don't use the OVERRIDE or FINAL macros."""
47 # TODO(mostynb): remove this check once the macros are removed
48 # from base/compiler_specific.h.
50 errors = []
52 source_file_filter = lambda x: input_api.FilterSourceFile(
53 x, white_list=BASE_SOURCE_FILES, black_list=None)
55 override_files = []
56 final_files = []
58 for f in input_api.AffectedSourceFiles(source_file_filter):
59 contents = input_api.ReadFile(f, 'rb')
61 # "override" and "final" should be used instead of OVERRIDE/FINAL now.
62 if re.search(r"\bOVERRIDE\b", contents):
63 override_files.append(f.LocalPath())
65 if re.search(r"\bFINAL\b", contents):
66 final_files.append(f.LocalPath())
68 if override_files:
69 return [output_api.PresubmitError(
70 'These files use OVERRIDE instead of using override:',
71 items=override_files)]
72 if final_files:
73 return [output_api.PresubmitError(
74 'These files use FINAL instead of using final:',
75 items=final_files)]
77 return []
79 def CheckChangeOnUpload(input_api, output_api):
80 results = []
81 results.extend(_CheckOverrideFinal(input_api, output_api))
82 results.extend(_CommonChecks(input_api, output_api))
83 return results
86 def CheckChangeOnCommit(input_api, output_api):
87 results = []
88 results.extend(_CommonChecks(input_api, output_api))
89 return results
92 def GetPreferredTryMasters(project, change):
93 return {
94 'tryserver.chromium.linux': {
95 'linux_chromium_rel_swarming': set(['defaulttests']),
97 'tryserver.chromium.mac': {
98 'mac_chromium_rel_swarming': set(['defaulttests']),
100 'tryserver.chromium.win': {
101 'win_chromium_rel_swarming': set(['defaulttests']),