AP_HAL_ChibiOS: process @include lines within hwdef files

This commit is contained in:
Peter Barker 2023-06-30 17:45:45 +10:00 committed by Peter Barker
parent 53e6f289e5
commit d0b967097e
2 changed files with 33 additions and 8 deletions

View File

@ -1,7 +1 @@
# setup for LEDs on chan9
SERVO9_FUNCTION 120
# Default VTX power to on
RELAY_DEFAULT 1
# UART1 for DJI Goggles
SERIAL1_PROTOCOL 33
@include ../KakuteH7Mini/defaults.parm

View File

@ -2736,6 +2736,32 @@ INCLUDE common.ld
done.add(type)
return peripherals
def get_processed_defaults_file(self, defaults_filepath, depth=0):
'''reads defaults_filepath, expanding any @include lines to include
the contents of the so-references file - recursively.'''
if depth > 10:
raise Exception("include loop")
ret = ""
with open(defaults_filepath, 'r') as defaults_fh:
while True:
line = defaults_fh.readline()
if line == "":
break
m = re.match("^@include\s*([^\s]+)", line)
if m is None:
ret += line
continue
# we've found an include; do that...
include_filepath = os.path.join(os.path.dirname(defaults_filepath), m.group(1))
try:
# ret += "# Begin included file (%s)" % include_filepath
ret += self.get_processed_defaults_file(include_filepath, depth=depth+1)
# ret += "# End included file (%s)" % include_filepath
except FileNotFoundError:
raise Exception("%s includes %s but that filepath was not found" %
(defaults_filepath, include_filepath))
return ret
def write_processed_defaults_file(self, filepath):
# see if board has a defaults.parm file or a --default-parameters file was specified
@ -2754,7 +2780,12 @@ INCLUDE common.ld
print("No default parameter file found")
return
self.env_vars['DEFAULT_PARAMETERS'] = defaults_abspath
content = self.get_processed_defaults_file(defaults_abspath)
with open(filepath, "w") as processed_defaults_fh:
processed_defaults_fh.write(content)
self.env_vars['DEFAULT_PARAMETERS'] = filepath
def write_env_py(self, filename):