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:
Sky Malice
2025-03-28 15:01:24 -07:00
committed by LUCI CQ
parent c75e6df261
commit c214cd9faf
3 changed files with 35 additions and 16 deletions

View File

@@ -775,22 +775,25 @@ def CheckLicense(input_api,
# The (c) is deprecated, but tolerate it until it's removed from all # The (c) is deprecated, but tolerate it until it's removed from all
# files. "All rights reserved" is also deprecated, but tolerate it until # files. "All rights reserved" is also deprecated, but tolerate it until
# it's removed from all files. # it's removed from all files.
license_re = (r'.*? Copyright (\(c\) )?%(year)s The %(project)s Authors' license_re = (
r'(\. All rights reserved\.)?\n' r'(?:.+ )?Copyright (\(c\) )?%(year)s The %(project)s Authors'
r'.*? %(key_line)s\n' r'(\. All rights reserved\.)?\n'
r'.*? found in the LICENSE file\.(?: \*/)?\n') % { r'(?:.+ )?%(key_line)s\n'
'year': years_re, r'(?:.+ )?found in the LICENSE file\.(?: \*/)?\n') % {
'project': project_name, 'year': years_re,
'key_line': key_line, 'project': project_name,
} 'key_line': key_line,
}
# On new files don't tolerate any digression from the ideal. # On new files don't tolerate any digression from the ideal.
new_license_re = (r'.*? Copyright %(year)s The %(project)s Authors\n' new_license_re = (
r'.*? %(key_line)s\n' r'(?:.+ )?Copyright %(year)s The %(project)s Authors\n'
r'.*? found in the LICENSE file\.(?: \*/)?\n') % { r'(?:.+ )?%(key_line)s\n'
'year': years_re, r'(?:.+ )?found in the LICENSE file\.(?: \*/)?\n') % {
'project': project_name, 'year': years_re,
'key_line': key_line, 'project': project_name,
} 'key_line': key_line,
}
license_re = input_api.re.compile(license_re, input_api.re.MULTILINE) license_re = input_api.re.compile(license_re, input_api.re.MULTILINE)
new_license_re = input_api.re.compile(new_license_re, new_license_re = input_api.re.compile(new_license_re,

View File

@@ -574,6 +574,7 @@ class InputApi(object):
r'.+\.mojom$', r'.+\.mojom$',
r'.+\.fidl$', r'.+\.fidl$',
r'.+\.rs$', r'.+\.rs$',
r'.+\/res\/.+\.xml$',
) )
# Path regexp that should be excluded from being considered containing # Path regexp that should be excluded from being considered containing

View File

@@ -1450,7 +1450,7 @@ class InputApiUnittest(PresubmitTestsBase):
def testDefaultOverrides(self): def testDefaultOverrides(self):
input_api = presubmit.InputApi(self.fake_change, './PRESUBMIT.py', input_api = presubmit.InputApi(self.fake_change, './PRESUBMIT.py',
False, None, False) 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) self.assertEqual(len(input_api.DEFAULT_FILES_TO_SKIP), 12)
input_api.DEFAULT_FILES_TO_CHECK = (r'.+\.c$', ) input_api.DEFAULT_FILES_TO_CHECK = (r'.+\.c$', )
@@ -2796,6 +2796,21 @@ the current line as well!
license_text = None license_text = None
self._LicenseCheck(text, license_text, False, None, new_file=True) 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): def testCannedCheckTreeIsOpenOpen(self):
input_api = self.MockInputApi(None, True) input_api = self.MockInputApi(None, True)
input_api.urllib_request.urlopen( input_api.urllib_request.urlopen(