From ee7464140a13cb28710c40d26581469c2ec5b510 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 2021 10:17:04 +1100 Subject: [PATCH] HAL_ChibiOS: avoid re-writing hwdef.h if unchanged this makes dependency handling faster --- .../hwdef/scripts/chibios_hwdef.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index c6da5949e1..71d64e1aed 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -12,6 +12,7 @@ import shlex import pickle import re import shutil +import filecmp parser = argparse.ArgumentParser("chibios_pins.py") parser.add_argument( @@ -2068,7 +2069,8 @@ def write_all_lines(hwdat): def write_hwdef_header(outfilename): '''write hwdef header file''' print("Writing hwdef setup in %s" % outfilename) - f = open(outfilename, 'w') + tmpfile = outfilename + ".tmp" + f = open(tmpfile, 'w') f.write('''/* generated hardware definitions from hwdef.dat - DO NOT EDIT @@ -2222,6 +2224,21 @@ def write_hwdef_header(outfilename): if fnmatch.fnmatch(d, r): error("Missing required DMA for %s" % d) + f.close() + # see if we ended up with the same file, on an unnecessary reconfigure + try: + if filecmp.cmp(outfilename, tmpfile): + print("No change in hwdef.h") + os.unlink(tmpfile) + return + except Exception: + pass + try: + os.unlink(outfilename) + except Exception: + pass + os.rename(tmpfile, outfilename) + def build_peripheral_list(): '''build a list of peripherals for DMA resolver to work on'''