2021-10-22 17:27:19 +08:00
|
|
|
#!/bin/sh
|
2013-06-24 18:09:29 +08:00
|
|
|
# Originally from the git sources (GIT-VERSION-GEN)
|
|
|
|
# Presumably (C) Junio C Hamano <junkio@cox.net>
|
|
|
|
# Reused under GPL v2.0
|
|
|
|
# Modified for fish by David Adam <zanchey@ucc.gu.uwa.edu.au>
|
|
|
|
|
2018-06-02 01:48:03 +08:00
|
|
|
set -e
|
|
|
|
|
2019-12-17 11:13:32 +08:00
|
|
|
# Find the fish directory as two levels up from script directory.
|
|
|
|
FISH_BASE_DIR="$( cd "$( dirname "$( dirname "$0" )" )" && pwd )"
|
2014-10-12 21:01:13 +08:00
|
|
|
DEF_VER=unknown
|
2022-05-26 15:28:49 +08:00
|
|
|
git_permission_failed=0
|
2013-06-24 18:09:29 +08:00
|
|
|
|
|
|
|
# First see if there is a version file (included in release tarballs),
|
|
|
|
# then try git-describe, then default.
|
|
|
|
if test -f version
|
|
|
|
then
|
|
|
|
VN=$(cat version) || VN="$DEF_VER"
|
2022-05-26 15:28:49 +08:00
|
|
|
else
|
|
|
|
if VN=$(git -C "$FISH_BASE_DIR" describe --always --dirty 2>/dev/null); then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
if test $? = 128; then
|
|
|
|
# Current git versions return status 128
|
|
|
|
# when run in a repo owned by another user.
|
|
|
|
# Even for describe and everything.
|
|
|
|
# This occurs for `sudo make install`.
|
|
|
|
git_permission_failed=1
|
|
|
|
fi
|
|
|
|
VN="$DEF_VER"
|
|
|
|
fi
|
2013-06-24 18:09:29 +08:00
|
|
|
fi
|
|
|
|
|
2019-01-28 10:32:37 +08:00
|
|
|
# If the first param is --stdout, then output to stdout and exit.
|
|
|
|
if test "$1" = '--stdout'
|
|
|
|
then
|
|
|
|
echo $VN
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set the output directory as either the first param or cwd.
|
|
|
|
test -n "$1" && OUTPUT_DIR=$1/ || OUTPUT_DIR=
|
2021-10-22 17:27:19 +08:00
|
|
|
FBVF="${OUTPUT_DIR}FISH-BUILD-VERSION-FILE"
|
2019-01-28 10:32:37 +08:00
|
|
|
|
2022-05-26 15:28:49 +08:00
|
|
|
if test "$VN" = unknown && test -r "$FBVF" && test "$git_permission_failed" = 1
|
|
|
|
then
|
|
|
|
# HACK: Git failed, so we keep the current version file.
|
|
|
|
# This helps in case you built fish as a normal user
|
|
|
|
# and then try to `sudo make install` it.
|
|
|
|
date +%s > ${OUTPUT_DIR}fish-build-version-witness.txt
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-10-22 17:27:19 +08:00
|
|
|
if test -r "$FBVF"
|
2013-06-24 18:09:29 +08:00
|
|
|
then
|
2021-10-22 17:27:19 +08:00
|
|
|
VC=$(grep -v '^#' "$FBVF" | tr -d '"' | sed -e 's/^FISH_BUILD_VERSION=//')
|
2013-06-24 18:09:29 +08:00
|
|
|
else
|
2019-11-29 03:24:12 +08:00
|
|
|
VC="unset"
|
2013-06-24 18:09:29 +08:00
|
|
|
fi
|
2018-01-08 17:39:45 +08:00
|
|
|
|
2018-06-02 01:48:03 +08:00
|
|
|
# Maybe output the FBVF
|
2018-01-09 14:29:34 +08:00
|
|
|
# It looks like FISH_BUILD_VERSION="2.7.1-621-ga2f065e6"
|
2013-06-24 18:09:29 +08:00
|
|
|
test "$VN" = "$VC" || {
|
2017-10-05 12:28:55 +08:00
|
|
|
echo >&2 "FISH_BUILD_VERSION=$VN"
|
2021-10-22 17:27:19 +08:00
|
|
|
echo "FISH_BUILD_VERSION=\"$VN\"" >"$FBVF"
|
2013-06-24 18:09:29 +08:00
|
|
|
}
|
2018-01-08 17:39:45 +08:00
|
|
|
|
|
|
|
# Output the fish-build-version-witness.txt
|
|
|
|
# See https://cmake.org/cmake/help/v3.4/policy/CMP0058.html
|
2018-08-28 23:10:10 +08:00
|
|
|
date +%s > ${OUTPUT_DIR}fish-build-version-witness.txt
|