2 # Build a packaged crate.
4 # This script is not run directly, but linked into ./build/ when running one of
5 # the other scripts, so you should do that instead of running this directly.
7 # Usage: [REALVER=<EXACTVER>] ./build.sh <CRATE> [<SEMVER>] [<EXTRA DEPENDENCY DEB> ...]
10 # IGNORE_MISSING_BUILD_DEPS=1
11 # Don't abort on missing build deps. You'll need
12 # this when giving extra dependency debs.
14 # Skip signing built packages.
16 # Release to something other than unstable, e.g. experimental
18 # Build using another schroot than debcargo-unstable-amd64-sbuild
20 # will pass to sbuild; for example SBUILD_OPTS=--arch=i386
22 # Include extra dependency debs, e.g. EXTRA_DEBS=librust*.deb.
25 SCRIPTDIR
="$(dirname $(readlink -f "$0"))"
27 abort
() { local x
=$1; shift; for i
in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; }
28 report
() { for i
in "$@"; do echo >&2 "debcargo-conf builder: $i"; done; }
30 if [ "$(basename "$PWD")" != "build" ]; then
31 abort
1 "This script is only meant to be run from the build/ directory."
34 if [ -n "$DEBCARGO" ]; then
36 elif type -p debcargo
>/dev
/null
2>&1; then
37 DEBCARGO
=$
(type -p debcargo
)
38 elif [ -f "$HOME/.cargo/bin/debcargo" ]; then
39 DEBCARGO
="$HOME/.cargo/bin/debcargo"
41 abort
1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it"
46 if test -z "$VER" -o -f "$VER"; then
52 DISTRIBUTION
="${DISTRIBUTION:-unstable}"
54 PKGNAME
=$
($DEBCARGO deb-src-name
"$CRATE" $VER || abort
1 "couldn't find crate $CRATE")
55 DEBVER
=$
(dpkg-parsechangelog
-l $PKGNAME/debian
/changelog
-SVersion)
56 DEBSRC
=$
(dpkg-parsechangelog
-l $PKGNAME/debian
/changelog
-SSource)
57 DEBDIST
=$
(dpkg-parsechangelog
-l $PKGNAME/debian
/changelog
-SDistribution)
58 DEB_HOST_ARCH
=$
(dpkg-architecture
-q DEB_HOST_ARCH
)
59 SRCNAME
="${DEBSRC}_${DEBVER}"
60 BUILDNAME
="${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}"
61 if [ -z "$CHROOT" ]; then
62 if schroot
-i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev
/null
2>&1; then
63 CHROOT
="debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
64 elif schroot
-i -c "unstable-${DEB_HOST_ARCH}-sbuild" >/dev
/null
2>&1; then
65 CHROOT
="unstable-${DEB_HOST_ARCH}-sbuild"
66 echo >&2 "Automatically using sbuild chroot unstable-${DEB_HOST_ARCH}-sbuild; however it's"
67 echo >&2 "strongly recommended to create a separate chroot debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
68 echo >&2 "so your builds won't have to re-download & re-install cargo, rustc, and llvm every time."
69 echo >&2 "See README.rst section \"Build environment\" for details."
71 elif [ "$SOURCEONLY" != 1 ]; then
72 abort
1 "could not automatically find a suitable chroot; set CHROOT"
79 test ! -e "$dst" -o "$src" -nt "$dst"
82 if shouldbuild
"$SRCNAME.dsc" "$PKGNAME/debian/changelog" ]; then
83 if [ "$REUSE_EXISTING_ORIG_TARBALL" = 1 ]; then
85 mv "${DEBSRC}_${UPSVER}.orig.tar.gz" "${DEBSRC}_${UPSVER}.orig.tar.gz.new"
86 apt-get
-t unstable
source --download-only "${DEBSRC}" # "=${DEBVER}"
87 # check that old tarball contains same contents as new tarball
89 --label "${DEBSRC}_${UPSVER}.orig.tar.gz.new" \
90 <(zcat
"${DEBSRC}_${UPSVER}.orig.tar.gz.new" |
tar -tvvf-) \
91 --label "${DEBSRC}_${UPSVER}.orig.tar.gz" \
92 <(zcat
"${DEBSRC}_${UPSVER}.orig.tar.gz" |
tar -tvvf-); then
93 read -p "contents differ, continue with old tarball or abort? [y/N] " x
94 if [ "$x" != "y" ]; then exit 1; fi
96 # extract old tarball into new directory, to avoid "modified files" problems with dpkg-source later
97 ( cd "$PKGNAME" && dpkg-source
--after-build .
&& tar --strip-components=1 -xf "../${DEBSRC}_${UPSVER}.orig.tar.gz" )
99 ( cd "$PKGNAME" && dpkg-buildpackage
-d -S --no-sign )
100 # sign if not UNRELEASED
101 if echo "$DEBDIST" |
grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO
; then
102 if [ "$SKIP_SIGN" != 1 ]; then
103 debsign
${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID} "${SRCNAME}_source.changes"
108 # allow tab, comma, space as separators
109 IFS
=' , ' read -r -a EXTRA_DEBS
<<< "$EXTRA_DEBS"
110 if [ ${#EXTRA_DEBS[@]} -eq 0 ]; then
113 if [ ${#EXTRA_DEBS[@]} -ne 0 ]; then
114 IGNORE_MISSING_BUILD_DEPS
=1
115 echo >&2 "Given non-empty extra debs; defaulting IGNORE_MISSING_BUILD_DEPS=1"
120 if shouldbuild dpkg-dummy
/status
/var
/cache
/apt
/pkgcache.bin
; then
121 # pretend dpkg status file that marks all packages as installed
122 # this is because dpkg-checkbuilddeps only works on installed pkgs
123 ( apt-cache dumpavail
-o APT
::Default-Release
=$DISTRIBUTION && \
124 for i
in ${EXTRA_DEBS[*]}; do apt-cache show $
(echo $i | cut
-d_ -f1); done ) | \
125 sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy
/status.tmp
126 if ! test -s dpkg-dummy
/status.tmp
; then
127 abort
1 "couldn't generate dpkg-dummy/status, is Debian unstable in your APT sources?"
129 mv dpkg-dummy
/status
{.tmp
,}
131 ( cd "$PKGNAME" && dpkg-checkbuilddeps
--admindir=..
/dpkg-dummy
)
134 if ! check_build_deps
; then
135 if [ "$IGNORE_MISSING_BUILD_DEPS" != 1 ]; then
136 abort
1 "Missing build-dependencies, but maybe try '{apt,cargo} update'"
140 if [ "$SOURCEONLY" = 1 ]; then
144 if [ -n "${EXTRA_DEBS[*]}" ]; then
145 EXTRA_DEBS_SBUILD
=("${EXTRA_DEBS[@]/#/--extra-package=}")
146 EXTRA_DEBS_REPO_TMP
=$
(mktemp
-d "${SRCNAME}_REPO_XXXXXXXX")
147 # trap cleans up even if user does Ctrl-C
148 # https://stackoverflow.com/a/14812383 inside "trap" avoids running handler twice
149 trap 'excode=$?; rm -rf "'"$EXTRA_DEBS_REPO_TMP"'"; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
150 # symlinks don't work here
151 ln -f "${EXTRA_DEBS[@]}" "$EXTRA_DEBS_REPO_TMP/"
152 ( cd "$EXTRA_DEBS_REPO_TMP"; apt-ftparchive packages .
> Packages
)
153 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 ./")
156 AUTOPKGTEST_OPTS
=("--run-autopkgtest" "--autopkgtest-root-arg=" "--autopkgtest-opts=-- schroot ${CHROOT}")
157 if [ "$SKIP_AUTOPKGTEST" = 1 ]; then
159 EXTRA_DEBS_AUTOPKGTEST_OPTS
=()
163 if echo "$DEBDIST" |
grep -q UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO
; then
164 LINTIAN_OPTS
=([0]="--lintian-opt=--suppress-tags" [1]="--lintian-opt=bad-distribution-in-changes-file")
167 SBUILD_CONFIG
="$SCRIPTDIR/dev/sbuildrc" sbuild
--no-source --arch-any --arch-all \
168 ${CHROOT:+-c $CHROOT} \
169 ${DISTRIBUTION:+-d $DISTRIBUTION} \
170 "${EXTRA_DEBS_SBUILD[@]}" \
171 "${EXTRA_DEBS_AUTOPKGTEST_OPTS[@]}" \
172 "${AUTOPKGTEST_OPTS[@]}" \
173 "${LINTIAN_OPTS[@]}" \
176 if [ "$SKIP_AUTOPKGTEST" != 1 ]; then
177 report
"analyzing autopkgtest log: $BUILDNAME.test.log"
178 # this is a bit of a hack but works OK for now, until sbuild supports %SBUILD_BUILD_DIR in --autopkgtest-opt
179 sed -ne '/autopkgtest .*: testing package .* version .*/,$p' "$BUILDNAME.build" > "$BUILDNAME.test.log"
180 "$SCRIPTDIR/dev/rust-regressions.sh" "$BUILDNAME.test.log"
183 changestool
"$BUILDNAME.changes" adddsc
"$SRCNAME.dsc"
184 report
"build complete: $BUILDNAME.changes"
186 if grep -q "unknown-section FIXME" "$BUILDNAME.build"; then
187 abort
1 "Please fix the SECTION, found FIXME"
190 # sign if not UNRELEASED
191 if echo "$DEBDIST" |
grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO
; then
192 if [ "$SKIP_SIGN" != 1 ]; then
193 debsign
${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID} --no-re-sign "$BUILDNAME.changes"