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 # Release to something other than unstable, e.g. experimental
16 # Build using another schroot than debcargo-unstable-amd64-sbuild
19 SCRIPTDIR
="$(dirname $(readlink -f "$0"))"
21 abort
() { local x
=$1; shift; for i
in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; }
22 report
() { for i
in "$@"; do echo >&2 "debcargo-conf builder: $i"; done; }
24 if [ "$(basename "$PWD")" != "build" ]; then
25 abort
1 "This script is only meant to be run from the build/ directory."
28 if [ -n "$DEBCARGO" ]; then
30 elif which debcargo
>/dev
/null
; then
31 DEBCARGO
=$
(which debcargo
)
32 elif [ -f "$HOME/.cargo/bin/debcargo" ]; then
33 DEBCARGO
="$HOME/.cargo/bin/debcargo"
35 abort
1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it"
40 if test -z "$VER" -o -f "$VER"; then
46 DISTRIBUTION
="${DISTRIBUTION:-unstable}"
48 PKGNAME
=$
($DEBCARGO deb-src-name
"$CRATE" $VER || abort
1 "couldn't find crate $CRATE")
49 DEBVER
=$
(dpkg-parsechangelog
-l $PKGNAME/debian
/changelog
-SVersion)
50 DEBSRC
=$
(dpkg-parsechangelog
-l $PKGNAME/debian
/changelog
-SSource)
51 DEBDIST
=$
(dpkg-parsechangelog
-l $PKGNAME/debian
/changelog
-SDistribution)
52 DEB_HOST_ARCH
=$
(dpkg-architecture
-q DEB_HOST_ARCH
)
53 SRCNAME
="${DEBSRC}_${DEBVER}"
54 BUILDNAME
="${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}"
55 if [ -z "$CHROOT" ]; then
56 if schroot
-i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev
/null
2>&1; then
57 CHROOT
="debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
58 elif schroot
-i -c "unstable-${DEB_HOST_ARCH}-sbuild" >/dev
/null
2>&1; then
59 CHROOT
="unstable-${DEB_HOST_ARCH}-sbuild"
60 echo >&2 "Automatically using sbuild chroot unstable-${DEB_HOST_ARCH}-sbuild; however it's"
61 echo >&2 "strongly recommended to create a separate chroot debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
62 echo >&2 "so your builds won't have to re-download & re-install cargo, rustc, and llvm every time."
63 echo >&2 "See README.rst section \"Build environment\" for details."
65 elif [ "$SOURCEONLY" != 1 ]; then
66 abort
1 "could not automatically find a suitable chroot; set CHROOT"
73 test ! -e "$dst" -o "$src" -nt "$dst"
76 if shouldbuild
"$SRCNAME.dsc" "$PKGNAME/debian/changelog" ]; then
77 if [ "$REUSE_EXISTING_ORIG_TARBALL" = 1 ]; then
79 mv "${DEBSRC}_${UPSVER}.orig.tar.gz" "${DEBSRC}_${UPSVER}.orig.tar.gz.new"
80 apt-get
-t unstable
source --download-only "${DEBSRC}" # "=${DEBVER}"
81 # check that old tarball contains same contents as new tarball
83 --label "${DEBSRC}_${UPSVER}.orig.tar.gz.new" \
84 <(zcat
"${DEBSRC}_${UPSVER}.orig.tar.gz.new" |
tar -tvvf-) \
85 --label "${DEBSRC}_${UPSVER}.orig.tar.gz" \
86 <(zcat
"${DEBSRC}_${UPSVER}.orig.tar.gz" |
tar -tvvf-); then
87 read -p "contents differ, continue with old tarball or abort? [y/N] " x
88 if [ "$x" != "y" ]; then exit 1; fi
90 # extract old tarball into new directory, to avoid "modified files" problems with dpkg-source later
91 ( cd "$PKGNAME" && dpkg-source
--after-build .
&& tar --strip-components=1 -xf "../${DEBSRC}_${UPSVER}.orig.tar.gz" )
93 ( cd "$PKGNAME" && dpkg-buildpackage
-d -S --no-sign )
94 # sign if not UNRELEASED
95 if echo "$DEBDIST" |
grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO
; then
96 debsign
"${SRCNAME}_source.changes"
102 if shouldbuild dpkg-dummy
/status
/var
/cache
/apt
/pkgcache.bin
; then
103 # pretend dpkg status file that marks all packages as installed
104 # this is because dpkg-checkbuilddeps only works on installed pkgs
105 apt-cache dumpavail
-o APT
::Default-Release
=unstable | \
106 sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy
/status
107 if ! test -s dpkg-dummy
/status
; then
108 abort
1 "couldn't generate dpkg-dummy/status, is Debian unstable in your APT sources?"
111 ( cd "$PKGNAME" && dpkg-checkbuilddeps
--admindir=..
/dpkg-dummy
)
114 if ! check_build_deps
; then
115 if [ "$IGNORE_MISSING_BUILD_DEPS" != 1 ]; then
116 abort
1 "Missing build-dependencies, but maybe try '{apt,cargo} update'"
120 if [ "$SOURCEONLY" = 1 ]; then
125 if [ -n "${EXTRA_DEBS[*]}" ]; then
126 EXTRA_DEBS_SBUILD
=("${EXTRA_DEBS[@]/#/--extra-package=}")
127 EXTRA_DEBS_REPO_TMP
=$
(mktemp
-d "${SRCNAME}_REPO_XXXXXXXX")
128 # trap cleans up even if user does Ctrl-C
129 # https://stackoverflow.com/a/14812383 inside "trap" avoids running handler twice
130 trap 'excode=$?; rm -rf "'"$EXTRA_DEBS_REPO_TMP"'"; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
131 # symlinks don't work here
132 ln -f "${EXTRA_DEBS[@]}" "$EXTRA_DEBS_REPO_TMP/"
133 ( cd "$EXTRA_DEBS_REPO_TMP"; apt-ftparchive packages .
> Packages
)
134 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 ./")
137 AUTOPKGTEST_OPTS
=("--run-autopkgtest" "--autopkgtest-root-arg=" "--autopkgtest-opts=-- schroot ${CHROOT}")
138 if [ "$SKIP_AUTOPKGTEST" = 1 ]; then
140 EXTRA_DEBS_AUTOPKGTEST_OPTS
=()
144 if echo "$DEBDIST" |
grep -q UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO
; then
145 LINTIAN_OPTS
=([0]="--lintian-opt=--suppress-tags" [1]="--lintian-opt=bad-distribution-in-changes-file")
148 SBUILD_CONFIG
="$SCRIPTDIR/dev/sbuildrc" sbuild
--no-source --arch-any --arch-all \
149 ${CHROOT:+-c $CHROOT} \
150 ${DISTRIBUTION:+-d $DISTRIBUTION} \
151 "${EXTRA_DEBS_SBUILD[@]}" \
152 "${EXTRA_DEBS_AUTOPKGTEST_OPTS[@]}" \
153 "${AUTOPKGTEST_OPTS[@]}" \
154 "${LINTIAN_OPTS[@]}" \
156 if [ "$SKIP_AUTOPKGTEST" != 1 ]; then
157 report
"analyzing autopkgtest log: $BUILDNAME.test.log"
158 # this is a bit of a hack but works OK for now, until sbuild supports %SBUILD_BUILD_DIR in --autopkgtest-opt
159 sed -ne '/autopkgtest .*: testing package .* version .*/,$p' "$BUILDNAME.build" > "$BUILDNAME.test.log"
160 "$SCRIPTDIR/dev/rust-regressions.sh" "$BUILDNAME.test.log"
163 changestool
"$BUILDNAME.changes" adddsc
"$SRCNAME.dsc"
164 report
"build complete: $BUILDNAME.changes"
166 # sign if not UNRELEASED
167 if echo "$DEBDIST" |
grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO
; then
168 debsign
${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign "$BUILDNAME.changes"