]>
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;; | |
fb8affd9 | 19 | proxmox/*) true;; |
b6a1d240 XL |
20 | *) if git diff --cached --name-only | \ |
21 | grep '^src/.*/debian/changelog$' | \ | |
f830d4fb | 22 | while read x; do if ! [ -f "$x" ]; then continue; fi; echo "$x: $(head -n1 $x)"; done | \ |
b6a1d240 XL |
23 | grep -v UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then |
24 | echo >&2 "please don't finalise changelogs directly on the master branch, use ./release.sh instead"; exit 1; | |
25 | fi;; | |
26 | esac | |
27 | eof | |
28 | chmod +x "$HOOK_COMMIT" | |
29 | fi | |
30 | ||
23db3623 XL |
31 | if [ -n "$DEBCARGO" ]; then |
32 | true | |
f498b1c4 IJ |
33 | elif type -p debcargo >/dev/null 2>&1; then |
34 | DEBCARGO=$(type -p debcargo) | |
23db3623 XL |
35 | elif [ -f "$HOME/.cargo/bin/debcargo" ]; then |
36 | DEBCARGO="$HOME/.cargo/bin/debcargo" | |
37 | else | |
38 | abort 1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it" | |
39 | fi | |
40 | ||
41 | test -x "$DEBCARGO" || abort 1 "debcargo found but not executable: $DEBCARGO" | |
34c68b28 XL |
42 | dcver=$($DEBCARGO --version | sed -ne 's/debcargo //p') |
43 | case $dcver in | |
86d55e85 | 44 | 2.0.*|2.1.*|2.2.*|2.3.*) abort 1 "unsupported debcargo version $dcver. try reinstalling with \`cargo install debcargo --force\`";; |
5f4657b0 | 45 | 2.4.*) true;; |
02f99983 | 46 | 2.5.*) true;; |
59499285 | 47 | 2.6.*) true;; |
34c68b28 XL |
48 | *) abort 1 "unsupported debcargo version: $dcver";; |
49 | esac | |
23db3623 | 50 | |
32fc064c XL |
51 | if [ $# -ne 1 -a $# -ne 2 ]; then |
52 | echo >&2 "Usage: $0 <rust-crate-name>" | |
53 | echo >&2 " $0 <rust-crate-name> <old-version>" | |
54 | echo >&2 "See README.rst for more details on usage." | |
55 | exit 2 | |
56 | fi | |
57 | ||
999f9269 | 58 | CRATE="$1" |
ea9f59b2 | 59 | VER="$2" |
931eabc0 | 60 | |
609d97bd | 61 | if [ -n "$CRATE" -a -z "$VER" ] && grep -q crate_src_path "src/$CRATE/debian/debcargo.toml" 2>/dev/null; then |
5c6aa340 XL |
62 | # special hack for crate_src_path, could be cleaner... |
63 | PKGNAME="$CRATE" | |
64 | PKGBASE="$CRATE" | |
65 | else | |
66 | PKGNAME=${PKGNAME:-$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE")} | |
67 | PKGBASE=${PKGBASE:-$($DEBCARGO deb-src-name "$CRATE" || abort 1 "couldn't find crate $CRATE")} | |
68 | fi | |
69 | ||
931eabc0 XL |
70 | PKGDIR_REL="src/$PKGNAME" |
71 | PKGDIR="$PWD/$PKGDIR_REL" | |
72 | BUILDDIR="$PWD/build/$PKGNAME" | |
73 | PKGCFG="$PKGDIR/debian/debcargo.toml" | |
06485659 | 74 | UPLOADER="${DEBFULLNAME:-$NAME} <${DEBEMAIL:-$EMAIL}>" |
1230b71f XL |
75 | |
76 | mkdir -p "$(dirname $BUILDDIR)" | |
9cc53ba7 | 77 | ln -srf "$PWD/build.sh" "$PWD/build/build.sh" |
1057693c | 78 | chmod +x "$PWD/build/build.sh" |
1230b71f | 79 | |
999f9269 XL |
80 | if [ -z "$CRATE" ]; then |
81 | abort 2 "Usage: $0 <crate> [<version>]" | |
1230b71f | 82 | fi |
cc003c95 XL |
83 | |
84 | run_debcargo() { | |
f3600938 | 85 | rm -rf "$BUILDDIR" "$(dirname "$BUILDDIR")/rust-${PKGNAME}_${REALVER:-$VER}"*.orig.tar.* |
34712497 | 86 | set +e |
ba393157 | 87 | $DEBCARGO package --config "$PKGCFG" --directory "$BUILDDIR" "$@" "$CRATE" "${REALVER:-$VER}" |
34712497 SL |
88 | if [ $? -ne 0 ]; then |
89 | echo "Command failed. If the patches failed to apply, to rebase them, run": | |
90 | echo "cd $BUILDDIR" | |
91 | echo "rm -rf .pc" | |
92 | echo "ln -s $PKGDIR/debian/patches" | |
93 | echo "quilt push -a" | |
94 | echo "$EDITOR <file>" | |
95 | echo "quilt refresh" | |
96 | exit 1 | |
97 | fi | |
98 | set -e | |
cc003c95 | 99 | } |
b4e5b9dc XL |
100 | |
101 | shouldbuild() { | |
102 | local dst="$1" | |
103 | local src="$2" | |
104 | test ! -e "$dst" -o "$src" -nt "$dst" | |
105 | } | |
baae6f7c XL |
106 | |
107 | get_existing_version() { | |
108 | sed -nre "s/.*Package .* (.*) from crates.io.*/\1/gp" "$1/debian/changelog" | head -n1 | |
109 | } |