2021-10-07 00:43:44 -03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
'''
|
|
|
|
Wrapper around elf_diff (https://github.com/noseglasses/elf_diff)
|
|
|
|
to create a html report comparing an ArduPilot build across two
|
|
|
|
branches
|
|
|
|
|
|
|
|
pip3 install --user elf_diff weasyprint
|
|
|
|
|
|
|
|
AP_FLAKE8_CLEAN
|
|
|
|
|
2021-11-04 17:33:27 -03:00
|
|
|
How to use?
|
|
|
|
Starting in the ardupilot directory.
|
|
|
|
~/ardupilot $ python Tools/scripts/size_compare_branches.py --branch=[PR_BRANCH_NAME] --vehicle=copter
|
|
|
|
|
|
|
|
Output is placed into ../ELF_DIFF_[VEHICLE_NAME]
|
2021-10-07 00:43:44 -03:00
|
|
|
'''
|
|
|
|
|
2023-01-22 19:42:47 -04:00
|
|
|
import copy
|
2021-10-07 00:43:44 -03:00
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import string
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2022-11-01 20:36:20 -03:00
|
|
|
import tempfile
|
2021-10-07 00:43:44 -03:00
|
|
|
import time
|
2022-11-01 20:36:20 -03:00
|
|
|
import board_list
|
2021-10-07 00:43:44 -03:00
|
|
|
|
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
running_python3 = False
|
|
|
|
else:
|
|
|
|
running_python3 = True
|
|
|
|
|
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
class SizeCompareBranchesResult(object):
|
|
|
|
'''object to return results from a comparison'''
|
|
|
|
|
2023-01-25 18:06:13 -04:00
|
|
|
def __init__(self, board, vehicle, bytes_delta, identical):
|
2022-11-01 20:36:20 -03:00
|
|
|
self.board = board
|
|
|
|
self.vehicle = vehicle
|
|
|
|
self.bytes_delta = bytes_delta
|
2023-01-25 18:06:13 -04:00
|
|
|
self.identical = identical
|
2022-11-01 20:36:20 -03:00
|
|
|
|
|
|
|
|
2021-10-07 00:43:44 -03:00
|
|
|
class SizeCompareBranches(object):
|
|
|
|
'''script to build and compare branches using elf_diff'''
|
|
|
|
|
2022-08-11 22:03:30 -03:00
|
|
|
def __init__(self,
|
|
|
|
branch=None,
|
|
|
|
master_branch="master",
|
2022-11-01 20:36:20 -03:00
|
|
|
board=["MatekF405-Wing"],
|
|
|
|
vehicle=["plane"],
|
2022-08-11 22:03:30 -03:00
|
|
|
bin_dir=None,
|
2022-11-01 20:36:20 -03:00
|
|
|
run_elf_diff=True,
|
|
|
|
all_vehicles=False,
|
|
|
|
all_boards=False,
|
|
|
|
use_merge_base=True,
|
2023-02-15 07:20:52 -04:00
|
|
|
waf_consistent_builds=True,
|
2023-03-12 21:01:54 -03:00
|
|
|
show_empty=True,
|
2023-02-06 23:43:18 -04:00
|
|
|
extra_hwdef=[],
|
|
|
|
extra_hwdef_branch=[],
|
|
|
|
extra_hwdef_master=[]):
|
2021-10-07 00:43:44 -03:00
|
|
|
if branch is None:
|
2022-11-01 20:36:20 -03:00
|
|
|
branch = self.find_current_git_branch()
|
|
|
|
|
2021-10-07 00:43:44 -03:00
|
|
|
self.master_branch = master_branch
|
|
|
|
self.branch = branch
|
|
|
|
self.board = board
|
2021-11-04 00:15:24 -03:00
|
|
|
self.vehicle = vehicle
|
2021-10-07 00:43:44 -03:00
|
|
|
self.bin_dir = bin_dir
|
2022-11-01 20:36:20 -03:00
|
|
|
self.run_elf_diff = run_elf_diff
|
2022-08-11 22:03:30 -03:00
|
|
|
self.extra_hwdef = extra_hwdef
|
2023-02-06 23:43:18 -04:00
|
|
|
self.extra_hwdef_branch = extra_hwdef_branch
|
|
|
|
self.extra_hwdef_master = extra_hwdef_master
|
2022-11-01 20:36:20 -03:00
|
|
|
self.all_vehicles = all_vehicles
|
|
|
|
self.all_boards = all_boards
|
|
|
|
self.use_merge_base = use_merge_base
|
2023-02-15 07:20:52 -04:00
|
|
|
self.waf_consistent_builds = waf_consistent_builds
|
2023-03-12 21:01:54 -03:00
|
|
|
self.show_empty = show_empty
|
2021-10-07 00:43:44 -03:00
|
|
|
|
|
|
|
if self.bin_dir is None:
|
|
|
|
self.bin_dir = self.find_bin_dir()
|
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
self.boards_by_name = {}
|
|
|
|
for board in board_list.BoardList().boards:
|
|
|
|
self.boards_by_name[board.name] = board
|
|
|
|
|
|
|
|
# map from vehicle names to binary names
|
|
|
|
self.vehicle_map = {
|
|
|
|
"rover" : "ardurover",
|
|
|
|
"copter" : "arducopter",
|
|
|
|
"plane" : "arduplane",
|
|
|
|
"sub" : "ardusub",
|
|
|
|
"heli" : "arducopter-heli",
|
|
|
|
"blimp" : "blimp",
|
|
|
|
"antennatracker" : "antennatracker",
|
|
|
|
"AP_Periph" : "AP_Periph",
|
2023-01-22 19:42:47 -04:00
|
|
|
"bootloader": "AP_Bootloader",
|
2022-11-05 20:49:03 -03:00
|
|
|
"iofirmware": "iofirmware_highpolh", # FIXME: lowpolh?
|
2022-11-01 20:36:20 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if all_boards:
|
|
|
|
self.board = sorted(list(self.boards_by_name.keys()), key=lambda x: x.lower())
|
|
|
|
else:
|
|
|
|
# validate boards
|
|
|
|
all_boards = set(self.boards_by_name.keys())
|
|
|
|
for b in self.board:
|
|
|
|
if b not in all_boards:
|
|
|
|
raise ValueError("Bad board %s" % str(b))
|
|
|
|
|
|
|
|
if all_vehicles:
|
|
|
|
self.vehicle = sorted(list(self.vehicle_map.keys()), key=lambda x: x.lower())
|
|
|
|
else:
|
|
|
|
for v in self.vehicle:
|
|
|
|
if v not in self.vehicle_map.keys():
|
|
|
|
raise ValueError("Bad vehicle (%s); choose from %s" % (v, ",".join(self.vehicle_map.keys())))
|
|
|
|
|
2023-01-24 16:56:46 -04:00
|
|
|
# some boards we don't have a -bl.dat for, so skip them.
|
|
|
|
# TODO: find a way to get this information from board_list:
|
2023-02-15 10:04:49 -04:00
|
|
|
self.bootloader_blacklist = set([
|
|
|
|
'CubeOrange-SimOnHardWare',
|
|
|
|
'fmuv2',
|
|
|
|
'fmuv3-bdshot',
|
|
|
|
'iomcu',
|
2023-01-25 20:31:06 -04:00
|
|
|
'iomcu',
|
2023-02-15 10:04:49 -04:00
|
|
|
'iomcu_f103_8MHz',
|
|
|
|
'luminousbee4',
|
|
|
|
'skyviper-v2450',
|
|
|
|
'skyviper-f412-rev1',
|
|
|
|
'skyviper-journey',
|
|
|
|
'Pixhawk1-1M-bdshot',
|
|
|
|
'SITL_arm_linux_gnueabihf',
|
2023-01-24 16:56:46 -04:00
|
|
|
])
|
|
|
|
|
2023-02-15 10:04:49 -04:00
|
|
|
# blacklist all linux boards for bootloader build:
|
|
|
|
self.bootloader_blacklist.update(self.linux_board_names())
|
|
|
|
# ... and esp32 boards:
|
|
|
|
self.bootloader_blacklist.update(self.esp32_board_names())
|
|
|
|
|
|
|
|
def linux_board_names(self):
|
|
|
|
'''return a list of all Linux board names; FIXME: get this dynamically'''
|
|
|
|
# grep 'class.*[(]linux' Tools/ardupilotwaf/boards.py | perl -pe "s/class (.*)\(linux\).*/ '\\1',/"
|
|
|
|
return [
|
|
|
|
'navigator',
|
|
|
|
'erleboard',
|
|
|
|
'navio',
|
|
|
|
'navio2',
|
|
|
|
'edge',
|
|
|
|
'zynq',
|
|
|
|
'ocpoc_zynq',
|
|
|
|
'bbbmini',
|
|
|
|
'blue',
|
|
|
|
'pocket',
|
|
|
|
'pxf',
|
|
|
|
'bebop',
|
|
|
|
'vnav',
|
|
|
|
'disco',
|
|
|
|
'erlebrain2',
|
|
|
|
'bhat',
|
|
|
|
'dark',
|
|
|
|
'pxfmini',
|
|
|
|
'aero',
|
|
|
|
'rst_zynq',
|
|
|
|
'obal',
|
|
|
|
'SITL_x86_64_linux_gnu',
|
|
|
|
]
|
|
|
|
|
|
|
|
def esp32_board_names(self):
|
|
|
|
return [
|
|
|
|
'esp32buzz',
|
|
|
|
'esp32empty',
|
|
|
|
'esp32icarous',
|
|
|
|
'esp32diy',
|
|
|
|
]
|
|
|
|
|
2021-10-07 00:43:44 -03:00
|
|
|
def find_bin_dir(self):
|
|
|
|
'''attempt to find where the arm-none-eabi tools are'''
|
|
|
|
binary = shutil.which("arm-none-eabi-g++")
|
|
|
|
if binary is None:
|
|
|
|
raise Exception("No arm-none-eabi-g++?")
|
|
|
|
return os.path.dirname(binary)
|
|
|
|
|
|
|
|
# vast amounts of stuff copied into here from build_binaries.py
|
|
|
|
|
|
|
|
def run_program(self, prefix, cmd_list, show_output=True, env=None):
|
|
|
|
if show_output:
|
|
|
|
self.progress("Running (%s)" % " ".join(cmd_list))
|
2022-11-02 00:09:30 -03:00
|
|
|
p = subprocess.Popen(
|
|
|
|
cmd_list,
|
|
|
|
stdin=None,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
close_fds=True,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
env=env)
|
2021-10-07 00:43:44 -03:00
|
|
|
output = ""
|
|
|
|
while True:
|
|
|
|
x = p.stdout.readline()
|
|
|
|
if len(x) == 0:
|
|
|
|
returncode = os.waitpid(p.pid, 0)
|
|
|
|
if returncode:
|
|
|
|
break
|
|
|
|
# select not available on Windows... probably...
|
|
|
|
time.sleep(0.1)
|
|
|
|
continue
|
|
|
|
if running_python3:
|
|
|
|
x = bytearray(x)
|
|
|
|
x = filter(lambda x : chr(x) in string.printable, x)
|
|
|
|
x = "".join([chr(c) for c in x])
|
|
|
|
output += x
|
|
|
|
x = x.rstrip()
|
|
|
|
if show_output:
|
|
|
|
print("%s: %s" % (prefix, x))
|
|
|
|
(_, status) = returncode
|
2023-02-08 23:45:12 -04:00
|
|
|
if status != 0:
|
2021-10-07 00:43:44 -03:00
|
|
|
self.progress("Process failed (%s)" %
|
|
|
|
str(returncode))
|
|
|
|
raise subprocess.CalledProcessError(
|
|
|
|
returncode, cmd_list)
|
|
|
|
return output
|
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
def find_current_git_branch(self):
|
|
|
|
output = self.run_git(["symbolic-ref", "--short", "HEAD"])
|
|
|
|
output = output.strip()
|
|
|
|
return output
|
|
|
|
|
|
|
|
def find_git_branch_merge_base(self, branch, master_branch):
|
|
|
|
output = self.run_git(["merge-base", branch, master_branch])
|
|
|
|
output = output.strip()
|
|
|
|
return output
|
|
|
|
|
2021-10-07 00:43:44 -03:00
|
|
|
def run_git(self, args):
|
|
|
|
'''run git with args git_args; returns git's output'''
|
|
|
|
cmd_list = ["git"]
|
|
|
|
cmd_list.extend(args)
|
|
|
|
return self.run_program("SCB-GIT", cmd_list)
|
|
|
|
|
|
|
|
def run_waf(self, args, compiler=None):
|
2022-11-04 04:23:23 -03:00
|
|
|
# try to modify the environment so we can consistent builds:
|
|
|
|
consistent_build_envs = {
|
|
|
|
"CHIBIOS_GIT_VERSION": "12345678",
|
|
|
|
"GIT_VERSION": "abcdef",
|
|
|
|
"GIT_VERSION_INT": "15",
|
|
|
|
}
|
|
|
|
for (n, v) in consistent_build_envs.items():
|
|
|
|
os.environ[n] = v
|
|
|
|
|
2021-10-07 00:43:44 -03:00
|
|
|
if os.path.exists("waf"):
|
|
|
|
waf = "./waf"
|
|
|
|
else:
|
|
|
|
waf = os.path.join(".", "modules", "waf", "waf-light")
|
|
|
|
cmd_list = [waf]
|
|
|
|
cmd_list.extend(args)
|
|
|
|
env = None
|
|
|
|
if compiler is not None:
|
|
|
|
# default to $HOME/arm-gcc, but allow for any path with AP_GCC_HOME environment variable
|
|
|
|
gcc_home = os.environ.get("AP_GCC_HOME", os.path.join(os.environ["HOME"], "arm-gcc"))
|
|
|
|
gcc_path = os.path.join(gcc_home, compiler, "bin")
|
|
|
|
if os.path.exists(gcc_path):
|
|
|
|
# setup PATH to point at the right compiler, and setup to use ccache
|
|
|
|
env = os.environ.copy()
|
|
|
|
env["PATH"] = gcc_path + ":" + env["PATH"]
|
|
|
|
env["CC"] = "ccache arm-none-eabi-gcc"
|
|
|
|
env["CXX"] = "ccache arm-none-eabi-g++"
|
|
|
|
else:
|
|
|
|
raise Exception("BB-WAF: Missing compiler %s" % gcc_path)
|
|
|
|
self.run_program("SCB-WAF", cmd_list, env=env)
|
|
|
|
|
|
|
|
def progress(self, string):
|
|
|
|
'''pretty-print progress'''
|
|
|
|
print("SCB: %s" % string)
|
|
|
|
|
2023-02-06 23:43:18 -04:00
|
|
|
def build_branch_into_dir(self, board, branch, vehicle, outdir, extra_hwdef=None):
|
2021-10-07 00:43:44 -03:00
|
|
|
self.run_git(["checkout", branch])
|
|
|
|
self.run_git(["submodule", "update", "--recursive"])
|
|
|
|
shutil.rmtree("build", ignore_errors=True)
|
2022-08-11 22:03:30 -03:00
|
|
|
waf_configure_args = ["configure", "--board", board]
|
2023-02-15 07:20:52 -04:00
|
|
|
if self.waf_consistent_builds:
|
|
|
|
waf_configure_args.append("--consistent-builds")
|
2023-02-06 23:43:18 -04:00
|
|
|
|
|
|
|
if extra_hwdef is not None:
|
|
|
|
waf_configure_args.extend(["--extra-hwdef", extra_hwdef])
|
|
|
|
|
2022-08-11 22:03:30 -03:00
|
|
|
self.run_waf(waf_configure_args)
|
2022-11-01 20:36:20 -03:00
|
|
|
# we can't run `./waf copter blimp plane` without error, so do
|
|
|
|
# them one-at-a-time:
|
|
|
|
for v in vehicle:
|
2023-01-22 19:42:47 -04:00
|
|
|
if v == 'bootloader':
|
|
|
|
# need special configuration directive
|
|
|
|
continue
|
|
|
|
self.run_waf([v])
|
|
|
|
for v in vehicle:
|
|
|
|
if v != 'bootloader':
|
|
|
|
continue
|
2023-01-24 16:56:46 -04:00
|
|
|
if board in self.bootloader_blacklist:
|
|
|
|
continue
|
2023-01-22 19:42:47 -04:00
|
|
|
# need special configuration directive
|
|
|
|
bootloader_waf_configure_args = copy.copy(waf_configure_args)
|
|
|
|
bootloader_waf_configure_args.append('--bootloader')
|
|
|
|
self.run_waf(bootloader_waf_configure_args)
|
2022-11-01 20:36:20 -03:00
|
|
|
self.run_waf([v])
|
2023-01-22 19:42:47 -04:00
|
|
|
self.run_program("rsync", ["rsync", "-aP", "build/", outdir])
|
2022-11-01 20:36:20 -03:00
|
|
|
|
|
|
|
def run_all(self):
|
|
|
|
'''run tests for boards and vehicles passed in constructor'''
|
|
|
|
|
|
|
|
results = {}
|
|
|
|
for board in self.board:
|
|
|
|
vehicle_results = self.run_board(board)
|
|
|
|
results[board] = vehicle_results
|
|
|
|
with open("/tmp/some.csv", "w") as f:
|
|
|
|
f.write(self.csv_for_results(results))
|
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
def emit_csv_for_results(self, results):
|
|
|
|
'''emit dictionary of dictionaries as a CSV'''
|
|
|
|
print(self.csv_for_results(results))
|
|
|
|
|
|
|
|
def csv_for_results(self, results):
|
|
|
|
'''return a string with csv for results'''
|
|
|
|
boards = sorted(results.keys())
|
|
|
|
all_vehicles = set()
|
|
|
|
for board in boards:
|
|
|
|
all_vehicles.update(list(results[board].keys()))
|
|
|
|
sorted_all_vehicles = sorted(list(all_vehicles))
|
|
|
|
ret = ""
|
|
|
|
ret += ",".join(["Board"] + sorted_all_vehicles) + "\n"
|
|
|
|
for board in boards:
|
|
|
|
line = [board]
|
|
|
|
board_results = results[board]
|
|
|
|
for vehicle in sorted_all_vehicles:
|
|
|
|
bytes_delta = ""
|
|
|
|
if vehicle in board_results:
|
|
|
|
result = board_results[vehicle]
|
2023-01-25 18:06:13 -04:00
|
|
|
if result.identical:
|
|
|
|
bytes_delta = "*"
|
|
|
|
else:
|
|
|
|
bytes_delta = result.bytes_delta
|
2022-11-01 20:36:20 -03:00
|
|
|
line.append(str(bytes_delta))
|
2023-03-12 21:01:54 -03:00
|
|
|
# do not add to ret value if we're not showing empty results:
|
|
|
|
if not self.show_empty:
|
|
|
|
if len(list(filter(lambda x : x != "", line[1:]))) == 0:
|
|
|
|
continue
|
2022-11-01 20:36:20 -03:00
|
|
|
ret += ",".join(line) + "\n"
|
|
|
|
return ret
|
2021-10-07 00:43:44 -03:00
|
|
|
|
|
|
|
def run(self):
|
2022-11-01 20:36:20 -03:00
|
|
|
results = self.run_all()
|
|
|
|
self.emit_csv_for_results(results)
|
2021-10-07 00:43:44 -03:00
|
|
|
|
2023-01-25 18:06:13 -04:00
|
|
|
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()
|
|
|
|
|
2023-02-06 23:43:18 -04:00
|
|
|
def extra_hwdef_file(self, more):
|
|
|
|
# create a combined list of hwdefs:
|
|
|
|
extra_hwdefs = []
|
|
|
|
extra_hwdefs.extend(self.extra_hwdef)
|
|
|
|
extra_hwdefs.extend(more)
|
|
|
|
extra_hwdefs = list(filter(lambda x : x is not None, extra_hwdefs))
|
|
|
|
if len(extra_hwdefs) == 0:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# slurp all content into a variable:
|
|
|
|
content = bytearray()
|
|
|
|
for extra_hwdef in extra_hwdefs:
|
|
|
|
with open(extra_hwdef, "r+b") as f:
|
|
|
|
content += f.read()
|
|
|
|
|
|
|
|
# spew content to single file:
|
|
|
|
f = tempfile.NamedTemporaryFile(delete=False)
|
|
|
|
f.write(content)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
return f.name
|
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
def run_board(self, board):
|
|
|
|
ret = {}
|
|
|
|
board_info = self.boards_by_name[board]
|
2021-10-07 00:43:44 -03:00
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
vehicles_to_build = []
|
|
|
|
for vehicle in self.vehicle:
|
|
|
|
if vehicle == 'AP_Periph':
|
|
|
|
if not board_info.is_ap_periph:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if board_info.is_ap_periph:
|
|
|
|
continue
|
2023-01-22 19:42:47 -04:00
|
|
|
# the bootloader target isn't an autobuild target, so
|
|
|
|
# it gets special treatment here:
|
|
|
|
if vehicle != 'bootloader' and vehicle.lower() not in [x.lower() for x in board_info.autobuild_targets]:
|
2022-11-01 20:36:20 -03:00
|
|
|
continue
|
|
|
|
vehicles_to_build.append(vehicle)
|
|
|
|
if len(vehicles_to_build) == 0:
|
|
|
|
return ret
|
2021-10-07 00:43:44 -03:00
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
tmpdir = tempfile.mkdtemp()
|
|
|
|
outdir_1 = os.path.join(tmpdir, "out-master-%s" % (board,))
|
|
|
|
outdir_2 = os.path.join(tmpdir, "out-branch-%s" % (board,))
|
|
|
|
|
|
|
|
self.progress("Building branch 1 (%s)" % self.master_branch)
|
|
|
|
master_commit = self.master_branch
|
|
|
|
if self.use_merge_base:
|
|
|
|
master_commit = self.find_git_branch_merge_base(self.branch, self.master_branch)
|
|
|
|
self.progress("Using merge base (%s)" % master_commit)
|
|
|
|
shutil.rmtree(outdir_1, ignore_errors=True)
|
2023-02-06 23:43:18 -04:00
|
|
|
|
|
|
|
self.build_branch_into_dir(
|
|
|
|
board,
|
|
|
|
master_commit,
|
|
|
|
vehicles_to_build,
|
|
|
|
outdir_1,
|
|
|
|
extra_hwdef=self.extra_hwdef_file(self.extra_hwdef_master)
|
|
|
|
)
|
2022-11-01 20:36:20 -03:00
|
|
|
|
|
|
|
self.progress("Building branch 2 (%s)" % self.branch)
|
|
|
|
shutil.rmtree(outdir_2, ignore_errors=True)
|
2023-02-06 23:43:18 -04:00
|
|
|
self.build_branch_into_dir(
|
|
|
|
board,
|
|
|
|
self.branch,
|
|
|
|
vehicles_to_build,
|
|
|
|
outdir_2,
|
|
|
|
self.extra_hwdef_file(self.extra_hwdef_branch)
|
|
|
|
)
|
2022-11-01 20:36:20 -03:00
|
|
|
|
|
|
|
for vehicle in vehicles_to_build:
|
2023-01-24 16:56:46 -04:00
|
|
|
if vehicle == 'bootloader' and board in self.bootloader_blacklist:
|
|
|
|
continue
|
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
elf_filename = self.vehicle_map[vehicle]
|
|
|
|
bin_filename = self.vehicle_map[vehicle] + '.bin'
|
|
|
|
|
|
|
|
if self.run_elf_diff:
|
2023-02-15 20:50:25 -04:00
|
|
|
master_elf_dirname = "bin"
|
|
|
|
new_elf_dirname = "bin"
|
|
|
|
if vehicle == 'bootloader':
|
|
|
|
# elfs for bootloaders are in the bootloader directory...
|
|
|
|
master_elf_dirname = "bootloader"
|
|
|
|
new_elf_dirname = "bootloader"
|
|
|
|
master_elf_dir = os.path.join(outdir_1, board, master_elf_dirname)
|
|
|
|
new_elf_dir = os.path.join(outdir_2, board, new_elf_dirname)
|
2022-11-01 20:36:20 -03:00
|
|
|
self.progress("Starting compare (~10 minutes!)")
|
|
|
|
elf_diff_commandline = [
|
|
|
|
"time",
|
|
|
|
"python3",
|
|
|
|
"-m", "elf_diff",
|
|
|
|
"--bin_dir", self.bin_dir,
|
|
|
|
'--bin_prefix=arm-none-eabi-',
|
|
|
|
"--old_alias", "%s %s" % (self.master_branch, elf_filename),
|
|
|
|
"--new_alias", "%s %s" % (self.branch, elf_filename),
|
|
|
|
"--html_dir", "../ELF_DIFF_%s_%s" % (board, vehicle),
|
2023-02-15 20:50:25 -04:00
|
|
|
os.path.join(master_elf_dir, elf_filename),
|
|
|
|
os.path.join(new_elf_dir, elf_filename)
|
2022-11-01 20:36:20 -03:00
|
|
|
]
|
|
|
|
|
|
|
|
self.run_program("SCB", elf_diff_commandline)
|
2021-10-07 00:43:44 -03:00
|
|
|
|
2023-02-15 20:50:25 -04:00
|
|
|
master_bin_dir = os.path.join(outdir_1, board, "bin")
|
|
|
|
new_bin_dir = os.path.join(outdir_2, board, "bin")
|
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
try:
|
2023-01-25 18:06:13 -04:00
|
|
|
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)
|
2022-11-01 20:36:20 -03:00
|
|
|
except FileNotFoundError:
|
2023-01-25 18:06:13 -04:00
|
|
|
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)
|
|
|
|
|
|
|
|
identical = self.files_are_identical(master_path, new_path)
|
2021-10-07 00:43:44 -03:00
|
|
|
|
2023-01-25 18:06:13 -04:00
|
|
|
ret[vehicle] = SizeCompareBranchesResult(board, vehicle, new_size - master_size, identical)
|
2021-10-07 00:43:44 -03:00
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
return ret
|
2021-10-07 00:43:44 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = optparse.OptionParser("size_compare_branches.py")
|
2022-11-01 20:36:20 -03:00
|
|
|
parser.add_option("",
|
2023-03-08 21:27:29 -04:00
|
|
|
"--elf-diff",
|
2022-11-01 20:36:20 -03:00
|
|
|
action="store_true",
|
|
|
|
default=False,
|
2023-03-08 21:27:29 -04:00
|
|
|
help="run elf_diff on output files")
|
2021-10-07 00:43:44 -03:00
|
|
|
parser.add_option("",
|
|
|
|
"--master-branch",
|
|
|
|
type="string",
|
|
|
|
default="master",
|
|
|
|
help="master branch to use")
|
2022-12-22 18:12:59 -04:00
|
|
|
parser.add_option("",
|
|
|
|
"--no-merge-base",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="do not use the merge-base for testing, do a direct comparison between branches")
|
2023-02-15 07:20:52 -04:00
|
|
|
parser.add_option("",
|
|
|
|
"--no-waf-consistent-builds",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="do not use the --consistent-builds waf command-line option (for older branches)")
|
2021-10-07 00:43:44 -03:00
|
|
|
parser.add_option("",
|
|
|
|
"--branch",
|
|
|
|
type="string",
|
|
|
|
default=None,
|
|
|
|
help="branch to compare")
|
2021-11-04 00:15:24 -03:00
|
|
|
parser.add_option("",
|
|
|
|
"--vehicle",
|
2022-11-01 20:36:20 -03:00
|
|
|
action='append',
|
|
|
|
default=[],
|
2021-11-04 00:15:24 -03:00
|
|
|
help="vehicle to build for")
|
2023-03-12 21:01:54 -03:00
|
|
|
parser.add_option("",
|
|
|
|
"--show-empty",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Show result lines even if no builds were done for the board")
|
2021-10-07 00:43:44 -03:00
|
|
|
parser.add_option("",
|
|
|
|
"--board",
|
2022-11-01 20:36:20 -03:00
|
|
|
action='append',
|
|
|
|
default=[],
|
2021-10-07 00:43:44 -03:00
|
|
|
help="board to build for")
|
2022-08-11 22:03:30 -03:00
|
|
|
parser.add_option("",
|
|
|
|
"--extra-hwdef",
|
2023-02-06 23:43:18 -04:00
|
|
|
default=[],
|
|
|
|
action="append",
|
2022-08-11 22:03:30 -03:00
|
|
|
help="configure with this extra hwdef file")
|
2023-02-06 23:43:18 -04:00
|
|
|
parser.add_option("",
|
|
|
|
"--extra-hwdef-branch",
|
|
|
|
default=[],
|
|
|
|
action="append",
|
|
|
|
help="configure with this extra hwdef file only on new branch")
|
|
|
|
parser.add_option("",
|
|
|
|
"--extra-hwdef-master",
|
|
|
|
default=[],
|
|
|
|
action="append",
|
|
|
|
help="configure with this extra hwdef file only on merge/master branch")
|
2022-11-01 20:36:20 -03:00
|
|
|
parser.add_option("",
|
|
|
|
"--all-boards",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Build all boards")
|
|
|
|
parser.add_option("",
|
|
|
|
"--all-vehicles",
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Build all vehicles")
|
2021-10-07 00:43:44 -03:00
|
|
|
cmd_opts, cmd_args = parser.parse_args()
|
|
|
|
|
2022-11-01 20:36:20 -03:00
|
|
|
vehicle = []
|
|
|
|
for v in cmd_opts.vehicle:
|
|
|
|
vehicle.extend(v.split(','))
|
|
|
|
if len(vehicle) == 0:
|
|
|
|
vehicle.append("plane")
|
|
|
|
|
|
|
|
board = []
|
|
|
|
for b in cmd_opts.board:
|
|
|
|
board.extend(b.split(','))
|
|
|
|
if len(board) == 0:
|
|
|
|
board.append("MatekF405-Wing")
|
2021-10-07 00:43:44 -03:00
|
|
|
|
|
|
|
x = SizeCompareBranches(
|
|
|
|
branch=cmd_opts.branch,
|
|
|
|
master_branch=cmd_opts.master_branch,
|
2022-11-01 20:36:20 -03:00
|
|
|
board=board,
|
|
|
|
vehicle=vehicle,
|
2022-08-11 22:03:30 -03:00
|
|
|
extra_hwdef=cmd_opts.extra_hwdef,
|
2023-02-06 23:43:18 -04:00
|
|
|
extra_hwdef_branch=cmd_opts.extra_hwdef_branch,
|
|
|
|
extra_hwdef_master=cmd_opts.extra_hwdef_master,
|
2023-03-08 21:27:29 -04:00
|
|
|
run_elf_diff=(cmd_opts.elf_diff),
|
2022-11-01 20:36:20 -03:00
|
|
|
all_vehicles=cmd_opts.all_vehicles,
|
|
|
|
all_boards=cmd_opts.all_boards,
|
2022-12-22 18:12:59 -04:00
|
|
|
use_merge_base=not cmd_opts.no_merge_base,
|
2023-02-15 07:20:52 -04:00
|
|
|
waf_consistent_builds=not cmd_opts.no_waf_consistent_builds,
|
2023-03-12 21:01:54 -03:00
|
|
|
show_empty=cmd_opts.show_empty,
|
2021-10-07 00:43:44 -03:00
|
|
|
)
|
|
|
|
x.run()
|