]> git.proxmox.com Git - debcargo-conf.git/blob - vars.sh.frag
wasm-bindgen-webidl: Initial packaging, v0.2.49
[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.[0123456789]|2.2.[0123456789]-*) abort 1 "unsupported debcargo version $dcver. try reinstalling with \`cargo install debcargo --force\`";;
39 2.2.*) true;;
40 2.3.*) true;;
41 2.4.*) true;;
42 *) abort 1 "unsupported debcargo version: $dcver";;
43 esac
44
45 if [ $# -ne 1 -a $# -ne 2 ]; then
46 echo >&2 "Usage: $0 <rust-crate-name>"
47 echo >&2 " $0 <rust-crate-name> <old-version>"
48 echo >&2 "See README.rst for more details on usage."
49 exit 2
50 fi
51
52 CRATE="$1"
53 VER="$2"
54
55 PKGNAME=${PKGNAME:-$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE")}
56 PKGBASE=$($DEBCARGO deb-src-name "$CRATE" || abort 1 "couldn't find crate $CRATE")
57 PKGDIR_REL="src/$PKGNAME"
58 PKGDIR="$PWD/$PKGDIR_REL"
59 BUILDDIR="$PWD/build/$PKGNAME"
60 PKGCFG="$PKGDIR/debian/debcargo.toml"
61
62 mkdir -p "$(dirname $BUILDDIR)"
63 cp "$PWD/build.sh" "$PWD/build/build.sh"
64 chmod +x "$PWD/build/build.sh"
65
66 if [ -z "$CRATE" ]; then
67 abort 2 "Usage: $0 <crate> [<version>]"
68 fi
69
70 run_debcargo() {
71 rm -rf "$BUILDDIR" "$(dirname "$BUILDDIR")/rust-${PKGNAME}_${REALVER:-$VER}"*.orig.tar.*
72 $DEBCARGO package --config "$PKGCFG" --directory "$BUILDDIR" "$@" "$CRATE" "${REALVER:-$VER}"
73 }
74
75 shouldbuild() {
76 local dst="$1"
77 local src="$2"
78 test ! -e "$dst" -o "$src" -nt "$dst"
79 }