Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waf: move chibios hwdef generation to explicit call #27991

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions Tools/ardupilotwaf/chibios.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
import base64
import subprocess

# modify our search path:
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts'))
import chibios_hwdef

_dynamic_env_data = {}
def _load_dynamic_env_data(bld):
bldnode = bld.bldnode.make_node('modules/ChibiOS')
Expand Down Expand Up @@ -638,17 +642,27 @@ def generate_hwdef_h(env):
print(env.BOOTLOADER_OPTION)
env.BOOTLOADER_OPTION += " --signed-fw"
print(env.BOOTLOADER_OPTION)
hwdef_script = os.path.join(env.SRCROOT, 'libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py')
hwdef_out = env.BUILDROOT
if not os.path.exists(hwdef_out):
os.mkdir(hwdef_out)
python = sys.executable
cmd = "{0} '{1}' -D '{2}' --params '{3}' '{4}'".format(python, hwdef_script, hwdef_out, env.DEFAULT_PARAMETERS, env.HWDEF)

# Build a list of the hardware definitions
hwdef_arr = [env.HWDEF]
if env.HWDEF_EXTRA:
cmd += " '{0}'".format(env.HWDEF_EXTRA)
if env.BOOTLOADER_OPTION:
cmd += " " + env.BOOTLOADER_OPTION
return subprocess.call(cmd, shell=True)
# Add any extra hwdefs that may be defined
hwdef_arr.append(env.HWDEF_EXTRA)
joshanne marked this conversation as resolved.
Show resolved Hide resolved
ch = chibios_hwdef.ChibiOSHWDef(outdir=hwdef_out,
bootloader=env.BOOTLOADER,
signed_fw=env.AP_SIGNED_FIRMWARE,
joshanne marked this conversation as resolved.
Show resolved Hide resolved
default_params_filepath=env.DEFAULT_PARAMETERS,
hwdef=hwdef_arr)
try:
ch.run()
# Return success for subprocess call
return 0
except SystemExit:
# The run failed, so return the error code
return 1

def pre_build(bld):
'''pre-build hook to change dynamic sources'''
Expand All @@ -668,21 +682,18 @@ def pre_build(bld):

def build(bld):


hwdef_rule="%s '%s/hwdef/scripts/chibios_hwdef.py' -D '%s' --params '%s' '%s'" % (
bld.env.get_flat('PYTHON'),
bld.env.AP_HAL_ROOT,
bld.env.BUILDROOT,
bld.env.default_parameters,
bld.env.HWDEF)
hwdef_arr = [bld.env.HWDEF]
if bld.env.HWDEF_EXTRA:
hwdef_rule += " " + bld.env.HWDEF_EXTRA
if bld.env.BOOTLOADER_OPTION:
hwdef_rule += " " + bld.env.BOOTLOADER_OPTION
hwdef_arr.append(bld.env.HWDEF_EXTRA)
joshanne marked this conversation as resolved.
Show resolved Hide resolved
ch = chibios_hwdef.ChibiOSHWDef(outdir=bld.env.BUILDROOT,
bootloader=bld.env.BOOTLOADER,
signed_fw=bld.env.AP_SIGNED_FIRMWARE,
default_params_filepath=bld.env.DEFAULT_PARAMETERS,
hwdef=hwdef_arr)
bld(
# build hwdef.h from hwdef.dat. This is needed after a waf clean
source=bld.path.ant_glob(bld.env.HWDEF),
rule=hwdef_rule,
rule=ch.run,
group='dynamic_sources',
target=[bld.bldnode.find_or_declare('hwdef.h'),
bld.bldnode.find_or_declare('ldscript.ld'),
Expand Down
12 changes: 7 additions & 5 deletions libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -2891,12 +2891,14 @@ def get_processed_defaults_file(self, defaults_filepath, depth=0):
def write_processed_defaults_file(self, filepath):
# see if board has a defaults.parm file or a --default-parameters file was specified
defaults_filename = os.path.join(os.path.dirname(self.hwdef[0]), 'defaults.parm')
defaults_path = os.path.join(os.path.dirname(self.hwdef[0]), args.params)

defaults_abspath = None
if os.path.exists(defaults_path):
defaults_abspath = os.path.abspath(self.default_params_filepath)
self.progress("Default parameters path from command line: %s" % self.default_params_filepath)
if isinstance(self.default_params_filepath, str):
defaults_path = os.path.join(os.path.dirname(self.hwdef[0]), self.default_params_filepath)
if not os.path.exists(defaults_path):
self.error(f"Specified defaults file not found at path {defaults_path}")

defaults_abspath = os.path.abspath(defaults_path)
self.progress("Default parameters path from command line: %s" % defaults_path)
elif os.path.exists(defaults_filename):
defaults_abspath = os.path.abspath(defaults_filename)
self.progress("Default parameters path from hwdef: %s" % defaults_filename)
Expand Down
2 changes: 1 addition & 1 deletion wscript
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ def configure(cfg):
_set_build_context_variant(cfg.env.BOARD)
cfg.setenv(cfg.env.BOARD)

cfg.env.AP_SIGNED_FIRMWARE = cfg.options.signed_fw
if cfg.options.signed_fw:
cfg.env.AP_SIGNED_FIRMWARE = True
cfg.options.enable_check_firmware = True

cfg.env.BOARD = cfg.options.board
Expand Down
Loading