]> git.proxmox.com Git - debcargo-conf.git/blame - build.sh
build.sh: Allow building with extra packages
[debcargo-conf.git] / build.sh
CommitLineData
987288b3 1#!/bin/bash
1057693c
XL
2set -e
3
4abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; }
5
6if [ "$(basename "$PWD")" != "build" ]; then
7 abort 1 "This script is only meant to be run from the build/ directory."
8fi
9
10if [ -n "$DEBCARGO" ]; then
11 true
12elif which debcargo >/dev/null; then
13 DEBCARGO=$(which debcargo)
14elif [ -f "$HOME/.cargo/bin/debcargo" ]; then
15 DEBCARGO="$HOME/.cargo/bin/debcargo"
16else
17 abort 1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it"
18fi
19
20CRATE="$1"
21VER="$2"
987288b3
XL
22if test -z "$VER" -o -f "$VER"; then
23 VER=""
24 shift
25else
26 shift 2
27fi
1057693c
XL
28DISTRIBUTION="${DISTRIBUTION:-unstable}"
29
30PKGNAME=$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE")
31DEBVER=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SVersion)
32DEBSRC=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SSource)
33DEBDIST=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SDistribution)
34DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH)
35if [ -z "$CHROOT" ] && schroot -i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then
36 CHROOT="debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
37fi
38
39shouldbuild() {
40 local dst="$1"
41 local src="$2"
42 test ! -e "$dst" -o "$src" -nt "$dst"
43}
44
45if shouldbuild ${DEBSRC}_${DEBVER}.dsc "$PKGNAME/debian/changelog" ]; then
46 ( cd "$PKGNAME" && dpkg-buildpackage -d -S --no-sign )
47 # sign if not UNRELEASED
48 if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
49 debsign ${DEBSRC}_${DEBVER}_source.changes
50 fi
51fi
52
53check_build_deps() {
54 mkdir -p dpkg-dummy
55 if shouldbuild dpkg-dummy/status /var/cache/apt/pkgcache.bin; then
56 # pretend dpkg status file that marks all packages as installed
57 # this is because dpkg-checkbuilddeps only works on installed pkgs
58 apt-cache dumpavail | \
59 sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy/status
60 fi
c7386c93 61 ( cd "$PKGNAME" && dpkg-checkbuilddeps --admindir=../dpkg-dummy )
1057693c
XL
62}
63
64if ! check_build_deps; then
581335d2
XL
65 if [ "$IGNORE_MISSING_BUILD_DEPS" != 1 ]; then
66 abort 1 "Missing build-dependencies, but maybe try '{apt,cargo} update'"
67 fi
1057693c
XL
68fi
69
70if [ "$SOURCEONLY" = 1 ]; then
71 exit
72fi
73
987288b3
XL
74sbuild --no-source --arch-any --arch-all \
75 ${CHROOT:+-c $CHROOT} \
76 ${DISTRIBUTION:+-d $DISTRIBUTION} \
77 ${@/#/--extra-package=} \
78 ${DEBSRC}_${DEBVER}.dsc
1057693c
XL
79changestool ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes adddsc ${DEBSRC}_${DEBVER}.dsc
80
81# sign if not UNRELEASED
82if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
83 debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes
84fi