blob: 727cb0372b0c5fac9225d40fa4edc684e49be2fc [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/usr/bin/env bash
2export LANG=C
3export LC_ALL=C
4
5if [ -n "$TOPDIR" ]; then
6 cd "$TOPDIR" || exit 1
7fi
8
9SOURCE="${1:-.}"
10
11try_version() {
12 [ -f "$SOURCE/version.date" ] || return 1
13 SOURCE_DATE_EPOCH=$(cat "$SOURCE/version.date")
14 [ -n "$SOURCE_DATE_EPOCH" ]
15}
16
17try_git() {
18 SOURCE_DATE_EPOCH=$(git -C "$SOURCE" log -1 --no-show-signature \
19 --format=format:%ct "$SOURCE" 2>/dev/null)
20 [ -n "$SOURCE_DATE_EPOCH" ]
21}
22
23try_hg() {
24 SOURCE_DATE_EPOCH=$(hg --cwd "$SOURCE" log --template '{date}' -l 1 \
25 "$SOURCE" 2>/dev/null | cut -d. -f1)
26 [ -n "$SOURCE_DATE_EPOCH" ]
27}
28
29try_mtime() {
30 SOURCE_DATE_EPOCH=$(perl -e 'print((stat $ARGV[0])[9])' "$0")
31 [ -n "$SOURCE_DATE_EPOCH" ]
32}
33
34try_version || try_git || try_hg || try_mtime || SOURCE_DATE_EPOCH=""
35echo "$SOURCE_DATE_EPOCH"