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