Use multiple globs/emails in per-file syntax

Bug: 112259427
Test: tools/checkowners.py -c -v OWNERS */OWNERS */*/OWNERS
Change-Id: I0e2c2c64a23df360fbe7691c4336ca04099fba13
This commit is contained in:
Chih-Hung Hsieh 2018-08-15 16:07:27 -07:00
parent c9f31dff01
commit f77c7f75e5
4 changed files with 29 additions and 32 deletions

7
OWNERS
View File

@ -2,10 +2,7 @@ ccross@android.com
dwillemsen@google.com
nanzhang@google.com
per-file * = ccross@android.com
per-file * = dwillemsen@google.com
per-file * = nanzhang@google.com
per-file * = ccross@android.com,dwillemsen@google.com,nanzhang@google.com
# for version updates
per-file version_defaults.mk = aseaton@google.com
per-file version_defaults.mk = elisapascual@google.com
per-file version_defaults.mk = aseaton@google.com,elisapascual@google.com

View File

@ -1,8 +1 @@
per-file * = ccross@android.com
per-file * = dwillemsen@google.com
per-file * = nanzhang@google.com
per-file dex_preopt*.mk = ngeoffray@google.com
per-file dex_preopt*.mk = calin@google.com
per-file dex_preopt*.mk = mathewi@google.com
per-file dex_preopt*.mk = dbrazdil@google.com
per-file dex_preopt*.mk = ngeoffray@google.com,calin@google.com,mathewi@google.com,dbrazdil@google.com

View File

@ -1,2 +1 @@
per-file warn.py = chh@google.com
per-file checkowners.py = chh@google.com
per-file warn.py,checkowners.py = chh@google.com

View File

@ -35,22 +35,31 @@ def find_address(address):
echo('Checking email address: ' + address)
result = urllib2.urlopen(request).read()
checked_addresses[address] = result.find('"_account_id":') >= 0
if checked_addresses[address]:
echo('Found email address: ' + address)
return checked_addresses[address]
def check_address(fname, num, address):
if find_address(address):
return 0
print '%s:%d: ERROR: unknown email address: %s' % (fname, num, address)
return 1
def main():
# One regular expression to check all valid lines.
noparent = 'set +noparent'
email = '([^@ ]+@[^ @]+|\\*)'
directive = '(%s|%s)' % (email, noparent)
emails = '(%s( *, *%s)*)' % (email, email)
directive = '(%s|%s)' % (emails, noparent)
glob = '[a-zA-Z0-9_\\.\\-\\*\\?]+'
perfile = 'per-file +' + glob + ' *= *' + directive
globs = '(%s( *, *%s)*)' % (glob, glob)
perfile = 'per-file +' + globs + ' *= *' + directive
pats = '(|%s|%s|%s)$' % (noparent, email, perfile)
patterns = re.compile(pats)
# One pattern to capture email address.
email_address = '.*(@| |=|^)([^@ =]+@[^ @]+)'
address_pattern = re.compile(email_address)
address_pattern = re.compile('([^@ ]+@[^ @]+)')
perfile_pattern = re.compile('per-file +.*=(.*)')
error = 0
for fname in args.owners:
@ -60,17 +69,16 @@ def main():
num += 1
stripped_line = re.sub('#.*$', '', line).strip()
if not patterns.match(stripped_line):
error = 1
print('%s:%d: ERROR: unknown line [%s]'
% (fname, num, line.strip()))
elif args.check_address and address_pattern.match(stripped_line):
address = address_pattern.match(stripped_line).group(2)
if find_address(address):
echo('Found email address: ' + address)
else:
error = 1
print('%s:%d: ERROR: unknown email address: %s'
% (fname, num, address))
error += 1
print '%s:%d: ERROR: unknown line [%s]' % (fname, num, line.strip())
elif args.check_address:
if perfile_pattern.match(stripped_line):
for addr in perfile_pattern.match(stripped_line).group(1).split(','):
a = addr.strip()
if a and a != '*':
error += check_address(fname, num, addr.strip())
elif address_pattern.match(stripped_line):
error += check_address(fname, num, stripped_line)
sys.exit(error)
if __name__ == '__main__':