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.
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
)
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
):
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',
37 def _CommonChecks(input_api
, output_api
):
38 """Checks common to both upload and commit."""
40 results
.extend(_CheckNoInterfacesInBase(input_api
, output_api
))
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.
52 source_file_filter
= lambda x
: input_api
.FilterSourceFile(
53 x
, white_list
=BASE_SOURCE_FILES
, black_list
=None)
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())
69 return [output_api
.PresubmitError(
70 'These files use OVERRIDE instead of using override:',
71 items
=override_files
)]
73 return [output_api
.PresubmitError(
74 'These files use FINAL instead of using final:',
79 def CheckChangeOnUpload(input_api
, output_api
):
81 results
.extend(_CheckOverrideFinal(input_api
, output_api
))
82 results
.extend(_CommonChecks(input_api
, output_api
))
86 def CheckChangeOnCommit(input_api
, output_api
):
88 results
.extend(_CommonChecks(input_api
, output_api
))
92 def GetPreferredTryMasters(project
, change
):
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']),