]> git.proxmox.com Git - debcargo-conf.git/blob - build.sh
Merge remote-tracking branch 'origin/pending-difference'
[debcargo-conf.git] / build.sh
1 #!/bin/bash
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"
22 if test -z "$VER" -o -f "$VER"; then
23 VER=""
24 shift
25 else
26 shift 2
27 fi
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
46 ( cd "$PKGNAME" && dpkg-buildpackage -d -S --no-sign )
47 if [ "$REUSE_EXISTING_ORIG_TARBALL" = 1 ]; then
48 UPSVER="${DEBVER%-*}"
49 mv "${DEBSRC}_${UPSVER}.orig.tar.gz" "${DEBSRC}_${UPSVER}.orig.tar.gz.new"
50 apt-get -t unstable source "${DEBSRC}" # "=${DEBVER}"
51 # check that old tarball contains same contents as new tarball
52 diff -q <(zcat "${DEBSRC}_${UPSVER}.orig.tar.gz.new") <(zcat "${DEBSRC}_${UPSVER}.orig.tar.gz")
53 ( cd "$PKGNAME" && dpkg-buildpackage -d -S --no-sign )
54 fi
55 # sign if not UNRELEASED
56 if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
57 debsign ${DEBSRC}_${DEBVER}_source.changes
58 fi
59 fi
60
61 check_build_deps() {
62 mkdir -p dpkg-dummy
63 if shouldbuild dpkg-dummy/status /var/cache/apt/pkgcache.bin; then
64 # pretend dpkg status file that marks all packages as installed
65 # this is because dpkg-checkbuilddeps only works on installed pkgs
66 apt-cache dumpavail -o APT::Default-Release=unstable | \
67 sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy/status
68 fi
69 ( cd "$PKGNAME" && dpkg-checkbuilddeps --admindir=../dpkg-dummy )
70 }
71
72 if ! check_build_deps; then
73 if [ "$IGNORE_MISSING_BUILD_DEPS" != 1 ]; then
74 abort 1 "Missing build-dependencies, but maybe try '{apt,cargo} update'"
75 fi
76 fi
77
78 if [ "$SOURCEONLY" = 1 ]; then
79 exit
80 fi
81
82 sbuild --no-source --arch-any --arch-all \
83 ${CHROOT:+-c $CHROOT} \
84 ${DISTRIBUTION:+-d $DISTRIBUTION} \
85 ${@/#/--extra-package=} \
86 ${DEBSRC}_${DEBVER}.dsc
87 changestool ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes adddsc ${DEBSRC}_${DEBVER}.dsc
88
89 # sign if not UNRELEASED
90 if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
91 debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes
92 fi