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