blob: 3d5513a8b60a90ee745fc1ff83717ac436cfebb9 [file] [log] [blame]
Ben Hutchings746efa12016-09-18 01:44:04 +01001#!/usr/bin/python
2
3import os, re, sys
4
5def list_whence():
6 with open('WHENCE') as whence:
7 for line in whence:
Thierry Reding016a2ec2019-09-30 13:17:04 +02008 match = re.match(r'(?:File|Source):\s*"(.*)"', line)
Hans de Goede026bbcf2018-12-13 17:35:11 +01009 if match:
10 yield match.group(1)
11 continue
Thierry Reding016a2ec2019-09-30 13:17:04 +020012 match = re.match(r'(?:File|Source):\s*(\S*)', line)
Ben Hutchings746efa12016-09-18 01:44:04 +010013 if match:
14 yield match.group(1)
15 continue
16 match = re.match(r'Licen[cs]e: (?:.*\bSee (.*) for details\.?|(\S*))\n',
17 line)
18 if match:
19 if match.group(1):
20 for name in re.split(r', | and ', match.group(1)):
21 yield name
22 continue
23 if match.group(2):
24 # Just one word - may or may not be a filename
25 if not re.search(r'unknown|distributable', match.group(2),
26 re.IGNORECASE):
27 yield match.group(2)
28 continue
29
30def list_git():
31 with os.popen('git ls-files') as git_files:
32 for line in git_files:
33 yield line.rstrip('\n')
34
35def main():
Brian Norris95289452020-02-28 17:32:48 -080036 ret = 0
Ben Hutchings746efa12016-09-18 01:44:04 +010037 whence_list = list(list_whence())
38 known_files = set(name for name in whence_list if not name.endswith('/')) | \
39 set(['check_whence.py', 'configure', 'Makefile',
Josh Boyer95d22ac2019-08-21 08:03:43 -040040 'README', 'copy-firmware.sh', 'WHENCE'])
Ben Hutchings746efa12016-09-18 01:44:04 +010041 known_prefixes = set(name for name in whence_list if name.endswith('/'))
42 git_files = set(list_git())
43
Brian Norris5a121472020-01-23 10:40:34 -080044 known_files |= set(['OWNERS',
45 'PRESUBMIT.cfg',
46 'README.chromium.md',
47 ])
48
Ben Hutchings746efa12016-09-18 01:44:04 +010049 for name in sorted(list(known_files - git_files)):
50 sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
Brian Norris95289452020-02-28 17:32:48 -080051 ret = 1
Ben Hutchings746efa12016-09-18 01:44:04 +010052
53 for name in sorted(list(git_files - known_files)):
54 # Ignore subdirectory changelogs and GPG detached signatures
55 if (name.endswith('/ChangeLog') or
56 (name.endswith('.asc') and name[:-4] in known_files)):
57 continue
58
59 # Ignore unknown files in known directories
60 for prefix in known_prefixes:
61 if name.startswith(prefix):
62 break
63 else:
64 sys.stderr.write('E: %s not listed in WHENCE\n' % name)
Brian Norris95289452020-02-28 17:32:48 -080065 ret = 1
66 return ret
Ben Hutchings746efa12016-09-18 01:44:04 +010067
68if __name__ == '__main__':
Brian Norris95289452020-02-28 17:32:48 -080069 sys.exit(main())