Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: third_party/WebKit/PRESUBMIT.py

Issue 1453743002: Add an upload presubmit rule to catch disallowed use of Chromium namespaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for Blink. 5 """Top-level presubmit script for Blink.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl. 8 for more details about the presubmit API built into gcl.
9 """ 9 """
10 10
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 for f in input_api.AffectedFiles(): 219 for f in input_api.AffectedFiles():
220 if not f.LocalPath().endswith('-expected.txt'): 220 if not f.LocalPath().endswith('-expected.txt'):
221 continue 221 continue
222 for line_num, line in f.ChangedContents(): 222 for line_num, line in f.ChangedContents():
223 error = pattern.search(line) 223 error = pattern.search(line)
224 if error: 224 if error:
225 results.append(output_api.PresubmitError('Found an invalid prefe rence %s in expected result %s:%s' % (error.group(1), f, line_num))) 225 results.append(output_api.PresubmitError('Found an invalid prefe rence %s in expected result %s:%s' % (error.group(1), f, line_num)))
226 return results 226 return results
227 227
228
229 def _CheckForForbiddenNamespace(input_api, output_api):
230 """Checks that Blink uses Chromium namespaces only in permitted code."""
231 # This list is not exhaustive, but covers likely ones.
232 chromium_namespaces = ["base", "cc", "content", "gfx", "net", "ui"]
233 chromium_classes = ["scoped_ptr", "scoped_refptr"]
234
235 def source_file_filter(path):
236 return input_api.FilterSourceFile(path,
237 white_list=[r'third_party/WebKit/Sourc e/.*\.(h|cpp)$'],
238 black_list=[r'third_party/WebKit/Sourc e/(platform|wtf|web)/'])
239
240 comment_re = input_api.re.compile(r'^\s*//')
241 result = []
242 for namespace in chromium_namespaces:
243 namespace_re = input_api.re.compile(r'\b{0}::|^\s*using namespace {0};|^ \s*namespace {0} \{{'.format(input_api.re.escape(namespace)))
244 uses_namespace_outside_comments = lambda line: namespace_re.search(line) and not comment_re.search(line)
245 errors = input_api.canned_checks._FindNewViolationsOfRule(lambda _, line : not uses_namespace_outside_comments(line),
246 input_api, sou rce_file_filter)
247 if errors:
248 result += [output_api.PresubmitError('Do not use Chromium namespace {} inside Blink core:\n{}'.format(namespace, '\n'.join(errors)))]
249 for class_name in chromium_classes:
250 class_re = input_api.re.compile(r'\b{0}\b'.format(input_api.re.escape(cl ass_name)))
251 uses_class_outside_comments = lambda line: class_re.search(line) and not comment_re.search(line)
252 errors = input_api.canned_checks._FindNewViolationsOfRule(lambda _, line : not uses_class_outside_comments(line),
253 input_api, sou rce_file_filter)
254 if errors:
255 result += [output_api.PresubmitError('Do not use Chromium class {} i nside Blink core:\n{}'.format(class_name, '\n'.join(errors)))]
256 return result
257
258
228 def CheckChangeOnUpload(input_api, output_api): 259 def CheckChangeOnUpload(input_api, output_api):
229 results = [] 260 results = []
230 results.extend(_CommonChecks(input_api, output_api)) 261 results.extend(_CommonChecks(input_api, output_api))
231 results.extend(_CheckStyle(input_api, output_api)) 262 results.extend(_CheckStyle(input_api, output_api))
232 results.extend(_CheckForPrintfDebugging(input_api, output_api)) 263 results.extend(_CheckForPrintfDebugging(input_api, output_api))
233 results.extend(_CheckForDangerousTestFunctions(input_api, output_api)) 264 results.extend(_CheckForDangerousTestFunctions(input_api, output_api))
234 results.extend(_CheckForInvalidPreferenceError(input_api, output_api)) 265 results.extend(_CheckForInvalidPreferenceError(input_api, output_api))
266 results.extend(_CheckForForbiddenNamespace(input_api, output_api))
235 return results 267 return results
236 268
237 269
238 def CheckChangeOnCommit(input_api, output_api): 270 def CheckChangeOnCommit(input_api, output_api):
239 results = [] 271 results = []
240 results.extend(_CommonChecks(input_api, output_api)) 272 results.extend(_CommonChecks(input_api, output_api))
241 results.extend(input_api.canned_checks.CheckTreeIsOpen( 273 results.extend(input_api.canned_checks.CheckTreeIsOpen(
242 input_api, output_api, 274 input_api, output_api,
243 json_url='http://chromium-status.appspot.com/current?format=json')) 275 json_url='http://chromium-status.appspot.com/current?format=json'))
244 results.extend(input_api.canned_checks.CheckChangeHasDescription( 276 results.extend(input_api.canned_checks.CheckChangeHasDescription(
(...skipping 19 matching lines...) Expand all
264 for master in masters: 296 for master in masters:
265 try_config.setdefault(master, {}) 297 try_config.setdefault(master, {})
266 for builder in masters[master]: 298 for builder in masters[master]:
267 # Do not trigger presubmit builders, since they're likely to fail 299 # Do not trigger presubmit builders, since they're likely to fail
268 # (e.g. OWNERS checks before finished code review), and we're 300 # (e.g. OWNERS checks before finished code review), and we're
269 # running local presubmit anyway. 301 # running local presubmit anyway.
270 if 'presubmit' not in builder: 302 if 'presubmit' not in builder:
271 try_config[master][builder] = ['defaulttests'] 303 try_config[master][builder] = ['defaulttests']
272 304
273 return try_config 305 return try_config
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698