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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/PRESUBMIT.py
diff --git a/third_party/WebKit/PRESUBMIT.py b/third_party/WebKit/PRESUBMIT.py
index 435286ee50fd0507caafd9f6502e6221b6d17e70..f303d152047377a7ab54ccf65214ab92229de3b4 100644
--- a/third_party/WebKit/PRESUBMIT.py
+++ b/third_party/WebKit/PRESUBMIT.py
@@ -225,6 +225,37 @@ def _CheckForInvalidPreferenceError(input_api, output_api):
results.append(output_api.PresubmitError('Found an invalid preference %s in expected result %s:%s' % (error.group(1), f, line_num)))
return results
+
+def _CheckForForbiddenNamespace(input_api, output_api):
+ """Checks that Blink uses Chromium namespaces only in permitted code."""
+ # This list is not exhaustive, but covers likely ones.
+ chromium_namespaces = ["base", "cc", "content", "gfx", "net", "ui"]
+ chromium_classes = ["scoped_ptr", "scoped_refptr"]
+
+ def source_file_filter(path):
+ return input_api.FilterSourceFile(path,
+ white_list=[r'third_party/WebKit/Source/.*\.(h|cpp)$'],
+ black_list=[r'third_party/WebKit/Source/(platform|wtf|web)/'])
+
+ comment_re = input_api.re.compile(r'^\s*//')
+ result = []
+ for namespace in chromium_namespaces:
+ namespace_re = input_api.re.compile(r'\b{0}::|^\s*using namespace {0};|^\s*namespace {0} \{{'.format(input_api.re.escape(namespace)))
+ uses_namespace_outside_comments = lambda line: namespace_re.search(line) and not comment_re.search(line)
+ errors = input_api.canned_checks._FindNewViolationsOfRule(lambda _, line: not uses_namespace_outside_comments(line),
+ input_api, source_file_filter)
+ if errors:
+ result += [output_api.PresubmitError('Do not use Chromium namespace {} inside Blink core:\n{}'.format(namespace, '\n'.join(errors)))]
+ for class_name in chromium_classes:
+ class_re = input_api.re.compile(r'\b{0}\b'.format(input_api.re.escape(class_name)))
+ uses_class_outside_comments = lambda line: class_re.search(line) and not comment_re.search(line)
+ errors = input_api.canned_checks._FindNewViolationsOfRule(lambda _, line: not uses_class_outside_comments(line),
+ input_api, source_file_filter)
+ if errors:
+ result += [output_api.PresubmitError('Do not use Chromium class {} inside Blink core:\n{}'.format(class_name, '\n'.join(errors)))]
+ return result
+
+
def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CommonChecks(input_api, output_api))
@@ -232,6 +263,7 @@ def CheckChangeOnUpload(input_api, output_api):
results.extend(_CheckForPrintfDebugging(input_api, output_api))
results.extend(_CheckForDangerousTestFunctions(input_api, output_api))
results.extend(_CheckForInvalidPreferenceError(input_api, output_api))
+ results.extend(_CheckForForbiddenNamespace(input_api, output_api))
return results
« 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