build: merge the packages only when the set of packages changed

package/merge deletes the symlink farm of every built package and creates
it again on every build. package/merge-index then reads all of those
packages to create the index. With two thousand packages both steps take a
third of a second, and the cost grows with the size of the configuration.

Record the name, the size and the timestamp of every package file. Skip
both steps while that list is unchanged and the index is present. A rebuild
of the symlinks drops the index, so merge-index creates it again.

This takes the time of package/install on an unchanged tree from 1.05 s to
0.60 s for the OpenWrt One.

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 af60df881d
commit 8d25643025
1 file changed
+24 -7
+24 -7
View File
@@ -50,14 +50,29 @@ PACKAGE_INSTALL_FILES:= \
$(curdir)/cleanup: $(TMP_DIR)/.build
rm -rf $(STAGING_DIR_ROOT)
PACKAGE_EXT:=$(if $(CONFIG_USE_APK),apk,ipk)
PACKAGE_INDEX_FILE:=$(PACKAGE_DIR_ALL)/$(if $(CONFIG_USE_APK),packages.adb,Packages)
PACKAGE_MERGE_LIST:=$(PACKAGE_DIR_ALL).list
define package_merge_links
rm -rf $(PACKAGE_DIR_ALL); \
mkdir -p $(PACKAGE_DIR_ALL); \
$(foreach pdir,$(PACKAGE_SUBDIRS), \
$(if $(wildcard $(pdir)/*.$(PACKAGE_EXT)), \
ln -s $(pdir)/*.$(PACKAGE_EXT) $(PACKAGE_DIR_ALL) || true;))
endef
$(curdir)/merge:
rm -rf $(PACKAGE_DIR_ALL)
mkdir -p $(PACKAGE_DIR_ALL)
ifneq ($(CONFIG_USE_APK),)
-$(foreach pdir,$(PACKAGE_SUBDIRS),$(if $(wildcard $(pdir)/*.apk),ln -s $(pdir)/*.apk $(PACKAGE_DIR_ALL);))
else
-$(foreach pdir,$(PACKAGE_SUBDIRS),$(if $(wildcard $(pdir)/*.ipk),ln -s $(pdir)/*.ipk $(PACKAGE_DIR_ALL);))
endif
mkdir -p $(dir $(PACKAGE_MERGE_LIST))
find $(PACKAGE_SUBDIRS) -maxdepth 1 -name '*.$(PACKAGE_EXT)' \
-printf '%p %s %T@\n' 2>/dev/null | LC_ALL=C sort > $(PACKAGE_MERGE_LIST).new
if cmp -s $(PACKAGE_MERGE_LIST).new $(PACKAGE_MERGE_LIST) && \
[ -f $(PACKAGE_INDEX_FILE) ]; then \
rm -f $(PACKAGE_MERGE_LIST).new; \
else \
$(package_merge_links) \
mv $(PACKAGE_MERGE_LIST).new $(PACKAGE_MERGE_LIST); \
fi
$(BUILD_KEY_APK_SEC):
$(STAGING_DIR_HOST)/bin/openssl ecparam -name prime256v1 -genkey -noout -out $(BUILD_KEY_APK_SEC)
@@ -67,6 +82,7 @@ $(BUILD_KEY_APK_PUB): $(BUILD_KEY_APK_SEC)
$(curdir)/merge-index: $(curdir)/merge
ifneq ($(CONFIG_USE_APK),)
[ -f $(PACKAGE_INDEX_FILE) ] || \
(cd $(PACKAGE_DIR_ALL) && $(STAGING_DIR_HOST)/bin/apk mkndx \
--root $(TOPDIR) \
--keys-dir $(TOPDIR) \
@@ -76,6 +92,7 @@ ifneq ($(CONFIG_USE_APK),)
*.apk; \
)
else
[ -f $(PACKAGE_INDEX_FILE) ] || \
(cd $(PACKAGE_DIR_ALL) && $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages; )
endif