1 # Copyright (c) 2010 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.
13 r
"net/tools/spdyshark/[\\\/].*",
24 r
".*? Copyright \(c\) 20[0-9\-]{2,7} The Chromium Authors\. All rights "
26 r
".*? Use of this source code is governed by a BSD-style license that can "
28 r
".*? found in the LICENSE file\."
32 def _CheckSingletonInHeaders(input_api
, output_api
, source_file_filter
):
33 """Checks to make sure no header files have |Singleton<|."""
34 pattern
= input_api
.re
.compile(r
'Singleton<')
36 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
37 if (f
.LocalPath().endswith('.h') or f
.LocalPath().endswith('.hxx') or
38 f
.LocalPath().endswith('.hpp') or f
.LocalPath().endswith('.inl')):
39 contents
= input_api
.ReadFile(f
)
40 if pattern
.search(contents
):
44 return [ output_api
.PresubmitError(
45 'Found Singleton<T> in the following header files.\n' +
46 'Please move them to an appropriate source file so that the ' +
47 'template gets instantiated in a single compilation unit.',
51 def _CheckConstNSObject(input_api
, output_api
, source_file_filter
):
52 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
53 pattern
= input_api
.re
.compile(r
'const\s+NS\w*\s*\*')
55 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
56 if f
.LocalPath().endswith('.h') or f
.LocalPath().endswith('.mm'):
57 contents
= input_api
.ReadFile(f
)
58 if pattern
.search(contents
):
62 if input_api
.is_committing
:
63 res_type
= output_api
.PresubmitPromptWarning
65 res_type
= output_api
.PresubmitNotifyResult
66 return [ res_type('|const NSClass*| is wrong, see ' +
67 'http://dev.chromium.org/developers/clang-mac',
72 def _CommonChecks(input_api
, output_api
):
74 # What does this code do?
75 # It loads the default black list (e.g. third_party, experimental, etc) and
76 # add our black list (breakpad, skia and v8 are still not following
77 # google style and are not really living this repository).
78 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
79 black_list
= input_api
.DEFAULT_BLACK_LIST
+ _EXCLUDED_PATHS
80 white_list
= input_api
.DEFAULT_WHITE_LIST
+ _TEXT_FILES
81 sources
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
)
82 text_files
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
,
83 white_list
=white_list
)
84 results
.extend(input_api
.canned_checks
.CheckLongLines(
85 input_api
, output_api
, source_file_filter
=sources
))
86 results
.extend(input_api
.canned_checks
.CheckChangeHasNoTabs(
87 input_api
, output_api
, source_file_filter
=sources
))
88 results
.extend(input_api
.canned_checks
.CheckChangeHasNoStrayWhitespace(
89 input_api
, output_api
, source_file_filter
=sources
))
90 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
91 input_api
, output_api
))
92 results
.extend(input_api
.canned_checks
.CheckChangeHasTestField(
93 input_api
, output_api
))
94 results
.extend(input_api
.canned_checks
.CheckChangeSvnEolStyle(
95 input_api
, output_api
, source_file_filter
=text_files
))
96 results
.extend(input_api
.canned_checks
.CheckSvnForCommonMimeTypes(
97 input_api
, output_api
))
98 results
.extend(input_api
.canned_checks
.CheckLicense(
99 input_api
, output_api
, _LICENSE_HEADER
, source_file_filter
=sources
))
100 results
.extend(_CheckConstNSObject(
101 input_api
, output_api
, source_file_filter
=sources
))
102 results
.extend(_CheckSingletonInHeaders(
103 input_api
, output_api
, source_file_filter
=sources
))
107 def CheckChangeOnUpload(input_api
, output_api
):
109 results
.extend(_CommonChecks(input_api
, output_api
))
113 def CheckChangeOnCommit(input_api
, output_api
):
115 if not input_api
.json
:
116 results
.append(output_api
.PresubmitNotifyResult(
117 'You don\'t have json nor simplejson installed.\n'
118 ' This is a warning that you will need to upgrade your python '
120 ' This is no big deal but you\'ll eventually need to '
122 ' How? Easy! You can do it right now and shut me off! Just:\n'
123 ' del depot_tools\\python.bat\n'
125 ' Thanks for your patience.'))
126 results
.extend(_CommonChecks(input_api
, output_api
))
127 # TODO(thestig) temporarily disabled, doesn't work in third_party/
128 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
129 # input_api, output_api, sources))
130 # Make sure the tree is 'open'.
131 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
134 json_url
='http://chromium-status.appspot.com/current?format=json'))
135 results
.extend(input_api
.canned_checks
.CheckRietveldTryJobExecution(input_api
,
136 output_api
, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
137 'tryserver@chromium.org'))
139 # These builders are just too slow.
143 'Chromium Arm (dbg)',
145 'Chromium Linux x64',
147 results
.extend(input_api
.canned_checks
.CheckBuildbotPendingBuilds(
150 'http://build.chromium.org/buildbot/waterfall/json/builders?filter=1',
156 def GetPreferredTrySlaves():
157 return ['win', 'linux', 'mac']