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 <[email protected]>
---

v2: Fix accidental extra blank line that sneaked into v1

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

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"
 }
 
-- 
2.13.3

Reply via email to