Tools: size_compare_branches.py: detect file identicality

This commit is contained in:
Peter Barker 2023-01-26 09:06:13 +11:00 committed by Peter Barker
parent cead93934d
commit b51b59008b

View File

@ -36,10 +36,11 @@ else:
class SizeCompareBranchesResult(object):
'''object to return results from a comparison'''
def __init__(self, board, vehicle, bytes_delta):
def __init__(self, board, vehicle, bytes_delta, identical):
self.board = board
self.vehicle = vehicle
self.bytes_delta = bytes_delta
self.identical = identical
class SizeCompareBranches(object):
@ -268,7 +269,10 @@ class SizeCompareBranches(object):
bytes_delta = ""
if vehicle in board_results:
result = board_results[vehicle]
bytes_delta = result.bytes_delta
if result.identical:
bytes_delta = "*"
else:
bytes_delta = result.bytes_delta
line.append(str(bytes_delta))
ret += ",".join(line) + "\n"
return ret
@ -277,6 +281,10 @@ class SizeCompareBranches(object):
results = self.run_all()
self.emit_csv_for_results(results)
def files_are_identical(self, file1, file2):
'''returns true if the files have the same content'''
return open(file1, "rb").read() == open(file2, "rb").read()
def run_board(self, board):
ret = {}
board_info = self.boards_by_name[board]
@ -341,13 +349,19 @@ class SizeCompareBranches(object):
self.run_program("SCB", elf_diff_commandline)
try:
master_size = os.path.getsize(os.path.join(master_bin_dir, bin_filename))
new_size = os.path.getsize(os.path.join(new_bin_dir, bin_filename))
master_path = os.path.join(master_bin_dir, bin_filename)
new_path = os.path.join(new_bin_dir, bin_filename)
master_size = os.path.getsize(master_path)
new_size = os.path.getsize(new_path)
except FileNotFoundError:
master_size = os.path.getsize(os.path.join(master_bin_dir, elf_filename))
new_size = os.path.getsize(os.path.join(new_bin_dir, elf_filename))
master_path = os.path.join(master_bin_dir, elf_filename)
new_path = os.path.join(new_bin_dir, elf_filename)
master_size = os.path.getsize(master_path)
new_size = os.path.getsize(new_path)
ret[vehicle] = SizeCompareBranchesResult(board, vehicle, new_size - master_size)
identical = self.files_are_identical(master_path, new_path)
ret[vehicle] = SizeCompareBranchesResult(board, vehicle, new_size - master_size, identical)
return ret