Browse Source

waf: fixed build to produce consistent binary

this ensures that optimisation levels are added regardless of whether
clean is run before or after a configure
zr-v5.1
Andrew Tridgell 5 years ago
parent
commit
9f2c689ec8
  1. 2
      Tools/ardupilotwaf/boards.py
  2. 48
      Tools/ardupilotwaf/chibios.py
  3. 3
      Tools/ardupilotwaf/embed.py

2
Tools/ardupilotwaf/boards.py

@ -585,12 +585,12 @@ class chibios(Board):
def pre_build(self, bld): def pre_build(self, bld):
'''pre-build hook that gets called before dynamic sources''' '''pre-build hook that gets called before dynamic sources'''
super(chibios, self).pre_build(bld)
from waflib.Context import load_tool from waflib.Context import load_tool
module = load_tool('chibios', [], with_sys_path=True) module = load_tool('chibios', [], with_sys_path=True)
fun = getattr(module, 'pre_build', None) fun = getattr(module, 'pre_build', None)
if fun: if fun:
fun(bld) fun(bld)
super(chibios, self).pre_build(bld)
class linux(Board): class linux(Board):
def configure_env(self, cfg, env): def configure_env(self, cfg, env):

48
Tools/ardupilotwaf/chibios.py

@ -352,38 +352,50 @@ def configure(cfg):
cfg.msg('Default parameters', cfg.options.default_parameters, color='YELLOW') cfg.msg('Default parameters', cfg.options.default_parameters, color='YELLOW')
env.DEFAULT_PARAMETERS = cfg.options.default_parameters env.DEFAULT_PARAMETERS = cfg.options.default_parameters
# we need to run chibios_hwdef.py at configure stage to generate the ldscript.ld try:
# that is needed by the remaining configure checks ret = generate_hwdef_h(env)
except Exception:
cfg.fatal("Failed to process hwdef.dat")
if ret != 0:
cfg.fatal("Failed to process hwdef.dat ret=%d" % ret)
load_env_vars(cfg.env)
if env.HAL_WITH_UAVCAN:
setup_can_build(cfg)
setup_optimization(cfg.env)
def generate_hwdef_h(env):
'''run chibios_hwdef.py'''
import subprocess import subprocess
if env.BOOTLOADER: if env.BOOTLOADER:
env.HWDEF = srcpath('libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef-bl.dat' % env.BOARD) env.HWDEF = os.path.join(env.SRCROOT, 'libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef-bl.dat' % env.BOARD)
env.BOOTLOADER_OPTION="--bootloader" env.BOOTLOADER_OPTION="--bootloader"
else: else:
env.HWDEF = srcpath('libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef.dat' % env.BOARD) env.HWDEF = os.path.join(env.SRCROOT, 'libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef.dat' % env.BOARD)
env.BOOTLOADER_OPTION="" env.BOOTLOADER_OPTION=""
hwdef_script = srcpath('libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py') hwdef_script = os.path.join(env.SRCROOT, 'libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py')
hwdef_out = env.BUILDROOT hwdef_out = env.BUILDROOT
if not os.path.exists(hwdef_out): if not os.path.exists(hwdef_out):
os.mkdir(hwdef_out) os.mkdir(hwdef_out)
python = sys.executable python = sys.executable
try: cmd = "{0} '{1}' -D '{2}' '{3}' {4} --params '{5}'".format(python, hwdef_script, hwdef_out, env.HWDEF, env.BOOTLOADER_OPTION, env.DEFAULT_PARAMETERS)
cmd = "{0} '{1}' -D '{2}' '{3}' {4} --params '{5}'".format(python, hwdef_script, hwdef_out, env.HWDEF, env.BOOTLOADER_OPTION, cfg.options.default_parameters) return subprocess.call(cmd, shell=True)
ret = subprocess.call(cmd, shell=True)
except Exception:
cfg.fatal("Failed to process hwdef.dat")
if ret != 0:
cfg.fatal("Failed to process hwdef.dat ret=%d" % ret)
load_env_vars(cfg.env)
if env.HAL_WITH_UAVCAN:
setup_can_build(cfg)
setup_optimization(cfg.env)
def pre_build(bld): def pre_build(bld):
'''pre-build hook to change dynamic sources''' '''pre-build hook to change dynamic sources'''
load_env_vars(bld.env) load_env_vars(bld.env)
if bld.env.HAL_WITH_UAVCAN: if bld.env.HAL_WITH_UAVCAN:
bld.get_board().with_uavcan = True bld.get_board().with_uavcan = True
hwdef_h = os.path.join(bld.env.BUILDROOT, 'hwdef.h')
if not os.path.exists(hwdef_h):
print("Generating hwdef.h")
try:
ret = generate_hwdef_h(bld.env)
except Exception:
bld.fatal("Failed to process hwdef.dat")
if ret != 0:
bld.fatal("Failed to process hwdef.dat ret=%d" % ret)
setup_optimization(bld.env)
def build(bld): def build(bld):
@ -394,7 +406,8 @@ def build(bld):
bld.env.get_flat('PYTHON'), bld.env.HWDEF, bld.env.BOOTLOADER_OPTION, bld.env.default_parameters), bld.env.get_flat('PYTHON'), bld.env.HWDEF, bld.env.BOOTLOADER_OPTION, bld.env.default_parameters),
group='dynamic_sources', group='dynamic_sources',
target=[bld.bldnode.find_or_declare('hwdef.h'), target=[bld.bldnode.find_or_declare('hwdef.h'),
bld.bldnode.find_or_declare('ldscript.ld')] bld.bldnode.find_or_declare('ldscript.ld'),
bld.bldnode.find_or_declare('hw.dat')]
) )
bld( bld(
@ -405,6 +418,7 @@ def build(bld):
) )
common_src = [bld.bldnode.find_or_declare('hwdef.h'), common_src = [bld.bldnode.find_or_declare('hwdef.h'),
bld.bldnode.find_or_declare('hw.dat'),
bld.bldnode.find_or_declare('modules/ChibiOS/include_dirs')] bld.bldnode.find_or_declare('modules/ChibiOS/include_dirs')]
common_src += bld.path.ant_glob('libraries/AP_HAL_ChibiOS/hwdef/common/*.[ch]') common_src += bld.path.ant_glob('libraries/AP_HAL_ChibiOS/hwdef/common/*.[ch]')
common_src += bld.path.ant_glob('libraries/AP_HAL_ChibiOS/hwdef/common/*.mk') common_src += bld.path.ant_glob('libraries/AP_HAL_ChibiOS/hwdef/common/*.mk')

3
Tools/ardupilotwaf/embed.py

@ -68,6 +68,9 @@ def create_embedded_h(filename, files, uncompressed=False):
out = open(filename, "wb") out = open(filename, "wb")
write_encode(out, '''// generated embedded files for AP_ROMFS\n\n''') write_encode(out, '''// generated embedded files for AP_ROMFS\n\n''')
# remove duplicates and sort
files = sorted(list(set(files)))
for i in range(len(files)): for i in range(len(files)):
(name, filename) = files[i] (name, filename) = files[i]
if not embed_file(out, filename, i, name, uncompressed): if not embed_file(out, filename, i, name, uncompressed):

Loading…
Cancel
Save