]>
Commit | Line | Data |
---|---|---|
987288b3 | 1 | #!/bin/bash |
1057693c XL |
2 | set -e |
3 | ||
4 | abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; } | |
5 | ||
6 | if [ "$(basename "$PWD")" != "build" ]; then | |
7 | abort 1 "This script is only meant to be run from the build/ directory." | |
8 | fi | |
9 | ||
10 | if [ -n "$DEBCARGO" ]; then | |
11 | true | |
12 | elif which debcargo >/dev/null; then | |
13 | DEBCARGO=$(which debcargo) | |
14 | elif [ -f "$HOME/.cargo/bin/debcargo" ]; then | |
15 | DEBCARGO="$HOME/.cargo/bin/debcargo" | |
16 | else | |
17 | abort 1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it" | |
18 | fi | |
19 | ||
20 | CRATE="$1" | |
21 | VER="$2" | |
987288b3 XL |
22 | if test -z "$VER" -o -f "$VER"; then |
23 | VER="" | |
24 | shift | |
25 | else | |
26 | shift 2 | |
27 | fi | |
1057693c XL |
28 | DISTRIBUTION="${DISTRIBUTION:-unstable}" |
29 | ||
30 | PKGNAME=$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE") | |
31 | DEBVER=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SVersion) | |
32 | DEBSRC=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SSource) | |
33 | DEBDIST=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SDistribution) | |
34 | DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH) | |
35 | if [ -z "$CHROOT" ] && schroot -i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then | |
36 | CHROOT="debcargo-unstable-${DEB_HOST_ARCH}-sbuild" | |
37 | fi | |
38 | ||
39 | shouldbuild() { | |
40 | local dst="$1" | |
41 | local src="$2" | |
42 | test ! -e "$dst" -o "$src" -nt "$dst" | |
43 | } | |
44 | ||
45 | if shouldbuild ${DEBSRC}_${DEBVER}.dsc "$PKGNAME/debian/changelog" ]; then | |
2f1d8dc5 XL |
46 | if [ "$REUSE_EXISTING_ORIG_TARBALL" = 1 ]; then |
47 | UPSVER="${DEBVER%-*}" | |
48 | mv "${DEBSRC}_${UPSVER}.orig.tar.gz" "${DEBSRC}_${UPSVER}.orig.tar.gz.new" | |
551c3a83 | 49 | apt-get -t unstable source --download-only "${DEBSRC}" # "=${DEBVER}" |
2f1d8dc5 | 50 | # check that old tarball contains same contents as new tarball |
a0c73b1a XL |
51 | if ! diff -ru \ |
52 | --label "${DEBSRC}_${UPSVER}.orig.tar.gz.new" \ | |
53 | <(zcat "${DEBSRC}_${UPSVER}.orig.tar.gz.new" | tar -tvvf-) \ | |
54 | --label "${DEBSRC}_${UPSVER}.orig.tar.gz" \ | |
55 | <(zcat "${DEBSRC}_${UPSVER}.orig.tar.gz" | tar -tvvf-); then | |
56 | read -p "contents differ, continue with old tarball or abort? [y/N] " x | |
57 | if [ "$x" != "y" ]; then exit 1; fi | |
58 | fi | |
551c3a83 XL |
59 | # extract old tarball into new directory, to avoid "modified files" problems with dpkg-source later |
60 | ( cd "$PKGNAME" && dpkg-source --after-build . && tar --strip-components=1 -xf "../${DEBSRC}_${UPSVER}.orig.tar.gz" ) | |
2f1d8dc5 | 61 | fi |
551c3a83 | 62 | ( cd "$PKGNAME" && dpkg-buildpackage -d -S --no-sign ) |
1057693c XL |
63 | # sign if not UNRELEASED |
64 | if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then | |
65 | debsign ${DEBSRC}_${DEBVER}_source.changes | |
66 | fi | |
67 | fi | |
68 | ||
69 | check_build_deps() { | |
70 | mkdir -p dpkg-dummy | |
71 | if shouldbuild dpkg-dummy/status /var/cache/apt/pkgcache.bin; then | |
72 | # pretend dpkg status file that marks all packages as installed | |
73 | # this is because dpkg-checkbuilddeps only works on installed pkgs | |
60864af1 | 74 | apt-cache dumpavail -o APT::Default-Release=unstable | \ |
1057693c | 75 | sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy/status |
89617f5c XL |
76 | if ! test -s dpkg-dummy/status; then |
77 | echo >&2 "couldn't generate dpkg-dummy/status, is Debian unstable in your APT sources?" | |
78 | exit 1 | |
79 | fi | |
1057693c | 80 | fi |
c7386c93 | 81 | ( cd "$PKGNAME" && dpkg-checkbuilddeps --admindir=../dpkg-dummy ) |
1057693c XL |
82 | } |
83 | ||
84 | if ! check_build_deps; then | |
581335d2 XL |
85 | if [ "$IGNORE_MISSING_BUILD_DEPS" != 1 ]; then |
86 | abort 1 "Missing build-dependencies, but maybe try '{apt,cargo} update'" | |
87 | fi | |
1057693c XL |
88 | fi |
89 | ||
90 | if [ "$SOURCEONLY" = 1 ]; then | |
91 | exit | |
92 | fi | |
93 | ||
987288b3 XL |
94 | sbuild --no-source --arch-any --arch-all \ |
95 | ${CHROOT:+-c $CHROOT} \ | |
96 | ${DISTRIBUTION:+-d $DISTRIBUTION} \ | |
97 | ${@/#/--extra-package=} \ | |
98 | ${DEBSRC}_${DEBVER}.dsc | |
1057693c XL |
99 | changestool ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes adddsc ${DEBSRC}_${DEBVER}.dsc |
100 | ||
101 | # sign if not UNRELEASED | |
102 | if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then | |
103 | debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes | |
104 | fi |