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

Unified Diff: PRESUBMIT.py

Issue 1003363005: Add presubmit check for copyright notice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months 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: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index ae5a2183162c81026e8e382e6792b75fe362cc8c..d2e8ee6951cc5cf2c443d3e8efe1d7d03ac069c6 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -118,6 +118,38 @@ def _IfDefChecks(input_api, output_api):
return results
+def _CopyrightChecks(input_api, output_api, source_file_filter=None):
+ results = []
+ year_pattern = r'\d{4}'
+ year_range_pattern = r'%s(-%s)?' % (year_pattern, year_pattern)
+ years_pattern = r'%s(,%s)*,?' % (year_range_pattern, year_range_pattern)
+ copyright_pattern = (
+ r'Copyright (\([cC]\) )?%s %s' % (years_pattern, '%s'))
+ owners = [
+ 'ARM Ltd.',
+ 'Code Aurora Forum. All rights reserved.',
+ 'Google,? Inc\.?( All rights reserved.)?',
+ 'Intel Inc.',
+ 'Lua.org, PUC-Rio',
+ 'Skia',
+ 'The Android Open Source Project',
+ 'The Chromium Authors. All rights reserved.',
+ 'The Native Client Authors. All rights reserved.',
borenet 2015/03/23 14:38:05 I just pulled these from existing copyright notice
mtklein 2015/03/23 14:49:50 Let's both exclude third_party ('Lua.org, PUC-Rio'
borenet 2015/03/23 17:20:35 Done.
+ ]
+
+ for affected_file in input_api.AffectedSourceFiles(source_file_filter):
+ contents = input_api.ReadFile(affected_file, 'rb')
+ found = False
+ for owner in owners:
+ if re.search(copyright_pattern % owner, contents):
+ found = True
+ break
+ if not found:
+ results.append(output_api.PresubmitError(
+ '%s is missing a correct copyright header.' % affected_file))
+ return results
+
+
def _CommonChecks(input_api, output_api):
"""Presubmit checks common to upload and commit."""
results = []
@@ -132,6 +164,8 @@ def _CommonChecks(input_api, output_api):
input_api, output_api, source_file_filter=sources))
results.extend(_PythonChecks(input_api, output_api))
results.extend(_IfDefChecks(input_api, output_api))
+ results.extend(_CopyrightChecks(input_api, output_api,
+ source_file_filter=sources))
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