HAL_ChibiOS: avoid re-writing hwdef.h if unchanged

this makes dependency handling faster
This commit is contained in:
Andrew Tridgell 2021-12-13 10:17:04 +11:00 committed by Peter Barker
parent 0e5beb423e
commit ee7464140a

View File

@ -12,6 +12,7 @@ import shlex
import pickle import pickle
import re import re
import shutil import shutil
import filecmp
parser = argparse.ArgumentParser("chibios_pins.py") parser = argparse.ArgumentParser("chibios_pins.py")
parser.add_argument( parser.add_argument(
@ -2068,7 +2069,8 @@ def write_all_lines(hwdat):
def write_hwdef_header(outfilename): def write_hwdef_header(outfilename):
'''write hwdef header file''' '''write hwdef header file'''
print("Writing hwdef setup in %s" % outfilename) print("Writing hwdef setup in %s" % outfilename)
f = open(outfilename, 'w') tmpfile = outfilename + ".tmp"
f = open(tmpfile, 'w')
f.write('''/* f.write('''/*
generated hardware definitions from hwdef.dat - DO NOT EDIT generated hardware definitions from hwdef.dat - DO NOT EDIT
@ -2222,6 +2224,21 @@ def write_hwdef_header(outfilename):
if fnmatch.fnmatch(d, r): if fnmatch.fnmatch(d, r):
error("Missing required DMA for %s" % d) 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(): def build_peripheral_list():
'''build a list of peripherals for DMA resolver to work on''' '''build a list of peripherals for DMA resolver to work on'''