]> git.proxmox.com Git - debcargo-conf.git/blob - vars.sh.frag
Merge branches 'pending-chrono', 'pending-quickcheck-macros', 'pending-quick-xml...
[debcargo-conf.git] / vars.sh.frag
1 # -*- mode: sh -*-
2 set -e
3
4 abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; }
5
6 mkdir -p "$(dirname "$0")/.git/hooks"
7 HOOK_COMMIT="$(dirname "$0")/.git/hooks/pre-commit"
8 if [ ! -x "$HOOK_COMMIT" ]; then
9 cat <<'eof' >"$HOOK_COMMIT"
10 #!/bin/sh
11 if git rev-parse -q --verify MERGE_HEAD; then exit; fi
12 case $(git rev-parse --abbrev-ref HEAD) in
13 pending-*) true;;
14 *) if git diff --cached --name-only | \
15 grep '^src/.*/debian/changelog$' | \
16 while read x; do if ! [ -f "$x" ]; then continue; fi; echo "$x: $(head -n1 $x)"; done | \
17 grep -v UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
18 echo >&2 "please don't finalise changelogs directly on the master branch, use ./release.sh instead"; exit 1;
19 fi;;
20 esac
21 eof
22 chmod +x "$HOOK_COMMIT"
23 fi
24
25 if [ -n "$DEBCARGO" ]; then
26 true
27 elif which debcargo >/dev/null; then
28 DEBCARGO=$(which debcargo)
29 elif [ -f "$HOME/.cargo/bin/debcargo" ]; then
30 DEBCARGO="$HOME/.cargo/bin/debcargo"
31 else
32 abort 1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it"
33 fi
34
35 test -x "$DEBCARGO" || abort 1 "debcargo found but not executable: $DEBCARGO"
36 dcver=$($DEBCARGO --version | sed -ne 's/debcargo //p')
37 case $dcver in
38 2.0.*|2.1.*|2.2.*|2.3.*) abort 1 "unsupported debcargo version $dcver. try reinstalling with \`cargo install debcargo --force\`";;
39 2.4.*) true;;
40 *) abort 1 "unsupported debcargo version: $dcver";;
41 esac
42
43 if [ $# -ne 1 -a $# -ne 2 ]; then
44 echo >&2 "Usage: $0 <rust-crate-name>"
45 echo >&2 " $0 <rust-crate-name> <old-version>"
46 echo >&2 "See README.rst for more details on usage."
47 exit 2
48 fi
49
50 CRATE="$1"
51 VER="$2"
52
53 PKGNAME=${PKGNAME:-$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE")}
54 PKGBASE=$($DEBCARGO deb-src-name "$CRATE" || abort 1 "couldn't find crate $CRATE")
55 PKGDIR_REL="src/$PKGNAME"
56 PKGDIR="$PWD/$PKGDIR_REL"
57 BUILDDIR="$PWD/build/$PKGNAME"
58 PKGCFG="$PKGDIR/debian/debcargo.toml"
59
60 mkdir -p "$(dirname $BUILDDIR)"
61 ln -srf "$PWD/build.sh" "$PWD/build/build.sh"
62 chmod +x "$PWD/build/build.sh"
63
64 if [ -z "$CRATE" ]; then
65 abort 2 "Usage: $0 <crate> [<version>]"
66 fi
67
68 run_debcargo() {
69 rm -rf "$BUILDDIR" "$(dirname "$BUILDDIR")/rust-${PKGNAME}_${REALVER:-$VER}"*.orig.tar.*
70 $DEBCARGO package --config "$PKGCFG" --directory "$BUILDDIR" "$@" "$CRATE" "${REALVER:-$VER}"
71 }
72
73 shouldbuild() {
74 local dst="$1"
75 local src="$2"
76 test ! -e "$dst" -o "$src" -nt "$dst"
77 }
78
79 get_existing_version() {
80 sed -nre "s/.*Package .* (.*) from crates.io.*/\1/gp" "$1/debian/changelog" | head -n1
81 }