update credits
[LibreOffice.git] / bin / find-headers-to-move-inside-modules.py
blob3ca30544a7c9a74b4509a8bb0069f8b4e488c369
1 #!/usr/bin/python3
3 # Look for headers inside include/ that can be moved into their respective modules.
4 # Not 100% accurate
6 import subprocess
8 headerSet = set()
9 a = subprocess.Popen("git ls-files include/", stdout=subprocess.PIPE, shell=True)
10 with a.stdout as txt:
11 for line in txt:
12 header = line[8:].strip()
13 if b"README" in header: continue
14 if header == b"version.hrc": continue
15 # ignore URE headers
16 if header.startswith(b"IwyuFilter_include.yaml"): continue
17 if header.startswith(b"cppu/"): continue
18 if header.startswith(b"cppuhelper/"): continue
19 if header.startswith(b"osl/"): continue
20 if header.startswith(b"sal/"): continue
21 if header.startswith(b"salhelper/"): continue
22 if header.startswith(b"uno/"): continue
23 headerSet.add(header)
25 headerSetUnused = headerSet.copy()
26 headerSetOnlyInOwnModule = headerSet.copy()
27 a = subprocess.Popen("git grep '^#include <'", stdout=subprocess.PIPE, shell=True)
28 with a.stdout as txt:
29 for line in txt:
30 idx1 = line.find(b"#include <")
31 idx2 = line.find(b">", idx1 + 10)
32 include = line[idx1 + 10 : idx2]
33 headerSetUnused.discard(include)
35 idx1 = line.find(b"/")
36 includedFromModule = line[0 : idx1]
37 idx1 = include.find(b"/")
38 module = include[0 : idx1]
39 if module != includedFromModule:
40 headerSetOnlyInOwnModule.discard(include)
42 print("completely unused")
43 print("----------------------------")
44 for x in sorted(headerSetUnused):
45 print(x)
46 print("")
47 print("only used in own module")
48 print("----------------------------")
49 for x in sorted(headerSetOnlyInOwnModule):
50 print(x)