From ce1ee6334fe791a5de0ed695a4552f8477cf266d Mon Sep 17 00:00:00 2001 From: willpiper Date: Sat, 19 Jun 2021 18:17:12 +0100 Subject: [PATCH] AP_HAL_ChibiOS: addressed reviewed comments --- .../hwdef/scripts/chibios_hwdef.py | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index 091ecace8e..0556ad0cd8 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -2205,29 +2205,28 @@ def process_line(line): env_vars[a[1]] = ' '.join(a[2:]) -def process_file(fname,extra_hwdef): +def process_file(filename): '''process a hwdef.dat file''' - for filename in [fname,extra_hwdef]: - try: - f = open(filename, "r") - except Exception: - error("Unable to open file %s" % filename) - for line in f.readlines(): - line = line.split('#')[0] # ensure we discard the comments - line = line.strip() - if len(line) == 0 or line[0] == '#': - continue - a = shlex.split(line) - if a[0] == "include" and len(a) > 1: - include_file = a[1] - if include_file[0] != '/': - dir = os.path.dirname(filename) - include_file = os.path.normpath( - os.path.join(dir, include_file)) - print("Including %s" % include_file) - process_file(include_file) - else: - process_line(line) + try: + f = open(filename, "r") + except Exception: + error("Unable to open file %s" % filename) + for line in f.readlines(): + line = line.split('#')[0] # ensure we discard the comments + line = line.strip() + if len(line) == 0 or line[0] == '#': + continue + a = shlex.split(line) + if a[0] == "include" and len(a) > 1: + include_file = a[1] + if include_file[0] != '/': + dir = os.path.dirname(filename) + include_file = os.path.normpath( + os.path.join(dir, include_file)) + print("Including %s" % include_file) + process_file(include_file) + else: + process_line(line) def add_apperiph_defaults(f): '''add default defines for peripherals''' @@ -2261,7 +2260,11 @@ def add_apperiph_defaults(f): # process input file -process_file(args.hwdef,args.extra_hwdef) +if args.hwdef != None: + for filename in [args.hwdef,args.extra_hwdef]: + process_file(filename) +else: + process_file(args.hwdef) outdir = args.outdir if outdir is None: