Commit 9623d88e authored by Bruce Dawson's avatar Bruce Dawson Committed by LUCI CQ

Enforce license requirement on new files

We have long had a presubmit that warns when a file lacks a suitable
license, but because this is a warning it can be ignored by the author
and is not visible to reviewers. Every failure that is not prevented
will occur, and indeed newly added files from this year (seen in
crrev.com/c/3706888 and crrev.com/c/3437860, and possibly others) are
missing valid licenses.

This change turns the warning into an error on newly added files.

Bug: 1361031
Change-Id: Ie17bd6e591918affd9d865a3bf2be6c2bf62d1ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3887721Reviewed-by: 's avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
parent 3d1a52e0
......@@ -668,6 +668,7 @@ def CheckLicense(input_api, output_api, license_re=None, project_name=None,
license_re = input_api.re.compile(license_re, input_api.re.MULTILINE)
bad_files = []
bad_new_files = False
for f in input_api.AffectedSourceFiles(source_file_filter):
contents = input_api.ReadFile(f, 'r')
if accept_empty_files and not contents:
......@@ -675,8 +676,21 @@ def CheckLicense(input_api, output_api, license_re=None, project_name=None,
# Search for key_line first to avoid fruitless and expensive regex searches.
if (key_line and not key_line in contents):
bad_files.append(f.LocalPath())
# f.OldContents() is expensive so don't call unless necessary.
if not f.OldContents():
bad_new_files = True
elif not license_re.search(contents):
bad_files.append(f.LocalPath())
# f.OldContents() is expensive so don't call unless necessary.
if not f.OldContents():
bad_new_files = True
if bad_new_files:
return [
output_api.PresubmitError(
'License must match:\n%s\n' % license_re.pattern +
'Found a bad license header in these files, some of which are new:',
items=bad_files)
]
if bad_files:
return [output_api.PresubmitPromptWarning(
'License must match:\n%s\n' % license_re.pattern +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment