From ac4f1dd36ce8c3b3c06652780d86056d78efa642 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Tue, 22 Sep 2026 12:39:37 +0200 Subject: [PATCH] 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 --- Makefile | 12 +++++++++--- rules.mk | 11 +++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 02bfa514096..aec12743761 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/rules.mk b/rules.mk index d5b955a37f6..0fd2ccf5123 100644 --- a/rules.mk +++ b/rules.mk @@ -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. #