File: git_version_gen.sh

package info (click to toggle)
fish 4.2.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 35,980 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (70 lines) | stat: -rwxr-xr-x 1,919 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# 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>

set -e

# Find the fish directory as two levels up from script directory.
FISH_BASE_DIR="$( cd "$( dirname "$( dirname "$0" )" )" && pwd )"
DEF_VER=unknown
git_permission_failed=0

# 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"
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
fi

# 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=
FBVF="${OUTPUT_DIR}FISH-BUILD-VERSION-FILE"

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

if test -r "$FBVF"
then
	VC=$(cat "$FBVF")
else
	VC="unset"
fi

# Maybe output the FBVF
# It looks like "2.7.1-621-ga2f065e6"
test "$VN" = "$VC" || {
	echo >&2 "$VN"
	echo "$VN" >"$FBVF"
}

# Output the fish-build-version-witness.txt
# See https://cmake.org/cmake/help/v3.4/policy/CMP0058.html
date +%s > "${OUTPUT_DIR}"fish-build-version-witness.txt