PVS: V547 Expression 'pOldSelFly' is always true.
[LibreOffice.git] / bin / find-headers-to-move-inside-modules.py
blob10efd4bf12b79908100c277f999a91eeff29f92a
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:
14 continue
15 if header == b"version.hrc":
16 continue
17 # ignore URE headers
18 if header.startswith(b"IwyuFilter_include.yaml"):
19 continue
20 if header.startswith(b"cppu/"):
21 continue
22 if header.startswith(b"cppuhelper/"):
23 continue
24 if header.startswith(b"osl/"):
25 continue
26 if header.startswith(b"sal/"):
27 continue
28 if header.startswith(b"salhelper/"):
29 continue
30 if header.startswith(b"uno/"):
31 continue
32 headerSet.add(header)
34 headerSetUnused = headerSet.copy()
35 headerSetOnlyInOwnModule = headerSet.copy()
36 a = subprocess.Popen("git grep '^#include <'", stdout=subprocess.PIPE, shell=True)
37 with a.stdout as txt:
38 for line in txt:
39 idx1 = line.find(b"#include <")
40 idx2 = line.find(b">", idx1 + 10)
41 include = line[idx1 + 10 : idx2]
42 headerSetUnused.discard(include)
44 idx1 = line.find(b"/")
45 includedFromModule = line[0 : idx1]
46 idx1 = include.find(b"/")
47 module = include[0 : idx1]
48 if module != includedFromModule:
49 headerSetOnlyInOwnModule.discard(include)
51 print("completely unused")
52 print("----------------------------")
53 for x in sorted(headerSetUnused):
54 print(x)
55 print("")
56 print("only used in own module")
57 print("----------------------------")
58 for x in sorted(headerSetOnlyInOwnModule):
59 print(x)