Skip to content

Commit 53a08e3

Browse files
committed
build: make find_md5 reproducible with AUTOREMOVE
While experimenting with the AUTOREMOVE option in search of a way to use prebuilt host tools in different buildroot, it was discovered that the md5 generated by find_md5 in depends.mk is not reproducible. Currently the hash is generated by the path of the file in addition to the file mod time. Out of confusion, probably, there was an idea that such command was used on the package build_dir. Reality is that this command is run on the package files. (Makefile, patches, src) This is problematic because the package Makefile (for example) change at each git clone and base the hash on the Makefile mtime doesn't really reflect if the Makefile actually changes across a buildroot or not. A better approach is to generate an hash of each file and then generate an hash on the sort hash list. This way we remove the problem of git clone setting a wrong mtime while keeping the integrity of checking if a file changed for the package as any change will result in a different hash. Introduce a new kind of find_md5 function, find_md5_reproducible that apply this new logic and limit it only with AUTOREMOVE option set to prevent any kind of slowdown due to additional hash generation. Signed-off-by: Christian Marangi <[email protected]>
1 parent 0e3d51c commit 53a08e3

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

include/depends.mk

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
DEP_FINDPARAMS := -x "*/.svn*" -x ".*" -x "*:*" -x "*\!*" -x "* *" -x "*\\\#*" -x "*/.*_check" -x "*/.*.swp" -x "*/.pkgdir*"
1313

1414
find_md5=find $(wildcard $(1)) -type f $(patsubst -x,-and -not -path,$(DEP_FINDPARAMS) $(2)) -printf "%p%T@\n" | sort | $(MKHASH) md5
15+
find_md5_reproducible=find $(wildcard $(1)) -type f $(patsubst -x,-and -not -path,$(DEP_FINDPARAMS) $(2)) -print0 | xargs -0 $(MKHASH) md5 | sort | $(MKHASH) md5
1516

1617
define rdep
1718
.PRECIOUS: $(2)

include/host-build.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ include $(INCLUDE_DIR)/depends.mk
2121
include $(INCLUDE_DIR)/quilt.mk
2222

2323
BUILD_TYPES += host
24-
HOST_STAMP_PREPARED=$(HOST_BUILD_DIR)/.prepared$(if $(HOST_QUILT)$(DUMP),,$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(HOST_PREPARED_DEPENDS)))
24+
HOST_STAMP_PREPARED=$(HOST_BUILD_DIR)/.prepared$(if $(HOST_QUILT)$(DUMP),,$(shell $(call $(if $(CONFIG_AUTOREMOVE),find_md5_reproducible,find_md5),${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(HOST_PREPARED_DEPENDS)))
2525
HOST_STAMP_CONFIGURED:=$(HOST_BUILD_DIR)/.configured
2626
HOST_STAMP_BUILT:=$(HOST_BUILD_DIR)/.built
2727
HOST_BUILD_PREFIX?=$(if $(IS_PACKAGE_BUILD),$(STAGING_DIR_HOSTPKG),$(STAGING_DIR_HOST))

include/kernel-build.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ifneq ($(DUMP),1)
1010
endif
1111

1212
KERNEL_FILE_DEPENDS=$(GENERIC_BACKPORT_DIR) $(GENERIC_PATCH_DIR) $(GENERIC_HACK_DIR) $(PATCH_DIR) $(GENERIC_FILES_DIR) $(FILES_DIR)
13-
STAMP_PREPARED=$(LINUX_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,$(KERNEL_FILE_DEPENDS),)))
13+
STAMP_PREPARED=$(LINUX_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call $(if $(CONFIG_AUTOREMOVE),find_md5_reproducible,find_md5),$(KERNEL_FILE_DEPENDS),)))
1414
STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
1515
include $(INCLUDE_DIR)/download.mk
1616
include $(INCLUDE_DIR)/quilt.mk

include/package.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ifneq ($(PREV_STAMP_PREPARED),)
8585
STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
8686
CONFIG_AUTOREBUILD:=
8787
else
88-
STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(PKG_PREPARED_DEPENDS)))
88+
STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call $(if $(CONFIG_AUTOREMOVE),find_md5_reproducible,find_md5),${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(PKG_PREPARED_DEPENDS)))
8989
endif
9090
STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
9191
STAMP_CONFIGURED_WILDCARD=$(PKG_BUILD_DIR)/.configured_*

0 commit comments

Comments
 (0)