Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import os, re, sys |
Brian Norris | df6c2a4 | 2020-02-28 18:15:05 -0800 | [diff] [blame] | 4 | from io import open |
Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 5 | |
| 6 | def list_whence(): |
Brian Norris | df6c2a4 | 2020-02-28 18:15:05 -0800 | [diff] [blame] | 7 | with open('WHENCE', encoding='utf-8') as whence: |
Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 8 | for line in whence: |
Thierry Reding | 016a2ec | 2019-09-30 13:17:04 +0200 | [diff] [blame] | 9 | match = re.match(r'(?:File|Source):\s*"(.*)"', line) |
Hans de Goede | 026bbcf | 2018-12-13 17:35:11 +0100 | [diff] [blame] | 10 | if match: |
| 11 | yield match.group(1) |
| 12 | continue |
Thierry Reding | 016a2ec | 2019-09-30 13:17:04 +0200 | [diff] [blame] | 13 | match = re.match(r'(?:File|Source):\s*(\S*)', line) |
Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 14 | 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 | |
| 31 | def list_git(): |
| 32 | with os.popen('git ls-files') as git_files: |
| 33 | for line in git_files: |
| 34 | yield line.rstrip('\n') |
| 35 | |
| 36 | def main(): |
Brian Norris | 9528945 | 2020-02-28 17:32:48 -0800 | [diff] [blame] | 37 | ret = 0 |
Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 38 | 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 Boyer | 95d22ac | 2019-08-21 08:03:43 -0400 | [diff] [blame] | 41 | 'README', 'copy-firmware.sh', 'WHENCE']) |
Brian Norris | 2bd383d | 2020-02-28 17:47:31 -0800 | [diff] [blame] | 42 | |
| 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 Norris | 2bd383d | 2020-02-28 17:47:31 -0800 | [diff] [blame] | 63 | '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 Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 82 | known_prefixes = set(name for name in whence_list if name.endswith('/')) |
| 83 | git_files = set(list_git()) |
| 84 | |
Brian Norris | 5a12147 | 2020-01-23 10:40:34 -0800 | [diff] [blame] | 85 | known_files |= set(['OWNERS', |
| 86 | 'PRESUBMIT.cfg', |
| 87 | 'README.chromium.md', |
| 88 | ]) |
| 89 | |
Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 90 | for name in sorted(list(known_files - git_files)): |
| 91 | sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name) |
Brian Norris | 9528945 | 2020-02-28 17:32:48 -0800 | [diff] [blame] | 92 | ret = 1 |
Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 93 | |
| 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 Norris | 9528945 | 2020-02-28 17:32:48 -0800 | [diff] [blame] | 106 | ret = 1 |
| 107 | return ret |
Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 108 | |
| 109 | if __name__ == '__main__': |
Brian Norris | 9528945 | 2020-02-28 17:32:48 -0800 | [diff] [blame] | 110 | sys.exit(main()) |