~aleteoryx/muditaos

ref: sign_test muditaos/tools/catch_duplicates.py -rwxr-xr-x 1.2 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python3
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

# Script detecting source files which are compiled twice and listing libraries where they are compiled
# Usage example: ./catch_duplicates.py ../build-rt1051-Release/compile_commands.json > what_compiles_twice.log

import sys, json

def print_duplicates(filename, occurs):
	print_duplicates.duplicate_number += 1
	print("Duplicate " + str(print_duplicates.duplicate_number) + "\n" + filename)
	for val in occurs:
		print(val)
	print("")
print_duplicates.duplicate_number = 0


def main():
	file_handle = open(sys.argv[1], "r")
	cc_dict = json.load(file_handle)
	known_files = set()

	for x in range(len(cc_dict)):
		filename1 = str(cc_dict[x]['file'])
		directory1 = str(cc_dict[x]['directory'])
		occurs = set()
		occurs.add(directory1)

		if filename1 not in known_files:

			for y in range(len(cc_dict)):
				filename2 = str(cc_dict[y]['file'])
				directory2 = str(cc_dict[y]['directory'])

				if filename1 == filename2 and x != y:
					occurs.add(directory2)

		if len(occurs) > 1:
			print_duplicates(filename1, occurs)
		
		known_files.add(filename1)

	file_handle.close()


if __name__ == '__main__':
    main()