]> git.proxmox.com Git - debcargo-conf.git/blob - build.sh
Merge remote-tracking branch 'origin/pending-chrono'
[debcargo-conf.git] / build.sh
1 #!/bin/bash
2 set -e
3
4 SCRIPTDIR="$(dirname $(readlink -f "$0"))"
5
6 abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; }
7 report() { for i in "$@"; do echo >&2 "debcargo-conf builder: $i"; done; }
8
9 if [ "$(basename "$PWD")" != "build" ]; then
10 abort 1 "This script is only meant to be run from the build/ directory."
11 fi
12
13 if [ -n "$DEBCARGO" ]; then
14 true
15 elif which debcargo >/dev/null; then
16 DEBCARGO=$(which debcargo)
17 elif [ -f "$HOME/.cargo/bin/debcargo" ]; then
18 DEBCARGO="$HOME/.cargo/bin/debcargo"
19 else
20 abort 1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it"
21 fi
22
23 CRATE="$1"
24 VER="$2"
25 if test -z "$VER" -o -f "$VER"; then
26 VER=""
27 shift
28 else
29 shift 2
30 fi
31 DISTRIBUTION="${DISTRIBUTION:-unstable}"
32
33 PKGNAME=$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE")
34 DEBVER=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SVersion)
35 DEBSRC=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SSource)
36 DEBDIST=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SDistribution)
37 DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH)
38 SRCNAME="${DEBSRC}_${DEBVER}"
39 BUILDNAME="${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}"
40 if [ -z "$CHROOT" ]; then
41 if schroot -i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then
42 CHROOT="debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
43 elif schroot -i -c "unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then
44 CHROOT="unstable-${DEB_HOST_ARCH}-sbuild"
45 echo >&2 "Automatically using sbuild chroot unstable-${DEB_HOST_ARCH}-sbuild; however it's"
46 echo >&2 "strongly recommended to create a separate chroot debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
47 echo >&2 "so your builds won't have to re-download & re-install cargo, rustc, and llvm every time."
48 echo >&2 "See README.rst section \"Build environment\" for details."
49 sleep 1
50 elif [ "$SOURCEONLY" != 1 ]; then
51 abort 1 "could not automatically find a suitable chroot; set CHROOT"
52 fi
53 fi
54
55 shouldbuild() {
56 local dst="$1"
57 local src="$2"
58 test ! -e "$dst" -o "$src" -nt "$dst"
59 }
60
61 if shouldbuild "$SRCNAME.dsc" "$PKGNAME/debian/changelog" ]; then
62 if [ "$REUSE_EXISTING_ORIG_TARBALL" = 1 ]; then
63 UPSVER="${DEBVER%-*}"
64 mv "${DEBSRC}_${UPSVER}.orig.tar.gz" "${DEBSRC}_${UPSVER}.orig.tar.gz.new"
65 apt-get -t unstable source --download-only "${DEBSRC}" # "=${DEBVER}"
66 # check that old tarball contains same contents as new tarball
67 if ! diff -ru \
68 --label "${DEBSRC}_${UPSVER}.orig.tar.gz.new" \
69 <(zcat "${DEBSRC}_${UPSVER}.orig.tar.gz.new" | tar -tvvf-) \
70 --label "${DEBSRC}_${UPSVER}.orig.tar.gz" \
71 <(zcat "${DEBSRC}_${UPSVER}.orig.tar.gz" | tar -tvvf-); then
72 read -p "contents differ, continue with old tarball or abort? [y/N] " x
73 if [ "$x" != "y" ]; then exit 1; fi
74 fi
75 # extract old tarball into new directory, to avoid "modified files" problems with dpkg-source later
76 ( cd "$PKGNAME" && dpkg-source --after-build . && tar --strip-components=1 -xf "../${DEBSRC}_${UPSVER}.orig.tar.gz" )
77 fi
78 ( cd "$PKGNAME" && dpkg-buildpackage -d -S --no-sign )
79 # sign if not UNRELEASED
80 if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
81 debsign "${SRCNAME}_source.changes"
82 fi
83 fi
84
85 check_build_deps() {
86 mkdir -p dpkg-dummy
87 if shouldbuild dpkg-dummy/status /var/cache/apt/pkgcache.bin; then
88 # pretend dpkg status file that marks all packages as installed
89 # this is because dpkg-checkbuilddeps only works on installed pkgs
90 apt-cache dumpavail -o APT::Default-Release=unstable | \
91 sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy/status
92 if ! test -s dpkg-dummy/status; then
93 abort 1 "couldn't generate dpkg-dummy/status, is Debian unstable in your APT sources?"
94 fi
95 fi
96 ( cd "$PKGNAME" && dpkg-checkbuilddeps --admindir=../dpkg-dummy )
97 }
98
99 if ! check_build_deps; then
100 if [ "$IGNORE_MISSING_BUILD_DEPS" != 1 ]; then
101 abort 1 "Missing build-dependencies, but maybe try '{apt,cargo} update'"
102 fi
103 fi
104
105 if [ "$SOURCEONLY" = 1 ]; then
106 exit
107 fi
108
109 EXTRA_DEBS=( "$@" )
110 if [ -n "${EXTRA_DEBS[*]}" ]; then
111 EXTRA_DEBS_SBUILD=("${EXTRA_DEBS[@]/#/--extra-package=}")
112 EXTRA_DEBS_REPO_TMP=$(mktemp -d "${SRCNAME}_REPO_XXXXXXXX")
113 # symlinks don't work here
114 ln -f "${EXTRA_DEBS[@]}" "$EXTRA_DEBS_REPO_TMP/"
115 ( cd "$EXTRA_DEBS_REPO_TMP"; apt-ftparchive packages . > Packages )
116 EXTRA_DEBS_AUTOPKGTEST_OPTS=([0]=--autopkgtest-opt=--copy="$PWD/$EXTRA_DEBS_REPO_TMP/:/tmp/$EXTRA_DEBS_REPO_TMP/" [1]=--autopkgtest-opt=--add-apt-source="deb [trusted=yes] file:///tmp/$EXTRA_DEBS_REPO_TMP ./")
117 fi
118
119 AUTOPKGTEST_OPTS=("--run-autopkgtest" "--autopkgtest-root-arg=" "--autopkgtest-opts=-- schroot ${CHROOT}")
120 if [ "$SKIP_AUTOPKGTEST" = 1 ]; then
121 AUTOPKGTEST_OPTS=()
122 EXTRA_DEBS_AUTOPKGTEST_OPTS=()
123 fi
124
125 LINTIAN_OPTS=()
126 if echo "$DEBDIST" | grep -q UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
127 LINTIAN_OPTS=([0]="--lintian-opt=--suppress-tags" [1]="--lintian-opt=bad-distribution-in-changes-file")
128 fi
129
130 sbuild --no-source --arch-any --arch-all \
131 ${CHROOT:+-c $CHROOT} \
132 ${DISTRIBUTION:+-d $DISTRIBUTION} \
133 "${EXTRA_DEBS_SBUILD[@]}" \
134 "${EXTRA_DEBS_AUTOPKGTEST_OPTS[@]}" \
135 "${AUTOPKGTEST_OPTS[@]}" \
136 "${LINTIAN_OPTS[@]}" \
137 "$SRCNAME.dsc"
138 if [ "$SKIP_AUTOPKGTEST" != 1 ]; then
139 report "analyzing autopkgtest log: $BUILDNAME.test.log"
140 # this is a bit of a hack but works OK for now, until sbuild supports %SBUILD_BUILD_DIR in --autopkgtest-opt
141 sed -ne '/autopkgtest .*: testing package .* version .*/,$p' "$BUILDNAME.build" > "$BUILDNAME.test.log"
142 "$SCRIPTDIR/dev/rust-regressions.sh" "$BUILDNAME.test.log"
143 fi
144
145 if [ -d "$EXTRA_DEBS_REPO_TMP" ]; then
146 rm -rf "$EXTRA_DEBS_REPO_TMP";
147 fi
148
149 changestool "$BUILDNAME.changes" adddsc "$SRCNAME.dsc"
150 report "build complete: $BUILDNAME.changes"
151
152 # sign if not UNRELEASED
153 if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
154 debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign "$BUILDNAME.changes"
155 fi