build: make it more reproducible

* file-date-gen: Consistently print the UTC date in C locale.
When $SOURCE_DATE_EPOCH is non-empty, use it as fallback date
before the current system date.

Reported-by: Chris Lamb <lamby@debian.org>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=896016
Closes: https://github.com/strace/strace/pull/68
This commit is contained in:
Дмитрий Левин 2018-04-19 18:03:58 +00:00
parent 98d3356b04
commit 31ce194d23

View File

@ -10,6 +10,7 @@ fi
: ${DATE_FILE:=$(dirname "$FILE")/.$(basename "${FILE}").date}
: ${DEFAULT_DATE:=$2}
: ${DATE_FORMAT:=%Y-%m-%d}
LC_TIME=C; export LC_TIME
date=
@ -23,13 +24,19 @@ date=
[ -n "${date}" ] ||
date="$(git log -n 1 --format=format:%cD --no-patch "${FILE}")"
[ -n "${date}" ] || year="${DEFAULT_DATE}"
[ -n "${date}" ] ||
date="${DEFAULT_DATE}"
[ -n "${date}" ] || date="$(date -u)"
[ -n "${date}" ] ||
[ -z "${SOURCE_DATE_EPOCH-}" ] ||
date="$(date -u -d "@${SOURCE_DATE_EPOCH}")"
[ -n "${date}" ] ||
date="$(date -u)"
[ -n "${date}" ] || {
echo >&2 'Undefined date.'
exit 1
}
exec printf "%s" $(date "+${DATE_FORMAT}" -d "${date}")
exec printf "%s" $(date -u "+${DATE_FORMAT}" -d "${date}")