]>
Commit | Line | Data |
---|---|---|
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 |
7 | set -e |
8 | ||
999f9269 | 9 | abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; } |
88f8e3e6 | 10 | |
cfc28aec | 11 | mkdir -p "$(dirname "$0")/.git/hooks" |
b6a1d240 XL |
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$' | \ | |
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;; | |
25 | esac | |
26 | eof | |
27 | chmod +x "$HOOK_COMMIT" | |
28 | fi | |
29 | ||
23db3623 XL |
30 | if [ -n "$DEBCARGO" ]; then |
31 | true | |
f498b1c4 IJ |
32 | elif type -p debcargo >/dev/null 2>&1; then |
33 | DEBCARGO=$(type -p debcargo) | |
23db3623 XL |
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" | |
34c68b28 XL |
41 | dcver=$($DEBCARGO --version | sed -ne 's/debcargo //p') |
42 | case $dcver in | |
86d55e85 | 43 | 2.0.*|2.1.*|2.2.*|2.3.*) abort 1 "unsupported debcargo version $dcver. try reinstalling with \`cargo install debcargo --force\`";; |
5f4657b0 | 44 | 2.4.*) true;; |
02f99983 | 45 | 2.5.*) true;; |
59499285 | 46 | 2.6.*) true;; |
34c68b28 XL |
47 | *) abort 1 "unsupported debcargo version: $dcver";; |
48 | esac | |
23db3623 | 49 | |
32fc064c XL |
50 | if [ $# -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 | |
55 | fi | |
56 | ||
999f9269 | 57 | CRATE="$1" |
ea9f59b2 | 58 | VER="$2" |
931eabc0 | 59 | |
609d97bd | 60 | if [ -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" | |
64 | else | |
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")} | |
67 | fi | |
68 | ||
931eabc0 XL |
69 | PKGDIR_REL="src/$PKGNAME" |
70 | PKGDIR="$PWD/$PKGDIR_REL" | |
71 | BUILDDIR="$PWD/build/$PKGNAME" | |
72 | PKGCFG="$PKGDIR/debian/debcargo.toml" | |
06485659 | 73 | UPLOADER="${DEBFULLNAME:-$NAME} <${DEBEMAIL:-$EMAIL}>" |
1230b71f XL |
74 | |
75 | mkdir -p "$(dirname $BUILDDIR)" | |
9cc53ba7 | 76 | ln -srf "$PWD/build.sh" "$PWD/build/build.sh" |
1057693c | 77 | chmod +x "$PWD/build/build.sh" |
1230b71f | 78 | |
999f9269 XL |
79 | if [ -z "$CRATE" ]; then |
80 | abort 2 "Usage: $0 <crate> [<version>]" | |
1230b71f | 81 | fi |
cc003c95 XL |
82 | |
83 | run_debcargo() { | |
f3600938 | 84 | rm -rf "$BUILDDIR" "$(dirname "$BUILDDIR")/rust-${PKGNAME}_${REALVER:-$VER}"*.orig.tar.* |
34712497 | 85 | set +e |
ba393157 | 86 | $DEBCARGO package --config "$PKGCFG" --directory "$BUILDDIR" "$@" "$CRATE" "${REALVER:-$VER}" |
34712497 SL |
87 | if [ $? -ne 0 ]; then |
88 | echo "Command failed. If the patches failed to apply, to rebase them, run": | |
89 | echo "cd $BUILDDIR" | |
90 | echo "rm -rf .pc" | |
91 | echo "ln -s $PKGDIR/debian/patches" | |
92 | echo "quilt push -a" | |
93 | echo "$EDITOR <file>" | |
94 | echo "quilt refresh" | |
95 | exit 1 | |
96 | fi | |
97 | set -e | |
cc003c95 | 98 | } |
b4e5b9dc XL |
99 | |
100 | shouldbuild() { | |
101 | local dst="$1" | |
102 | local src="$2" | |
103 | test ! -e "$dst" -o "$src" -nt "$dst" | |
104 | } | |
baae6f7c XL |
105 | |
106 | get_existing_version() { | |
107 | sed -nre "s/.*Package .* (.*) from crates.io.*/\1/gp" "$1/debian/changelog" | head -n1 | |
108 | } |