1 # Copyright (c) 2011 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.
15 r
"^net/tools/spdyshark/[\\\/].*",
27 r
".*? Copyright \(c\) %s The Chromium Authors\. All rights reserved\.\n"
28 r
".*? Use of this source code is governed by a BSD-style license that can "
30 r
".*? found in the LICENSE file\."
32 ) % time
.strftime("%Y")
34 def _CheckNoInterfacesInBase(input_api
, output_api
, source_file_filter
):
35 """Checks to make sure no files in libbase.a have |@interface|."""
36 pattern
= input_api
.re
.compile(r
'@interface')
38 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
39 if (f
.LocalPath().find('base/') != -1 and
40 f
.LocalPath().find('base/test/') == -1):
41 contents
= input_api
.ReadFile(f
)
42 if pattern
.search(contents
):
46 return [ output_api
.PresubmitError(
47 'Objective-C interfaces or categories are forbidden in libbase. ' +
48 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
49 'browse_thread/thread/efb28c10435987fd',
53 def _CheckSingletonInHeaders(input_api
, output_api
, source_file_filter
):
54 """Checks to make sure no header files have |Singleton<|."""
55 pattern
= input_api
.re
.compile(r
'Singleton<')
57 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
58 if (f
.LocalPath().endswith('.h') or f
.LocalPath().endswith('.hxx') or
59 f
.LocalPath().endswith('.hpp') or f
.LocalPath().endswith('.inl')):
60 contents
= input_api
.ReadFile(f
)
61 if pattern
.search(contents
):
65 return [ output_api
.PresubmitError(
66 'Found Singleton<T> in the following header files.\n' +
67 'Please move them to an appropriate source file so that the ' +
68 'template gets instantiated in a single compilation unit.',
73 def _CheckSubversionConfig(input_api
, output_api
):
74 """Verifies the subversion config file is correctly setup.
76 Checks that autoprops are enabled, returns an error otherwise.
78 join
= input_api
.os_path
.join
79 if input_api
.platform
== 'win32':
80 appdata
= input_api
.environ
.get('APPDATA', '')
82 return [output_api
.PresubmitError('%APPDATA% is not configured.')]
83 path
= join(appdata
, 'Subversion', 'config')
85 home
= input_api
.environ
.get('HOME', '')
87 return [output_api
.PresubmitError('$HOME is not configured.')]
88 path
= join(home
, '.subversion', 'config')
91 'Please look at http://dev.chromium.org/developers/coding-style to\n'
92 'configure your subversion configuration file. This enables automatic\n'
93 'properties to simplify the project maintenance.\n'
94 'Pro-tip: just download and install\n'
95 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
98 lines
= open(path
, 'r').read().splitlines()
99 # Make sure auto-props is enabled and check for 2 Chromium standard
101 if (not '*.cc = svn:eol-style=LF' in lines
or
102 not '*.pdf = svn:mime-type=application/pdf' in lines
or
103 not 'enable-auto-props = yes' in lines
):
105 output_api
.PresubmitNotifyResult(
106 'It looks like you have not configured your subversion config '
107 'file or it is not up-to-date.\n' + error_msg
)
109 except (OSError, IOError):
111 output_api
.PresubmitNotifyResult(
112 'Can\'t find your subversion config file.\n' + error_msg
)
117 def _CheckConstNSObject(input_api
, output_api
, source_file_filter
):
118 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
119 pattern
= input_api
.re
.compile(r
'const\s+NS\w*\s*\*')
121 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
122 if f
.LocalPath().endswith('.h') or f
.LocalPath().endswith('.mm'):
123 contents
= input_api
.ReadFile(f
)
124 if pattern
.search(contents
):
128 if input_api
.is_committing
:
129 res_type
= output_api
.PresubmitPromptWarning
131 res_type
= output_api
.PresubmitNotifyResult
132 return [ res_type('|const NSClass*| is wrong, see ' +
133 'http://dev.chromium.org/developers/clang-mac',
138 def _CommonChecks(input_api
, output_api
):
140 # What does this code do?
141 # It loads the default black list (e.g. third_party, experimental, etc) and
142 # add our black list (breakpad, skia and v8 are still not following
143 # google style and are not really living this repository).
144 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
145 black_list
= input_api
.DEFAULT_BLACK_LIST
+ _EXCLUDED_PATHS
146 white_list
= input_api
.DEFAULT_WHITE_LIST
+ _TEXT_FILES
147 sources
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
)
148 text_files
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
,
149 white_list
=white_list
)
151 # TODO(dpranke): enable upload as well
152 if input_api
.is_committing
:
153 results
.extend(input_api
.canned_checks
.CheckOwners(
154 input_api
, output_api
, source_file_filter
=sources
))
156 results
.extend(input_api
.canned_checks
.CheckLongLines(
157 input_api
, output_api
, source_file_filter
=sources
))
158 results
.extend(input_api
.canned_checks
.CheckChangeHasNoTabs(
159 input_api
, output_api
, source_file_filter
=sources
))
160 results
.extend(input_api
.canned_checks
.CheckChangeHasNoStrayWhitespace(
161 input_api
, output_api
, source_file_filter
=sources
))
162 results
.extend(input_api
.canned_checks
.CheckChangeSvnEolStyle(
163 input_api
, output_api
, source_file_filter
=text_files
))
164 results
.extend(input_api
.canned_checks
.CheckSvnForCommonMimeTypes(
165 input_api
, output_api
))
166 results
.extend(input_api
.canned_checks
.CheckLicense(
167 input_api
, output_api
, _LICENSE_HEADER
, source_file_filter
=sources
))
168 results
.extend(_CheckConstNSObject(
169 input_api
, output_api
, source_file_filter
=sources
))
170 results
.extend(_CheckSingletonInHeaders(
171 input_api
, output_api
, source_file_filter
=sources
))
172 results
.extend(_CheckNoInterfacesInBase(
173 input_api
, output_api
, source_file_filter
=sources
))
177 def CheckChangeOnUpload(input_api
, output_api
):
179 results
.extend(_CommonChecks(input_api
, output_api
))
183 def CheckChangeOnCommit(input_api
, output_api
):
185 if not input_api
.json
:
186 results
.append(output_api
.PresubmitNotifyResult(
187 'You don\'t have json nor simplejson installed.\n'
188 ' This is a warning that you will need to upgrade your python '
190 ' This is no big deal but you\'ll eventually need to '
192 ' How? Easy! You can do it right now and shut me off! Just:\n'
193 ' del depot_tools\\python.bat\n'
195 ' Thanks for your patience.'))
196 results
.extend(_CommonChecks(input_api
, output_api
))
197 # TODO(thestig) temporarily disabled, doesn't work in third_party/
198 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
199 # input_api, output_api, sources))
200 # Make sure the tree is 'open'.
201 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
204 json_url
='http://chromium-status.appspot.com/current?format=json'))
205 results
.extend(input_api
.canned_checks
.CheckRietveldTryJobExecution(input_api
,
206 output_api
, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
207 'tryserver@chromium.org'))
209 # These builders are just too slow.
213 'Chromium Arm (dbg)',
215 'Chromium Linux x64',
217 results
.extend(input_api
.canned_checks
.CheckBuildbotPendingBuilds(
220 'http://build.chromium.org/p/chromium/json/builders?filter=1',
223 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
224 input_api
, output_api
))
225 results
.extend(input_api
.canned_checks
.CheckChangeHasTestField(
226 input_api
, output_api
))
227 results
.extend(_CheckSubversionConfig(input_api
, output_api
))
231 def GetPreferredTrySlaves():
232 return ['win', 'linux', 'mac']