mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
Add android resource files to DEFAULT_FILES_TO_CHECK.
The existing licence regex assumed each line would start with an unknown and optional comment delimiter, followed by a required space. However the standard way to write the licence in XML files uses a multi-line comment, each individual line simply starts with the licence text, no delimiter or space. The license check thus needed to be updated to make the space optional as well. Bug: 407060754 Change-Id: I4a83dd9408de890593952e441ba6b650f726907c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6409392 Commit-Queue: Sky Malice <skym@chromium.org> Reviewed-by: Andy Perelson <ajp@google.com> Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
This commit is contained in:
@@ -775,22 +775,25 @@ def CheckLicense(input_api,
|
||||
# The (c) is deprecated, but tolerate it until it's removed from all
|
||||
# files. "All rights reserved" is also deprecated, but tolerate it until
|
||||
# it's removed from all files.
|
||||
license_re = (r'.*? Copyright (\(c\) )?%(year)s The %(project)s Authors'
|
||||
r'(\. All rights reserved\.)?\n'
|
||||
r'.*? %(key_line)s\n'
|
||||
r'.*? found in the LICENSE file\.(?: \*/)?\n') % {
|
||||
'year': years_re,
|
||||
'project': project_name,
|
||||
'key_line': key_line,
|
||||
}
|
||||
license_re = (
|
||||
r'(?:.+ )?Copyright (\(c\) )?%(year)s The %(project)s Authors'
|
||||
r'(\. All rights reserved\.)?\n'
|
||||
r'(?:.+ )?%(key_line)s\n'
|
||||
r'(?:.+ )?found in the LICENSE file\.(?: \*/)?\n') % {
|
||||
'year': years_re,
|
||||
'project': project_name,
|
||||
'key_line': key_line,
|
||||
}
|
||||
|
||||
# On new files don't tolerate any digression from the ideal.
|
||||
new_license_re = (r'.*? Copyright %(year)s The %(project)s Authors\n'
|
||||
r'.*? %(key_line)s\n'
|
||||
r'.*? found in the LICENSE file\.(?: \*/)?\n') % {
|
||||
'year': years_re,
|
||||
'project': project_name,
|
||||
'key_line': key_line,
|
||||
}
|
||||
new_license_re = (
|
||||
r'(?:.+ )?Copyright %(year)s The %(project)s Authors\n'
|
||||
r'(?:.+ )?%(key_line)s\n'
|
||||
r'(?:.+ )?found in the LICENSE file\.(?: \*/)?\n') % {
|
||||
'year': years_re,
|
||||
'project': project_name,
|
||||
'key_line': key_line,
|
||||
}
|
||||
|
||||
license_re = input_api.re.compile(license_re, input_api.re.MULTILINE)
|
||||
new_license_re = input_api.re.compile(new_license_re,
|
||||
|
||||
@@ -574,6 +574,7 @@ class InputApi(object):
|
||||
r'.+\.mojom$',
|
||||
r'.+\.fidl$',
|
||||
r'.+\.rs$',
|
||||
r'.+\/res\/.+\.xml$',
|
||||
)
|
||||
|
||||
# Path regexp that should be excluded from being considered containing
|
||||
|
||||
@@ -1450,7 +1450,7 @@ class InputApiUnittest(PresubmitTestsBase):
|
||||
def testDefaultOverrides(self):
|
||||
input_api = presubmit.InputApi(self.fake_change, './PRESUBMIT.py',
|
||||
False, None, False)
|
||||
self.assertEqual(len(input_api.DEFAULT_FILES_TO_CHECK), 26)
|
||||
self.assertEqual(len(input_api.DEFAULT_FILES_TO_CHECK), 27)
|
||||
self.assertEqual(len(input_api.DEFAULT_FILES_TO_SKIP), 12)
|
||||
|
||||
input_api.DEFAULT_FILES_TO_CHECK = (r'.+\.c$', )
|
||||
@@ -2796,6 +2796,21 @@ the current line as well!
|
||||
license_text = None
|
||||
self._LicenseCheck(text, license_text, False, None, new_file=True)
|
||||
|
||||
def testCheckLicenseNewXMLFilePass(self):
|
||||
# Check that XML-style comments in license text are supported.
|
||||
current_year = int(time.strftime('%Y'))
|
||||
text = (
|
||||
'<?xml version="1.0" encoding="utf-8"?>\n'
|
||||
'<!--\n'
|
||||
'Copyright %d The Chromium Authors\n'
|
||||
'Use of this source code is governed by a BSD-style license that '
|
||||
'can be\n'
|
||||
'found in the LICENSE file.\n'
|
||||
'-->\n'
|
||||
'<root/>\n' % current_year)
|
||||
license_text = None
|
||||
self._LicenseCheck(text, license_text, False, None, new_file=True)
|
||||
|
||||
def testCannedCheckTreeIsOpenOpen(self):
|
||||
input_api = self.MockInputApi(None, True)
|
||||
input_api.urllib_request.urlopen(
|
||||
|
||||
Reference in New Issue
Block a user