Debian Codegraph @

GIT-VERSION-GEN

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 DEF_VER=v2.55.0
4
5 LF='
6 '
7
8 if testscip-shell system . . test. "$#" -lt 2 || testscip-shell system . . test. "$#" -gt 3
9 then
10 echoscip-shell system . . echo. >&2 "USAGE: $0 <SOURCE_DIR> (--format=<STRING>|<INPUT>) [<OUTPUT>]"
11 exit 1
12 fi
13
14 SOURCE_DIR="$1"
15
16 case "$2" in
17 --format=*)
18 INPUT="${2#--format=}"
19 ;;
20 *)
21 if ! testscip-shell system . . test. -f "$2"
22 then
23 echoscip-shell system . . echo. >&2 "Input is not a file: $2"
24 exit 1
25 fi
26 INPUT=$(catscip-shell system . . cat. "$2")
27 ;;
28 esac
29
30 OUTPUT="$3"
31
32 # Protect us from reading Git version information outside of the Git directory
33 # in case it is not a repository itself, but embedded in an unrelated
34 # repository.
35 GIT_CEILING_DIRECTORIES="$SOURCE_DIR/.."
36 export GIT_CEILING_DIRECTORIES
37
38 if testscip-shell system . . test. -z "$GIT_VERSION"
39 then
40 # First see if there is a version file (included in release tarballs),
41 # then try git-describe, then default.
42 if testscip-shell system . . test. -f "$SOURCE_DIR"/version
43 then
44 VN=$(catscip-shell system . . cat. "$SOURCE_DIR"/version) || VN="$DEF_VER"
45 elif {
46 testscip-shell system . . test. -d "$SOURCE_DIR/.git" ||
47 testscip-shell system . . test. -d "${GIT_DIR:-.git}" ||
48 testscip-shell system . . test. -f "$SOURCE_DIR"/.git;
49 } &&
50 VN=$(gitscip-shell system . . git. -C "$SOURCE_DIR" describe --dirty --match="v[0-9]*" 2>/dev/nullscip-shell filesystem . . `/dev/null`.) &&
51 case "$VN" in
52 *$LF*) (exit 1) ;;
53 esac
54 then
55 VN=$(echoscip-shell system . . echo. "$VN" | sedscip-shell system . . sed. -e 's/-/./g');
56 else
57 VN="$DEF_VER"
58 fi
59
60 GIT_VERSION=$(exprscip-shell system . . expr. "$VN" : v*'\(.*\)')
61 fi
62
63 if testscip-shell system . . test. -z "$GIT_BUILT_FROM_COMMIT"
64 then
65 GIT_BUILT_FROM_COMMIT=$(gitscip-shell system . . git. -C "$SOURCE_DIR" rev-parse -q --verify HEAD 2>/dev/nullscip-shell filesystem . . `/dev/null`.)
66 fi
67
68 if testscip-shell system . . test. -z "$GIT_DATE"
69 then
70 GIT_DATE=$(gitscip-shell system . . git. -C "$SOURCE_DIR" show --quiet --format='%as' 2>/dev/nullscip-shell filesystem . . `/dev/null`.)
71 fi
72
73 if testscip-shell system . . test. -z "$GIT_USER_AGENT"
74 then
75 GIT_USER_AGENT="git/$GIT_VERSION"
76 fi
77
78 # While released Git versions only have three numbers, development builds also
79 # have a fourth number that corresponds to the number of patches since the last
80 # release.
81 read GIT_MAJOR_VERSION GIT_MINOR_VERSION GIT_MICRO_VERSION GIT_PATCH_LEVEL trailing <<EOF
82 $(echoscip-shell system . . echo. "$GIT_VERSION" 0 0 0 0 | trscip-shell system . . tr. '.a-zA-Z-' ' ')
83 EOF
84
85 REPLACED=$(printfscip-shell system . . printf. "%s\n" "$INPUT" | sedscip-shell system . . sed. -e "s|@GIT_VERSION@|$GIT_VERSION|" \
86 -e "s|@GIT_MAJOR_VERSION@|$GIT_MAJOR_VERSION|" \
87 -e "s|@GIT_MINOR_VERSION@|$GIT_MINOR_VERSION|" \
88 -e "s|@GIT_MICRO_VERSION@|$GIT_MICRO_VERSION|" \
89 -e "s|@GIT_PATCH_LEVEL@|$GIT_PATCH_LEVEL|" \
90 -e "s|@GIT_BUILT_FROM_COMMIT@|$GIT_BUILT_FROM_COMMIT|" \
91 -e "s|@GIT_USER_AGENT@|$GIT_USER_AGENT|" \
92 -e "s|@GIT_DATE@|$GIT_DATE|"
93 )
94
95 if testscip-shell system . . test. -z "$OUTPUT"
96 then
97 printfscip-shell system . . printf. "%s\n" "$REPLACED"
98 else
99 printfscip-shell system . . printf. "%s\n" "$REPLACED" >"$OUTPUT".$$+
100 if ! testscip-shell system . . test. -f "$OUTPUT" || ! cmpscip-shell system . . cmp. "$OUTPUT".$$+ "$OUTPUT" >/dev/nullscip-shell filesystem . . `/dev/null`.
101 then
102 mvscip-shell system . . mv. "$OUTPUT".$$+ "$OUTPUT"
103 else
104 rmscip-shell system . . rm. "$OUTPUT".$$+
105 fi
106 fi