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 type -p debcargo
>/dev
/null
2>&1; then
31 DEBCARGO
=$
(type -p 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"
104 if shouldbuild dpkg-dummy
/status
/var
/cache
/apt
/pkgcache.bin
; then
105 # pretend dpkg status file that marks all packages as installed
106 # this is because dpkg-checkbuilddeps only works on installed pkgs
107 ( apt-cache dumpavail
-o APT
::Default-Release
=unstable
&& \
108 for i
in ${EXTRA_DEBS[*]}; do apt-cache show $
(echo $i | cut
-d_ -f1); done ) | \
109 sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy
/status
110 if ! test -s dpkg-dummy
/status
; then
111 abort
1 "couldn't generate dpkg-dummy/status, is Debian unstable in your APT sources?"
114 ( cd "$PKGNAME" && dpkg-checkbuilddeps
--admindir=..
/dpkg-dummy
)
117 if ! check_build_deps
; then
118 if [ "$IGNORE_MISSING_BUILD_DEPS" != 1 ]; then
119 abort
1 "Missing build-dependencies, but maybe try '{apt,cargo} update'"
123 if [ "$SOURCEONLY" = 1 ]; then
127 if [ -n "${EXTRA_DEBS[*]}" ]; then
128 EXTRA_DEBS_SBUILD
=("${EXTRA_DEBS[@]/#/--extra-package=}")
129 EXTRA_DEBS_REPO_TMP
=$
(mktemp
-d "${SRCNAME}_REPO_XXXXXXXX")
130 # trap cleans up even if user does Ctrl-C
131 # https://stackoverflow.com/a/14812383 inside "trap" avoids running handler twice
132 trap 'excode=$?; rm -rf "'"$EXTRA_DEBS_REPO_TMP"'"; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
133 # symlinks don't work here
134 ln -f "${EXTRA_DEBS[@]}" "$EXTRA_DEBS_REPO_TMP/"
135 ( cd "$EXTRA_DEBS_REPO_TMP"; apt-ftparchive packages .
> Packages
)
136 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 ./")
139 AUTOPKGTEST_OPTS
=("--run-autopkgtest" "--autopkgtest-root-arg=" "--autopkgtest-opts=-- schroot ${CHROOT}")
140 if [ "$SKIP_AUTOPKGTEST" = 1 ]; then
142 EXTRA_DEBS_AUTOPKGTEST_OPTS
=()
146 if echo "$DEBDIST" |
grep -q UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO
; then
147 LINTIAN_OPTS
=([0]="--lintian-opt=--suppress-tags" [1]="--lintian-opt=bad-distribution-in-changes-file")
150 SBUILD_CONFIG
="$SCRIPTDIR/dev/sbuildrc" sbuild
--no-source --arch-any --arch-all \
151 ${CHROOT:+-c $CHROOT} \
152 ${DISTRIBUTION:+-d $DISTRIBUTION} \
153 "${EXTRA_DEBS_SBUILD[@]}" \
154 "${EXTRA_DEBS_AUTOPKGTEST_OPTS[@]}" \
155 "${AUTOPKGTEST_OPTS[@]}" \
156 "${LINTIAN_OPTS[@]}" \
158 if [ "$SKIP_AUTOPKGTEST" != 1 ]; then
159 report
"analyzing autopkgtest log: $BUILDNAME.test.log"
160 # this is a bit of a hack but works OK for now, until sbuild supports %SBUILD_BUILD_DIR in --autopkgtest-opt
161 sed -ne '/autopkgtest .*: testing package .* version .*/,$p' "$BUILDNAME.build" > "$BUILDNAME.test.log"
162 "$SCRIPTDIR/dev/rust-regressions.sh" "$BUILDNAME.test.log"
165 changestool
"$BUILDNAME.changes" adddsc
"$SRCNAME.dsc"
166 report
"build complete: $BUILDNAME.changes"
168 # sign if not UNRELEASED
169 if echo "$DEBDIST" |
grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO
; then
170 debsign
${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign "$BUILDNAME.changes"