Skip to content

Commit 755ab29

Browse files
committed
Add script to find identical LLVM binary files.
1 parent 97bb9ce commit 755ab29

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

llvm/.pylintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# pylint --generate-rcfile
2+
# https://pylint.pycqa.org/en/latest/
3+
4+
[MESSAGES CONTROL]
5+
disable=
6+
bad-indentation,
7+
invalid-name,
8+
line-too-long,
9+
missing-docstring,
10+
unused-wildcard-import,
11+
12+
[TYPECHECK]
13+
ignored-modules=unicodedata

llvm/FindSameFile.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import sys
2+
import os.path
3+
4+
def get_exe_file_list(file_size_map, root, path):
5+
folder = os.path.join(root, path)
6+
if not os.path.isdir(folder):
7+
return
8+
items = os.listdir(folder)
9+
for name in items:
10+
if name.startswith('api-ms'):
11+
continue
12+
ext = os.path.splitext(name)[1].lower()
13+
if ext not in ('.exe', '.dll', '.pyd'):
14+
continue
15+
path = os.path.join(folder, name)
16+
size = os.path.getsize(path)
17+
if size in file_size_map:
18+
file_size_map[size].append(path)
19+
else:
20+
file_size_map[size] = [path]
21+
22+
def cmp_file_list(items):
23+
path = items.pop(0)
24+
with open(path, 'rb') as fd:
25+
content = fd.read()
26+
same = [path]
27+
index = 0
28+
while index < len(items):
29+
path = items[index]
30+
index += 1
31+
with open(path, 'rb') as fd:
32+
doc = fd.read()
33+
if content == doc:
34+
index -= 1
35+
items.pop(index)
36+
same.append(path)
37+
if len(same) > 1:
38+
print('same file:', '\n\t'.join(same))
39+
40+
def find_same_file(root):
41+
file_size_map = {} # file size => [path list]
42+
get_exe_file_list(file_size_map, root, 'bin')
43+
get_exe_file_list(file_size_map, root, r'lib\site-packages\lldb')
44+
for items in file_size_map.values():
45+
while len(items) > 1:
46+
cmp_file_list(items)
47+
48+
if __name__ == '__main__':
49+
if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]):
50+
find_same_file(sys.argv[1])
51+
else:
52+
print(f'Usage: {sys.argv[0]} LLVM folder')

0 commit comments

Comments
 (0)