diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-03-12 22:28:45 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-03-12 22:28:45 +0300 |
commit | 736a8a8ac7abfeab5edb8dfd73ecf0b2c0282e61 (patch) | |
tree | 91ed834154ad75a5ff066bdad4f797e2e6db15bd | |
parent | 3e321f1724b4e2deae2a7750c789c6423f5201c2 (diff) | |
download | micropython-736a8a8ac7abfeab5edb8dfd73ecf0b2c0282e61.tar.gz micropython-736a8a8ac7abfeab5edb8dfd73ecf0b2c0282e61.zip |
zephyr: Make sure that generated prj.conf is updated only on content changes.
This is a typical problem with make: we want to trigger rebuilds only
if file actually changed, not if its timestamp changed. In this case,
it's aggravated by the fact that prj.conf depends on the value of
BOARD variable, so we need to do some tricks anyway. We still don't
try to detect if just BOARD changed, just try to generate new
prj.conf.tmp every time (quick), but do actual replacement of prj.conf
only if its content changed.
-rw-r--r-- | zephyr/Makefile | 3 | ||||
-rw-r--r-- | zephyr/makeprj.py | 29 |
2 files changed, 30 insertions, 2 deletions
diff --git a/zephyr/Makefile b/zephyr/Makefile index d020ab5ce0..7d4d6674ef 100644 --- a/zephyr/Makefile +++ b/zephyr/Makefile @@ -102,5 +102,4 @@ z_clean: .PHONY: prj.conf prj.conf: prj_base.conf - cat $< >$@ - if [ -f prj_$(BOARD).conf ]; then cat prj_$(BOARD).conf >>$@; fi + $(PYTHON) makeprj.py prj_base.conf prj_$(BOARD).conf $@ diff --git a/zephyr/makeprj.py b/zephyr/makeprj.py new file mode 100644 index 0000000000..239c877cd6 --- /dev/null +++ b/zephyr/makeprj.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +import sys +import os +import hashlib + + +def hash_file(fname): + if not os.path.exists(fname): + return b"" + hasher = hashlib.md5() + with open(fname, "rb") as f: + hasher.update(f.read()) + return hasher.digest() + + +old_digest = hash_file(sys.argv[3]) + +with open(sys.argv[3] + ".tmp", "wb") as f: + f.write(open(sys.argv[1], "rb").read()) + if os.path.exists(sys.argv[2]): + f.write(open(sys.argv[2], "rb").read()) + +new_digest = hash_file(sys.argv[3] + ".tmp") + +if new_digest != old_digest: + print("Replacing") + os.rename(sys.argv[3] + ".tmp", sys.argv[3]) +else: + os.remove(sys.argv[3] + ".tmp") |