]> git.proxmox.com Git - debcargo-conf.git/blame - vars.sh.frag
dunce: new upstream release
[debcargo-conf.git] / vars.sh.frag
CommitLineData
9cfc4370 1# -*- mode: sh -*-
5e18ef4f
XL
2# Common shell utilities.
3#
4# Envvars:
5# DEBCARGO
6# Path to debcargo. Set this to use your custom version, e.g. from git.
931eabc0
XL
7set -e
8
999f9269 9abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; }
88f8e3e6 10
cfc28aec 11mkdir -p "$(dirname "$0")/.git/hooks"
b6a1d240
XL
12HOOK_COMMIT="$(dirname "$0")/.git/hooks/pre-commit"
13if [ ! -x "$HOOK_COMMIT" ]; then
14cat <<'eof' >"$HOOK_COMMIT"
15#!/bin/sh
16if git rev-parse -q --verify MERGE_HEAD; then exit; fi
17case $(git rev-parse --abbrev-ref HEAD) in
18pending-*) true;;
19*) if git diff --cached --name-only | \
20 grep '^src/.*/debian/changelog$' | \
f830d4fb 21 while read x; do if ! [ -f "$x" ]; then continue; fi; echo "$x: $(head -n1 $x)"; done | \
b6a1d240
XL
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;;
25esac
26eof
27chmod +x "$HOOK_COMMIT"
28fi
29
23db3623
XL
30if [ -n "$DEBCARGO" ]; then
31 true
f498b1c4
IJ
32elif type -p debcargo >/dev/null 2>&1; then
33 DEBCARGO=$(type -p debcargo)
23db3623
XL
34elif [ -f "$HOME/.cargo/bin/debcargo" ]; then
35 DEBCARGO="$HOME/.cargo/bin/debcargo"
36else
37 abort 1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it"
38fi
39
40test -x "$DEBCARGO" || abort 1 "debcargo found but not executable: $DEBCARGO"
34c68b28
XL
41dcver=$($DEBCARGO --version | sed -ne 's/debcargo //p')
42case $dcver in
86d55e85 432.0.*|2.1.*|2.2.*|2.3.*) abort 1 "unsupported debcargo version $dcver. try reinstalling with \`cargo install debcargo --force\`";;
5f4657b0 442.4.*) true;;
02f99983 452.5.*) true;;
59499285 462.6.*) true;;
34c68b28
XL
47*) abort 1 "unsupported debcargo version: $dcver";;
48esac
23db3623 49
32fc064c
XL
50if [ $# -ne 1 -a $# -ne 2 ]; then
51 echo >&2 "Usage: $0 <rust-crate-name>"
52 echo >&2 " $0 <rust-crate-name> <old-version>"
53 echo >&2 "See README.rst for more details on usage."
54 exit 2
55fi
56
999f9269 57CRATE="$1"
ea9f59b2 58VER="$2"
931eabc0 59
609d97bd 60if [ -n "$CRATE" -a -z "$VER" ] && grep -q crate_src_path "src/$CRATE/debian/debcargo.toml" 2>/dev/null; then
5c6aa340
XL
61 # special hack for crate_src_path, could be cleaner...
62 PKGNAME="$CRATE"
63 PKGBASE="$CRATE"
64else
65 PKGNAME=${PKGNAME:-$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE")}
66 PKGBASE=${PKGBASE:-$($DEBCARGO deb-src-name "$CRATE" || abort 1 "couldn't find crate $CRATE")}
67fi
68
931eabc0
XL
69PKGDIR_REL="src/$PKGNAME"
70PKGDIR="$PWD/$PKGDIR_REL"
71BUILDDIR="$PWD/build/$PKGNAME"
72PKGCFG="$PKGDIR/debian/debcargo.toml"
1230b71f
XL
73
74mkdir -p "$(dirname $BUILDDIR)"
9cc53ba7 75ln -srf "$PWD/build.sh" "$PWD/build/build.sh"
1057693c 76chmod +x "$PWD/build/build.sh"
1230b71f 77
999f9269
XL
78if [ -z "$CRATE" ]; then
79 abort 2 "Usage: $0 <crate> [<version>]"
1230b71f 80fi
cc003c95
XL
81
82run_debcargo() {
f3600938 83 rm -rf "$BUILDDIR" "$(dirname "$BUILDDIR")/rust-${PKGNAME}_${REALVER:-$VER}"*.orig.tar.*
34712497 84 set +e
ba393157 85 $DEBCARGO package --config "$PKGCFG" --directory "$BUILDDIR" "$@" "$CRATE" "${REALVER:-$VER}"
34712497
SL
86 if [ $? -ne 0 ]; then
87 echo "Command failed. If the patches failed to apply, to rebase them, run":
88 echo "cd $BUILDDIR"
89 echo "rm -rf .pc"
90 echo "ln -s $PKGDIR/debian/patches"
91 echo "quilt push -a"
92 echo "$EDITOR <file>"
93 echo "quilt refresh"
94 exit 1
95 fi
96 set -e
cc003c95 97}
b4e5b9dc
XL
98
99shouldbuild() {
100 local dst="$1"
101 local src="$2"
102 test ! -e "$dst" -o "$src" -nt "$dst"
103}
baae6f7c
XL
104
105get_existing_version() {
106 sed -nre "s/.*Package .* (.*) from crates.io.*/\1/gp" "$1/debian/changelog" | head -n1
107}