Skip to content

Commit 736a8a8

Browse files
committed
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.
1 parent 3e321f1 commit 736a8a8

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

zephyr/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,4 @@ z_clean:
102102

103103
.PHONY: prj.conf
104104
prj.conf: prj_base.conf
105-
cat $< >$@
106-
if [ -f prj_$(BOARD).conf ]; then cat prj_$(BOARD).conf >>$@; fi
105+
$(PYTHON) makeprj.py prj_base.conf prj_$(BOARD).conf $@

zephyr/makeprj.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import os
4+
import hashlib
5+
6+
7+
def hash_file(fname):
8+
if not os.path.exists(fname):
9+
return b""
10+
hasher = hashlib.md5()
11+
with open(fname, "rb") as f:
12+
hasher.update(f.read())
13+
return hasher.digest()
14+
15+
16+
old_digest = hash_file(sys.argv[3])
17+
18+
with open(sys.argv[3] + ".tmp", "wb") as f:
19+
f.write(open(sys.argv[1], "rb").read())
20+
if os.path.exists(sys.argv[2]):
21+
f.write(open(sys.argv[2], "rb").read())
22+
23+
new_digest = hash_file(sys.argv[3] + ".tmp")
24+
25+
if new_digest != old_digest:
26+
print("Replacing")
27+
os.rename(sys.argv[3] + ".tmp", sys.argv[3])
28+
else:
29+
os.remove(sys.argv[3] + ".tmp")

0 commit comments

Comments
 (0)