forked from neovim/neovim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpkg.macros
80 lines (63 loc) · 2.13 KB
/
rpkg.macros
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
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# backward compat since cached function went away
# https://pagure.io/rpkg-util/c/bb62554c62fd52224709e861c2353a5c15b50220?branch=master
function cached {
declare v=${OUTPUT[$1]}
[[ -n $v ]] && echo -n "$v"
}
function get_cmake_var {
declare v
v=$(grep -m1 "^set($1\\s" <CMakeLists.txt)
v=$(sed -E 's/^\S+\s+"?//; s/[")].*//' <<<"$v")
[[ -n $v ]] && echo "$v" || abort "can't get $1"
}
function neovim_dev_version {
cached neovim_dev_version && return
declare major minor patch pre
major=$(get_cmake_var NVIM_VERSION_MAJOR) || exit
minor=$(get_cmake_var NVIM_VERSION_MINOR) || exit
patch=$(get_cmake_var NVIM_VERSION_PATCH) || exit
pre=$(get_cmake_var NVIM_VERSION_PRERELEASE) || exit
# git describe --first-parent origin/master
# v0.4.0-1080-g971e0ca90
declare describe tag commits hash
describe=$(git describe --first-parent --long origin/master)
read tag commits hash <<<"${describe//-/ }"
[[ $tag == v* && $commits =~ ^[0-9]+$ && -n $hash ]] || abort "failed git describe"
output "v$major.$minor.$patch$pre+$commits-$hash"
}
function git_version {
cached git_version && return
neovim_dev_version &>/dev/null # preload cache w/o command subst
declare v
v=$(neovim_dev_version) # v0.5.0-dev+1080-g971e0ca90
v=${v#v} # 0.5.0-dev+1080-g971e0ca90
v=${v/-/\~} # 0.5.0~dev+1080-g971e0ca90
v=${v//[+-]/.} # 0.5.0~dev.1080.g971e0ca90
output "$v"
}
function git_revision {
cached git_revision && return
# find last merge
declare last_merge rest
read last_merge rest <<<"$(git log --merges --oneline -n1)"
[[ -n $last_merge ]] || abort "failed to find last merge"
# count commits since last merge, might be zero
declare count
count=$(git log --oneline HEAD "^$last_merge" | wc -l)
output "$((count + 1))"
}
function git_changelog_date {
cached git_changelog_date && return
output "$(date +'%a %b %d %Y')"
}
function git_changelog_version {
cached git_changelog_version && return
git_version &>/dev/null # cache
git_revision &>/dev/null # cache
output "$(git_version)-$(git_revision)"
}
function abort {
echo "ABORT: $*" >&2
exit 1
}