mirror of https://github.com/ArduPilot/ardupilot
test_build_options.py: emit size savings from disabling features
This commit is contained in:
parent
3ad10d7077
commit
c27e3f0c35
|
@ -15,6 +15,9 @@ from pysim import util
|
||||||
|
|
||||||
|
|
||||||
class TestBuildOptions(object):
|
class TestBuildOptions(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.sizes_nothing_disabled = None
|
||||||
|
|
||||||
# swiped from app.py:
|
# swiped from app.py:
|
||||||
def get_build_options_from_ardupilot_tree(self):
|
def get_build_options_from_ardupilot_tree(self):
|
||||||
'''return a list of build options'''
|
'''return a list of build options'''
|
||||||
|
@ -51,24 +54,53 @@ class TestBuildOptions(object):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def test_feature(self, feature, options):
|
def test_feature(self, feature, options):
|
||||||
defines = self.get_defines(feature, options)
|
# defines = self.get_defines(feature, options)
|
||||||
|
defines = {
|
||||||
|
feature.define: 0,
|
||||||
|
}
|
||||||
self.test_compile_with_defines(defines)
|
self.test_compile_with_defines(defines)
|
||||||
|
|
||||||
|
def build_targets(self):
|
||||||
|
'''return a list of build targets'''
|
||||||
|
return ['copter', 'plane', 'rover', 'antennatracker', 'sub', 'blimp']
|
||||||
|
|
||||||
|
def board(self):
|
||||||
|
'''returns board to build for'''
|
||||||
|
return "CubeOrange"
|
||||||
|
|
||||||
def test_compile_with_defines(self, defines):
|
def test_compile_with_defines(self, defines):
|
||||||
extra_hwdef_filepath = "/tmp/extra.hwdef"
|
extra_hwdef_filepath = "/tmp/extra.hwdef"
|
||||||
self.write_defines_to_file(defines, extra_hwdef_filepath)
|
self.write_defines_to_file(defines, extra_hwdef_filepath)
|
||||||
util.waf_configure(
|
util.waf_configure(
|
||||||
"CubeOrange",
|
self.board(),
|
||||||
extra_hwdef=extra_hwdef_filepath,
|
extra_hwdef=extra_hwdef_filepath,
|
||||||
)
|
)
|
||||||
for t in 'copter', 'plane', 'rover', 'antennatracker', 'sub', 'blimp':
|
for t in self.build_targets():
|
||||||
try:
|
try:
|
||||||
util.waf_build(t)
|
util.run_cmd([util.relwaf(), t])
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Failed to build (%s) with everything disabled" %
|
print("Failed to build (%s) with things disabled" %
|
||||||
(t,))
|
(t,))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def find_build_sizes(self):
|
||||||
|
'''returns a hash with size of all build targets'''
|
||||||
|
ret = {}
|
||||||
|
target_to_binpath = {
|
||||||
|
"copter": "arducopter",
|
||||||
|
}
|
||||||
|
for target in self.build_targets():
|
||||||
|
path = os.path.join("build", self.board(), "bin", "%s.bin" % target_to_binpath[target])
|
||||||
|
ret[target] = os.path.getsize(path)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def disable_in_turn_check_sizes(self, feature, sizes_nothing_disabled):
|
||||||
|
current_sizes = self.find_build_sizes()
|
||||||
|
for (build, new_size) in current_sizes.items():
|
||||||
|
old_size = sizes_nothing_disabled[build]
|
||||||
|
print("Disabling %s(%s) on %s saves %u bytes" %
|
||||||
|
(feature.label, feature.define, build, old_size - new_size))
|
||||||
|
|
||||||
def run_disable_in_turn(self):
|
def run_disable_in_turn(self):
|
||||||
options = self.get_build_options_from_ardupilot_tree()
|
options = self.get_build_options_from_ardupilot_tree()
|
||||||
count = 1
|
count = 1
|
||||||
|
@ -77,6 +109,7 @@ class TestBuildOptions(object):
|
||||||
(feature.label, feature.define, count, len(options)))
|
(feature.label, feature.define, count, len(options)))
|
||||||
self.test_feature(feature, options)
|
self.test_feature(feature, options)
|
||||||
count += 1
|
count += 1
|
||||||
|
self.disable_in_turn_check_sizes(feature, self.sizes_nothing_disabled)
|
||||||
|
|
||||||
def run_disable_all(self):
|
def run_disable_all(self):
|
||||||
options = self.get_build_options_from_ardupilot_tree()
|
options = self.get_build_options_from_ardupilot_tree()
|
||||||
|
@ -85,8 +118,13 @@ class TestBuildOptions(object):
|
||||||
defines[feature.define] = 0
|
defines[feature.define] = 0
|
||||||
self.test_compile_with_defines(defines)
|
self.test_compile_with_defines(defines)
|
||||||
|
|
||||||
|
def run_disable_none(self):
|
||||||
|
self.test_compile_with_defines({})
|
||||||
|
self.sizes_nothing_disabled = self.find_build_sizes()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.run_disable_all()
|
self.run_disable_all()
|
||||||
|
self.run_disable_none()
|
||||||
self.run_disable_in_turn()
|
self.run_disable_in_turn()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue