diff mbox

[pacman-dev,v2] makepkg: respect $SOURCE_DATE_EPOCH to activate reproducible builds

Message ID 20170728035034.15380-1-eschwartz@archlinux.org
State Superseded, archived
Headers show

Commit Message

Eli Schwartz July 28, 2017, 3:50 a.m. UTC
If SOURCE_DATE_EPOCH is set, `touch` all source files before running
build() to fix the modification times. This works around build systems
and compilers that embed the file modification times into the file
contents of release artifacts.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---

v2: Fix accidental extra blank line that sneaked into v1

 scripts/makepkg.sh.in | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 20e9dd7e..77d39ca5 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -79,6 +79,7 @@  PKGFUNC=0
 PKGVERFUNC=0
 PREPAREFUNC=0
 REPKG=0
+REPRODUCIBLE=0
 RMDEPS=0
 SKIPCHECKSUMS=0
 SKIPPGPCHECK=0
@@ -87,7 +88,12 @@  SPLITPKG=0
 SOURCEONLY=0
 VERIFYSOURCE=0
 
-export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(date +%s)}
+if [[ -n $SOURCE_DATE_EPOCH ]]; then
+	REPRODUCIBLE=1
+else
+	SOURCE_DATE_EPOCH=$(date +%s)
+fi
+export SOURCE_DATE_EPOCH
 
 PACMAN_OPTS=()
 
@@ -475,6 +481,12 @@  run_prepare() {
 }
 
 run_build() {
+	if (( REPRODUCIBLE )); then
+		# We have activated reproducible builds, so unify source times before
+		# building
+		find "$srcdir" -exec touch -h -d @$SOURCE_DATE_EPOCH {} +
+	fi
+
 	run_function_safe "build"
 }