From 7a937ad8949cc8e0e63f152a8c3059c7b05dd202 Mon Sep 17 00:00:00 2001 From: Matt Lawrence Date: Thu, 6 Feb 2020 21:38:36 -0500 Subject: [PATCH] AP_HAL_ChibiOS: Fix waf --default-parameters If a defaults.parm file was present in the hwdef, waf ignored the --default-parameters=xyz.parm command line argument. This will allow it to use that command line argument specified file. --- Tools/ardupilotwaf/chibios.py | 8 ++++---- .../hwdef/scripts/chibios_hwdef.py | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Tools/ardupilotwaf/chibios.py b/Tools/ardupilotwaf/chibios.py index 4d0690c9d8019..06f56389647c4 100644 --- a/Tools/ardupilotwaf/chibios.py +++ b/Tools/ardupilotwaf/chibios.py @@ -350,7 +350,7 @@ def bldpath(path): if cfg.options.default_parameters: cfg.msg('Default parameters', cfg.options.default_parameters, color='YELLOW') - env.DEFAULT_PARAMETERS = srcpath(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 # that is needed by the remaining configure checks @@ -368,7 +368,7 @@ def bldpath(path): os.mkdir(hwdef_out) python = sys.executable try: - cmd = "{0} '{1}' -D '{2}' '{3}' {4}".format(python, hwdef_script, hwdef_out, env.HWDEF, env.BOOTLOADER_OPTION) + cmd = "{0} '{1}' -D '{2}' '{3}' {4} --params '{5}'".format(python, hwdef_script, hwdef_out, env.HWDEF, env.BOOTLOADER_OPTION, cfg.options.default_parameters) ret = subprocess.call(cmd, shell=True) except Exception: cfg.fatal("Failed to process hwdef.dat") @@ -391,8 +391,8 @@ def build(bld): bld( # build hwdef.h from hwdef.dat. This is needed after a waf clean source=bld.path.ant_glob(bld.env.HWDEF), - rule="%s '${AP_HAL_ROOT}/hwdef/scripts/chibios_hwdef.py' -D '${BUILDROOT}' '%s' %s" % ( - bld.env.get_flat('PYTHON'), bld.env.HWDEF, bld.env.BOOTLOADER_OPTION), + rule="%s '${AP_HAL_ROOT}/hwdef/scripts/chibios_hwdef.py' -D '${BUILDROOT}' '%s' %s --params '%s'" % ( + bld.env.get_flat('PYTHON'), bld.env.HWDEF, bld.env.BOOTLOADER_OPTION, bld.env.default_parameters), group='dynamic_sources', target=[bld.bldnode.find_or_declare('hwdef.h'), bld.bldnode.find_or_declare('ldscript.ld')] diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index cce6d9b1e2a05..7d5d5e503fb9b 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -20,6 +20,8 @@ '--bootloader', action='store_true', default=False, help='configure for bootloader') parser.add_argument( 'hwdef', type=str, default=None, help='hardware definition file') +parser.add_argument( + '--params', type=str, default=None, help='user default params path') args = parser.parse_args() @@ -1774,11 +1776,19 @@ def build_peripheral_list(): def write_env_py(filename): '''write out env.py for environment variables to control the build process''' - # see if board has a defaults.parm file + # see if board has a defaults.parm file or a --default-parameters file was specified defaults_filename = os.path.join(os.path.dirname(args.hwdef), 'defaults.parm') - if os.path.exists(defaults_filename) and not args.bootloader: - print("Adding defaults.parm") - env_vars['DEFAULT_PARAMETERS'] = os.path.abspath(defaults_filename) + defaults_path = os.path.join(os.path.dirname(args.hwdef), args.params) + + if not args.bootloader: + if os.path.exists(defaults_path): + env_vars['DEFAULT_PARAMETERS'] = os.path.abspath(defaults_path) + print("Default parameters path from command line: %s" % defaults_path) + elif os.path.exists(defaults_filename): + env_vars['DEFAULT_PARAMETERS'] = os.path.abspath(defaults_filename) + print("Default parameters path from hwdef: %s" % defaults_filename) + else: + print("No default parameter file found") # CHIBIOS_BUILD_FLAGS is passed to the ChibiOS makefile env_vars['CHIBIOS_BUILD_FLAGS'] = ' '.join(build_flags)