diff --git a/tools/git_hooks/find_duplicates.py b/tools/git_hooks/find_duplicates.py old mode 100644 new mode 100755 index cce4475a42..9f954ac6be --- a/tools/git_hooks/find_duplicates.py +++ b/tools/git_hooks/find_duplicates.py @@ -22,25 +22,5 @@ if __name__ == "__main__": scanned_files = {} - for r in [resources] + resources.features.values(): - for file in r.c_sources + r.s_sources + r.cpp_sources + r.objects + r.libraries + r.hex_files + r.bin_files: - scanned_files.setdefault(basename(file), []) - scanned_files[basename(file)].append(file) - filenameparts = splitext(file) - if filenameparts[-1] in ["c", "cpp", "s", "S"]: - filenameparts[-1] = "o" - file = ".".join(filenamparts) - scanned_files.setdefault(basename(file), []) - scanned_files[basename(file)].append(file) - - count_dupe = 0 - for key, value in scanned_files.iteritems(): - if len(value) > 1: - count_dupe += 1 - if not args.silent: - print("Multiple files found with name {}".format(key)) - for file in value: - print(" {}".format(file)) - - exit(count_dupe) + exit(resources.detect_duplicates()) diff --git a/tools/toolchains/__init__.py b/tools/toolchains/__init__.py index 395cfee00e..162905b8f9 100644 --- a/tools/toolchains/__init__.py +++ b/tools/toolchains/__init__.py @@ -120,27 +120,35 @@ class Resources: return self - def detect_duplicates(self): - dupe_dict = dict() + def _collect_duplicates(self, dupe_dict, dupe_headers): for filename in self.s_sources + self.c_sources + self.cpp_sources: objname, _ = splitext(basename(filename)) - dupe_dict.setdefault(objname, []) - dupe_dict[objname].append(filename) + dupe_dict.setdefault(objname, set()) + dupe_dict[objname] |= set([filename]) + for filename in self.headers: + headername = basename(filename) + dupe_headers.setdefault(headername, set()) + dupe_headers[headername] |= set([headername]) + for res in self.features.values(): + res._collect_duplicates(dupe_dict, dupe_headers) + return dupe_dict, dupe_headers + + def detect_duplicates(self): + count = 0 + dupe_dict, dupe_headers = self._collect_duplicates(dict(), dict()) for objname, filenames in dupe_dict.iteritems(): if len(filenames) > 1: + count+=1 print "[ERROR] Object file %s.o is not unique!"\ " It could be made from:" % objname print columnate(filenames) - dupe_headers = dict() - for filename in self.headers: - headername = basename(filename) - dupe_headers.setdefault(headername, []) - dupe_headers[headername].append(headername) for headername, locations in dupe_headers.iteritems(): - if len(filenames) > 1: + if len(locations) > 1: + count+=1 print "[ERROR] Header file %s is not unique! It could be:" %\ headername print columnate(locations) + return count def relative_to(self, base, dot=False):