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