-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.ml.gup
47 lines (42 loc) · 1.05 KB
/
version.ml.gup
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
#!bash -eu
set -o pipefail
if [ "${GUP_XTRACE:-0}" = 1 ]; then
set -x
fi
git_meta="../../.git"
gup -u ../../VERSION
if [ -e $git_meta ]; then
gup -u $git_meta/HEAD
head_ref="$(cat $git_meta/HEAD | grep -o 'refs/heads/.*' || true)"
if [ -n "$head_ref" ]; then
gup -u $git_meta/$head_ref
fi
commit="Some \"$(git rev-parse HEAD | cut -c -10)\""
else
gup --ifcreate $git_meta
commit="None"
fi
cat >"$1" <<EOF
module type Sig = sig
val version : string
end
module Make(Re:Re_ext.Sig) = struct
let version="$(cat ../../VERSION)"
let commit = $commit
let parse v =
let dot = Re.(regexp_string ".") in
let v =
try String.sub v 0 (String.rindex v '-')
with Not_found -> v in
let parts = Re.(split dot v) in
let parts = List.map int_of_string parts in
match parts with
| maj :: min :: patch :: _ -> (maj, min, patch)
| _ -> raise (Common.AssertionError ("unparseable version: " ^ v))
let minor (maj, min, _patch) = (maj, min)
let pretty () = match commit with
| Some c -> version ^ "-" ^ c
| None -> version
end
EOF
gup --contents "$1"