]> git.ipfire.org Git - thirdparty/linux-firmware.git/blob - check_whence.py
amdgpu: update vega20 firmware from 19.50
[thirdparty/linux-firmware.git] / check_whence.py
1 #!/usr/bin/python
2
3 import os, re, sys
4 from io import open
5
6 def list_whence():
7 with open('WHENCE', encoding='utf-8') as whence:
8 for line in whence:
9 match = re.match(r'(?:File|Source):\s*"(.*)"', line)
10 if match:
11 yield match.group(1)
12 continue
13 match = re.match(r'(?:File|Source):\s*(\S*)', line)
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():
37 ret = 0
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',
41 'README', 'copy-firmware.sh', 'WHENCE'])
42 known_prefixes = set(name for name in whence_list if name.endswith('/'))
43 git_files = set(list_git())
44
45 for name in sorted(list(known_files - git_files)):
46 sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
47 ret = 1
48
49 for name in sorted(list(git_files - known_files)):
50 # Ignore subdirectory changelogs and GPG detached signatures
51 if (name.endswith('/ChangeLog') or
52 (name.endswith('.asc') and name[:-4] in known_files)):
53 continue
54
55 # Ignore unknown files in known directories
56 for prefix in known_prefixes:
57 if name.startswith(prefix):
58 break
59 else:
60 sys.stderr.write('E: %s not listed in WHENCE\n' % name)
61 ret = 1
62 return ret
63
64 if __name__ == '__main__':
65 sys.exit(main())