build: Fix Shellcheck for get_source_date_epoch.sh

If a `cd` to `TOPDIR` fails the script should quit.

Also unify `try_mtime` function by storing it in a variable.

Signed-off-by: Paul Spooren <mail@aparcar.org>
This commit is contained in:
Paul Spooren 2020-08-15 10:57:00 -10:00 committed by Daniel Golle
parent 7d26f294cd
commit ae87e53e33
1 changed files with 5 additions and 2 deletions

View File

@ -1,7 +1,10 @@
#!/usr/bin/env bash
export LANG=C
export LC_ALL=C
[ -n "$TOPDIR" ] && cd $TOPDIR
if [ -n "$TOPDIR" ]; then
cd "$TOPDIR" || exit 1
fi
try_version() {
[ -f version.date ] || return 1
@ -22,7 +25,7 @@ try_hg() {
}
try_mtime() {
perl -e 'print((stat $ARGV[0])[9])' "$0"
SOURCE_DATE_EPOCH=$(perl -e 'print((stat $ARGV[0])[9])' "$0")
[ -n "$SOURCE_DATE_EPOCH" ]
}