blob: a1bc253c7e13fd35131a68a5b4ce8016b5afde9f [file] [log] [blame]
Ben Hutchings746efa12016-09-18 01:44:04 +01001#!/usr/bin/python
2
3import os, re, sys
Brian Norrisdf6c2a42020-02-28 18:15:05 -08004from io import open
Ben Hutchings746efa12016-09-18 01:44:04 +01005
6def list_whence():
Brian Norrisdf6c2a42020-02-28 18:15:05 -08007 with open('WHENCE', encoding='utf-8') as whence:
Ben Hutchings746efa12016-09-18 01:44:04 +01008 for line in whence:
Thierry Reding016a2ec2019-09-30 13:17:04 +02009 match = re.match(r'(?:File|Source):\s*"(.*)"', line)
Hans de Goede026bbcf2018-12-13 17:35:11 +010010 if match:
11 yield match.group(1)
12 continue
Thierry Reding016a2ec2019-09-30 13:17:04 +020013 match = re.match(r'(?:File|Source):\s*(\S*)', line)
Ben Hutchings746efa12016-09-18 01:44:04 +010014 if match:
15 yield match.group(1)
16 continue
17 match = re.match(r'Licen[cs]e: (?:.*\bSee (.*) for details\.?|(\S*))\n',
18 line)
19 if match:
20 if match.group(1):
21 for name in re.split(r', | and ', match.group(1)):
22 yield name
23 continue
24 if match.group(2):
25 # Just one word - may or may not be a filename
26 if not re.search(r'unknown|distributable', match.group(2),
27 re.IGNORECASE):
28 yield match.group(2)
29 continue
30
31def list_git():
32 with os.popen('git ls-files') as git_files:
33 for line in git_files:
34 yield line.rstrip('\n')
35
36def main():
Brian Norris95289452020-02-28 17:32:48 -080037 ret = 0
Ben Hutchings746efa12016-09-18 01:44:04 +010038 whence_list = list(list_whence())
39 known_files = set(name for name in whence_list if not name.endswith('/')) | \
40 set(['check_whence.py', 'configure', 'Makefile',
Josh Boyer95d22ac2019-08-21 08:03:43 -040041 'README', 'copy-firmware.sh', 'WHENCE'])
Brian Norris2bd383d2020-02-28 17:47:31 -080042
43 # TODO(https://crbug.com/1020597): exception list of files not yet listed
44 # properly in WHENCE. Please remove from this list as you fix up WHENCE.
45 known_files |= set([
46 'ath10k/QCA6174/hw3.0/firmware-sdio-6.bin',
47 'ath10k/QCA6174/hw3.0/notice_ath10k_firmware-sdio-6.txt',
48 'ath10k/WCN3990/hw1.0/board-2.bin',
49 'brcm/brcmfmac4356-pcie.txt',
50 'brcm/brcmfmac4371-pcie.bin',
51 'brcm/brcmfmac4371-pcie.txt',
52 'intel/eve-only-ibt-hw-37.8.10-fw-22.50.19.14.f.bseq',
53 'intel/fw_sst_0f28.bin',
54 'intel/fw_sst_0f28.bin-48kHz_i2s_master',
55 'intel/fw_sst_0f28.bin-i2s_master',
56 'intel/fw_sst_0f28.bin-i2s_slave',
57 'intel/fw_sst_0f28.bin-tdm_master',
58 'intel/fw_sst_0f28.bin-tdm_slave',
59 'intel/ibt-19-0-0.ddc',
60 'intel/ibt-19-0-0.sfi',
61 'intel/ibt-19-0-1.ddc',
62 'intel/ibt-19-0-1.sfi',
Brian Norris2bd383d2020-02-28 17:47:31 -080063 'iwlwifi-9000-pu-b0-jf-b0-43.ucode',
64 'iwlwifi-9000-pu-b0-jf-b0-46.ucode',
65 'iwlwifi-9260-th-b0-jf-b0-41.ucode',
66 'iwlwifi-9260-th-b0-jf-b0-43.ucode',
67 'iwlwifi-9260-th-b0-jf-b0-46.ucode',
68 'iwlwifi-Qu-b0-jf-b0-43.ucode',
69 'iwlwifi-Qu-c0-hr-b0-50.ucode',
70 'iwlwifi-Qu-c0-hr-b0-53.ucode',
71 'iwlwifi-QuZ-a0-hr-b0-48.ucode',
72 'iwlwifi-QuZ-a0-hr-b0-50.ucode',
73 'iwlwifi-QuZ-a0-hr-b0-53.ucode',
74 'iwlwifi-cc-a0-46.ucode',
75 'iwlwifi-cc-a0-50.ucode',
76 'iwlwifi-cc-a0-53.ucode',
77 'qca/nvm_00440302_eu.bin',
78 'qca/nvm_00440302_i2s.bin',
79 'qca/nvm_00440302_i2s_eu.bin',
80 ])
81
Ben Hutchings746efa12016-09-18 01:44:04 +010082 known_prefixes = set(name for name in whence_list if name.endswith('/'))
83 git_files = set(list_git())
84
Brian Norris5a121472020-01-23 10:40:34 -080085 known_files |= set(['OWNERS',
86 'PRESUBMIT.cfg',
87 'README.chromium.md',
88 ])
89
Ben Hutchings746efa12016-09-18 01:44:04 +010090 for name in sorted(list(known_files - git_files)):
91 sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
Brian Norris95289452020-02-28 17:32:48 -080092 ret = 1
Ben Hutchings746efa12016-09-18 01:44:04 +010093
94 for name in sorted(list(git_files - known_files)):
95 # Ignore subdirectory changelogs and GPG detached signatures
96 if (name.endswith('/ChangeLog') or
97 (name.endswith('.asc') and name[:-4] in known_files)):
98 continue
99
100 # Ignore unknown files in known directories
101 for prefix in known_prefixes:
102 if name.startswith(prefix):
103 break
104 else:
105 sys.stderr.write('E: %s not listed in WHENCE\n' % name)
Brian Norris95289452020-02-28 17:32:48 -0800106 ret = 1
107 return ret
Ben Hutchings746efa12016-09-18 01:44:04 +0100108
109if __name__ == '__main__':
Brian Norris95289452020-02-28 17:32:48 -0800110 sys.exit(main())