From b04c8f5e9becd6e91095e2add551f72870c9e869 Mon Sep 17 00:00:00 2001 From: Christian Franke <christian.fra...@t-online.de> Date: Fri, 16 Feb 2024 13:16:06 +0100 Subject: [PATCH] Add more checks of SOURCE_DATE_EPOCH
Fail if it is out of range. Warn if it lies in the future. Inform whether it is set or set but not exported. --- bin/cygport.in | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bin/cygport.in b/bin/cygport.in index 5fc89eaf..3fe8a52e 100755 --- a/bin/cygport.in +++ b/bin/cygport.in @@ -493,14 +493,32 @@ unset restrict if [ "${SOURCE_DATE_EPOCH+y}" = "y" ] then - if [ -n "$(echo "${SOURCE_DATE_EPOCH}" | sed -e 's/^$/X/' -e 's/[0-9]//g')" ] + if ! [[ "${SOURCE_DATE_EPOCH}" =~ ^[0-9]+$ ]] then error "SOURCE_DATE_EPOCH must be an integer number (seconds since the unix epoch)" fi + if ! _d=$(date --iso-8601=seconds -d "@${SOURCE_DATE_EPOCH}" 2>/dev/null) + then + error "SOURCE_DATE_EPOCH is out of range" + fi + if [ "${SOURCE_DATE_EPOCH}" -le "$(printf '%(%s)T')" ] + then + inform "Reproducible build: SOURCE_DATE_EPOCH='${SOURCE_DATE_EPOCH}' [$_d]" + else + warning "SOURCE_DATE_EPOCH='${SOURCE_DATE_EPOCH}' [$_d] lies in the future" + fi + unset _d + if [ -z "$(printenv SOURCE_DATE_EPOCH 2>/dev/null)" ] + then + inform "SOURCE_DATE_EPOCH is not exported to the environment" + fi + case $(peflags --version 2>/dev/null | sed -n '1s/^.* //p') in 4.6.[6-9]|4.[7-9]*|[5-9]*) ;; *) error "SOURCE_DATE_EPOCH requires peflags 4.6.6 or later" esac +else + inform "SOURCE_DATE_EPOCH is not set" fi -- 2.43.0