summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Spooren2026-05-30 09:16:08 +0000
committerPaul Spooren2026-06-11 07:50:14 +0000
commite6c934d532c1baaf4087ccba3f3977e94bec4b64 (patch)
tree1b2914a2f10623ab83e8c7728290483e05005a9d
parent2a8b27fab9c8e8bf67ff8a0c341b06a8c68453cf (diff)
downloadopenwrt-e6c934d532c1baaf4087ccba3f3977e94bec4b64.tar.gz
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> (cherry picked from commit e36c2946b7b574504335ff517b19b7c1eedf1bd8)
-rw-r--r--include/package-defaults.mk1
-rw-r--r--include/package-pack.mk5
-rw-r--r--include/package.mk5
-rwxr-xr-xscripts/ipkg-build4
4 files changed, 7 insertions, 8 deletions
diff --git a/include/package-defaults.mk b/include/package-defaults.mk
index af2db4712c..5bb6d1d2f4 100644
--- a/include/package-defaults.mk
+++ b/include/package-defaults.mk
@@ -64,6 +64,7 @@ ifneq ($(strip $(PKG_UNPACK)),)
define Build/Prepare/Default
$(PKG_UNPACK)
[ ! -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)
endef
endif
diff --git a/include/package-pack.mk b/include/package-pack.mk
index 6ea4c59546..9cb64d3ae9 100644
--- a/include/package-pack.mk
+++ b/include/package-pack.mk
@@ -423,7 +423,7 @@ $$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
)$$(call addfield,LicenseFiles,$(LICENSE_FILES)
)$$(call addfield,Section,$(SECTION)
)$$(call addfield,Require-User,$(USERID)
-)$$(call addfield,SourceDateEpoch,$(PKG_SOURCE_DATE_EPOCH)
+)$$(call addfield,SourceDateEpoch,$$(PKG_SOURCE_DATE_EPOCH)
)$$(call addfield,URL,$(URL)
)$$(if $$(ABIV_$(1)),ABIVersion: $$(ABIV_$(1))
)$(if $(PKG_CPE_ID),CPE-ID: $(PKG_CPE_ID)
@@ -437,8 +437,7 @@ $(_endef)
$$(PACK_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
$$(PACK_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
$$(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
rm -rf $$(IDIR_$(1))
ifeq ($$(CONFIG_USE_APK),)
diff --git a/include/package.mk b/include/package.mk
index a8278d0672..da9fc7d4eb 100644
--- a/include/package.mk
+++ b/include/package.mk
@@ -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))
-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)
PKG_JOBS?=-j1
@@ -315,7 +316,7 @@ define Build/CoreTargets
ifneq ($(CONFIG_AUTOREMOVE),)
compile:
-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
endif
endef
diff --git a/scripts/ipkg-build b/scripts/ipkg-build
index d2beb41844..2e18194abd 100755
--- a/scripts/ipkg-build
+++ b/scripts/ipkg-build
@@ -15,9 +15,7 @@ FIND="${FIND:-$(command -v gfind)}"
TAR="${TAR:-$(command -v tar)}"
# try to use fixed source epoch
-if [ -n "$PKG_SOURCE_DATE_EPOCH" ]; then
- TIMESTAMP=$(date --date="@$PKG_SOURCE_DATE_EPOCH")
-elif [ -n "$SOURCE_DATE_EPOCH" ]; then
+if [ -n "$SOURCE_DATE_EPOCH" ]; then
TIMESTAMP=$(date --date="@$SOURCE_DATE_EPOCH")
else
TIMESTAMP=$(date)