build: derive PKG_SOURCE_DATE_EPOCH from the unpacked source tree

Previously PKG_SOURCE_DATE_EPOCH came from a git log on the OpenWrt
package directory. That fails in shallow feed clones and in the SDK
(no .git), collapsing to the script's mtime and breaking .apk
reproducibility across SDK rebuilds and between buildbot and SDK.

With this comment, PKG_UNPACK generates a version.date file, later used to
determine a reproducible SOURCE_DATE_EPOCH. Since unpack happens after
download, the evaluation of SOURCE_DATE_EPOCH is now lazy, invoking the
`get_source_date_epoch.sh` script on every use.

While at it, drop export of PKG_SOURCE_DATE_EPOCH and clean it from the
ipkg-build script.

Link: https://github.com/openwrt/openwrt/issues/21579
Link: https://github.com/openwrt/openwrt/pull/21587

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Link: https://github.com/openwrt/openwrt/pull/23576
Signed-off-by: Paul Spooren <mail@aparcar.org>
This commit is contained in:
Paul Spooren
2026-05-30 11:16:08 +02:00
parent d93c6d9a49
commit e36c2946b7
4 changed files with 7 additions and 8 deletions
+1
View File
@@ -64,6 +64,7 @@ ifneq ($(strip $(PKG_UNPACK)),)
define Build/Prepare/Default define Build/Prepare/Default
$(PKG_UNPACK) $(PKG_UNPACK)
[ ! -d ./src/ ] || $(CP) ./src/. $(PKG_BUILD_DIR) [ ! -d ./src/ ] || $(CP) ./src/. $(PKG_BUILD_DIR)
-find $(PKG_BUILD_DIR) -mindepth 1 -type f -printf '%T@\n' 2>/dev/null | head -n1 | cut -d. -f1 > $(PKG_BUILD_DIR)/version.date
$(Build/Patch) $(Build/Patch)
endef endef
endif endif
+2 -3
View File
@@ -439,7 +439,7 @@ $$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
)$$(call addfield,LicenseFiles,$(LICENSE_FILES) )$$(call addfield,LicenseFiles,$(LICENSE_FILES)
)$$(call addfield,Section,$(SECTION) )$$(call addfield,Section,$(SECTION)
)$$(call addfield,Require-User,$(USERID) )$$(call addfield,Require-User,$(USERID)
)$$(call addfield,SourceDateEpoch,$(PKG_SOURCE_DATE_EPOCH) )$$(call addfield,SourceDateEpoch,$$(PKG_SOURCE_DATE_EPOCH)
)$$(call addfield,URL,$(URL) )$$(call addfield,URL,$(URL)
)$$(if $$(ABIV_$(1)),ABIVersion: $$(ABIV_$(1)) )$$(if $$(ABIV_$(1)),ABIVersion: $$(ABIV_$(1))
)$(if $(PKG_CPE_ID),CPE-ID: $(PKG_CPE_ID) )$(if $(PKG_CPE_ID),CPE-ID: $(PKG_CPE_ID)
@@ -453,8 +453,7 @@ $(_endef)
$$(PACK_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL) $$(PACK_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
$$(PACK_$(1)) : $(call shexport,Package/$(1)/description) $$(PACK_$(1)) : $(call shexport,Package/$(1)/description)
$$(PACK_$(1)) : export PATH=$$(TARGET_PATH_PKG) $$(PACK_$(1)) : export PATH=$$(TARGET_PATH_PKG)
$$(PACK_$(1)) : export PKG_SOURCE_DATE_EPOCH:=$(PKG_SOURCE_DATE_EPOCH) $$(PACK_$(1)) : export SOURCE_DATE_EPOCH=$$(PKG_SOURCE_DATE_EPOCH)
$$(PACK_$(1)) : export SOURCE_DATE_EPOCH:=$(PKG_SOURCE_DATE_EPOCH)
$(PKG_INFO_DIR)/$(1).provides $$(PACK_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-pack.mk $(PKG_INFO_DIR)/$(1).provides $$(PACK_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-pack.mk
rm -rf $$(IDIR_$(1)) rm -rf $$(IDIR_$(1))
ifeq ($$(CONFIG_USE_APK),) ifeq ($$(CONFIG_USE_APK),)
+3 -2
View File
@@ -15,7 +15,8 @@ PKG_SKIP_DOWNLOAD=$(USE_SOURCE_DIR)$(USE_GIT_TREE)$(USE_GIT_SRC_CHECKOUT)
MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j)) MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
PKG_SOURCE_DATE_EPOCH:=$(if $(DUMP),,$(shell $(TOPDIR)/scripts/get_source_date_epoch.sh $(CURDIR))) PKG_SOURCE_DATE_EPOCH = $(if $(DUMP),,$(shell $(TOPDIR)/scripts/get_source_date_epoch.sh \
$(if $(wildcard $(PKG_BUILD_DIR)/version.date),$(PKG_BUILD_DIR),$(CURDIR))))
ifeq ($(strip $(PKG_BUILD_PARALLEL)),0) ifeq ($(strip $(PKG_BUILD_PARALLEL)),0)
PKG_JOBS?=-j1 PKG_JOBS?=-j1
@@ -324,7 +325,7 @@ define Build/CoreTargets
ifneq ($(CONFIG_AUTOREMOVE),) ifneq ($(CONFIG_AUTOREMOVE),)
compile: compile:
-touch -r $(PKG_BUILD_DIR)/.built $(PKG_BUILD_DIR)/.autoremove 2>/dev/null >/dev/null -touch -r $(PKG_BUILD_DIR)/.built $(PKG_BUILD_DIR)/.autoremove 2>/dev/null >/dev/null
$(FIND) $(PKG_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' -print0 | \ $(FIND) $(PKG_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' -and -not -name 'version.date' -print0 | \
$(XARGS) -0 rm -rf $(XARGS) -0 rm -rf
endif endif
endef endef
+1 -3
View File
@@ -15,9 +15,7 @@ FIND="${FIND:-$(command -v gfind)}"
TAR="${TAR:-$(command -v tar)}" TAR="${TAR:-$(command -v tar)}"
# try to use fixed source epoch # try to use fixed source epoch
if [ -n "$PKG_SOURCE_DATE_EPOCH" ]; then if [ -n "$SOURCE_DATE_EPOCH" ]; then
TIMESTAMP=$(date --date="@$PKG_SOURCE_DATE_EPOCH")
elif [ -n "$SOURCE_DATE_EPOCH" ]; then
TIMESTAMP=$(date --date="@$SOURCE_DATE_EPOCH") TIMESTAMP=$(date --date="@$SOURCE_DATE_EPOCH")
else else
TIMESTAMP=$(date) TIMESTAMP=$(date)