build: write the build info files only when they change

buildversion, feedsversion and json_overview_image_info rewrite
version.buildinfo, feeds.buildinfo and profiles.json on every build. The
content is the same, but the new timestamp makes the checksum step hash
every image again, which takes 0.18 s for the OpenWrt One and grows with the
number of devices.

Write the three files to the temporary directory and copy them over the
result of the last build only when the content differs.

This takes the time of the index, image info and checksum step from 0.36 s
to 0.10 s, and the time of a full no-op build from 3.25 s to 3.00 s.

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin committed 2026-09-22 18:18:58 +02:00
1 parent 0e5a0bd558
commit ac4f1dd36c
2 files changed
+20 -3

No files matched your search

+9 -3
View File
@@ -105,8 +105,10 @@ prereq: $(target/stamp-prereq) tmp/.prereq_packages
$(BIN_DIR)/profiles.json: FORCE
$(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
mkdir -p $(BIN_DIR) $(TMP_DIR); \
WORK_DIR=$(BUILD_DIR)/json_info_files \
$(SCRIPT_DIR)/json_overview_image_info.py $@ \
$(SCRIPT_DIR)/json_overview_image_info.py $(TMP_DIR)/.profiles.json && \
$(call cp_if_changed,$(TMP_DIR)/.profiles.json,$@) \
)
json_overview_image_info: $(BIN_DIR)/profiles.json
@@ -115,10 +117,14 @@ checksum: FORCE
$(call sha256sums,$(BIN_DIR),$(CONFIG_BUILDBOT))
buildversion: FORCE
$(SCRIPT_DIR)/getver.sh > $(BIN_DIR)/version.buildinfo
mkdir -p $(BIN_DIR) $(TMP_DIR)
$(SCRIPT_DIR)/getver.sh > $(TMP_DIR)/.version.buildinfo
$(call cp_if_changed,$(TMP_DIR)/.version.buildinfo,$(BIN_DIR)/version.buildinfo)
feedsversion: FORCE
$(SCRIPT_DIR)/feeds list -fs > $(BIN_DIR)/feeds.buildinfo
mkdir -p $(BIN_DIR) $(TMP_DIR)
$(SCRIPT_DIR)/feeds list -fs > $(TMP_DIR)/.feeds.buildinfo
$(call cp_if_changed,$(TMP_DIR)/.feeds.buildinfo,$(BIN_DIR)/feeds.buildinfo)
# diffconfig.sh runs the config parser over the whole tree twice, which takes
# two seconds of every build. Skip it while neither .config nor a Kconfig file
+11
View File
@@ -500,6 +500,17 @@ define file_copy
$(CP) $(1) $(2)
endef
##@
# @brief Copy a file over another one only when the content differs, so that
# the destination keeps its timestamp.
#
# @param 1: Source file.
# @param 2: Destination file.
##
define cp_if_changed
{ cmp -s $(1) $(2) || cp $(1) $(2); }
endef
##@
# @brief Calculate sha256sum of any plain file within a given directory.
#