]> arthur.barton.de Git - bup.git/blob - configure-version
configure-version: completely handle _version.py
[bup.git] / configure-version
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 top="$(pwd)"
6 readonly top
7
8 usage()
9 {
10     echo 'Usage: ./configure-version [--update | --clean]'
11 }
12
13 update-vpy()
14 {
15     declare -r vpy=lib/bup/_version.py
16     rm -f $vpy.tmp-$$
17     local hash date desc
18     hash=$(git log -1 --pretty=format:%H)
19     date=$(git log -1 --pretty=format:%ci)
20     desc=$(git describe --always --match="[0-9]*")
21     cat > $vpy.tmp-$$ <<-EOF
22         COMMIT='$hash'
23         NAMES='(tag: bup-$desc)'
24         DATE='$date'
25         EOF
26     if ! test -e $vpy || ! cmp -s $vpy $vpy.tmp-$$; then
27         mv $vpy.tmp-$$ $vpy;
28     fi
29     rm -f $vpy.tmp-$$
30 }
31
32 if test "$#" -ne 1; then
33     usage 1>&2; exit 1
34 fi
35
36 if ! test -f lib/bup/bupsplit.c; then
37     echo 'error: cannot find bup source tree' 1>&2
38     exit 1
39 fi
40
41 case "$1" in
42     --update)
43         update-vpy
44         ;;
45     --clean)
46         rm -f lib/bup/_version.py lib/bup/_version.pyc lib/bup/_version.py.tmp-*
47         ;;
48     *)
49         usage 1>&2; exit 1
50         ;;
51 esac