Codebase list rust-stfu8 / 4c128e93-5432-4178-b3c8-3e176ad32f81/main build.sh
4c128e93-5432-4178-b3c8-3e176ad32f81/main

Tree @4c128e93-5432-4178-b3c8-3e176ad32f81/main (Download .tar.gz)

build.sh @4c128e93-5432-4178-b3c8-3e176ad32f81/main

987288b
5e18ef4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1057693
 
9cc53ba
 
1057693
9cc53ba
1057693
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
987288b
 
 
 
 
 
1057693
 
 
 
 
 
 
9cc53ba
 
43b8c90
1869918
43b8c90
1869918
43b8c90
 
 
 
 
 
1869918
43b8c90
 
1057693
 
 
 
 
 
 
 
9cc53ba
2f1d8dc
 
 
551c3a8
2f1d8dc
a0c73b1
 
 
 
 
 
 
 
551c3a8
 
2f1d8dc
551c3a8
1057693
 
9cc53ba
1057693
 
 
d0306da
 
1057693
 
 
 
 
d0306da
 
1057693
89617f5
9cc53ba
89617f5
1057693
c7386c9
1057693
 
 
581335d
 
 
1057693
 
 
 
 
 
95bfde4
 
 
5e18ef4
 
 
95bfde4
 
 
 
 
 
 
9cc53ba
 
95bfde4
e3985de
 
4a5c588
 
95bfde4
4a5c588
 
f890c34
987288b
 
95bfde4
 
e3985de
4a5c588
9cc53ba
 
 
 
 
 
 
95bfde4
9cc53ba
 
1057693
 
 
9cc53ba
1057693
#!/bin/bash
# Build a packaged crate.
#
# This script is not run directly, but linked into ./build/ when running one of
# the other scripts, so you should do that instead of running this directly.
#
# Usage: [REALVER=<EXACTVER>] ./build.sh <CRATE> [<SEMVER>] [<EXTRA DEPENDENCY DEB> ...]
#
# Envvars:
# IGNORE_MISSING_BUILD_DEPS=1
#     Don't abort on missing build deps. You'll need
#     this when giving extra dependency debs.
# DISTRIBUTION=$suite
#     Release to something other than unstable, e.g. experimental
# CHROOT=$chroot
#     Build using another schroot than debcargo-unstable-amd64-sbuild
set -e

SCRIPTDIR="$(dirname $(readlink -f "$0"))"

abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; }
report() { for i in "$@"; do echo >&2 "debcargo-conf builder: $i"; done; }

if [ "$(basename "$PWD")" != "build" ]; then
	abort 1 "This script is only meant to be run from the build/ directory."
fi

if [ -n "$DEBCARGO" ]; then
	true
elif which debcargo >/dev/null; then
	DEBCARGO=$(which debcargo)
elif [ -f "$HOME/.cargo/bin/debcargo" ]; then
	DEBCARGO="$HOME/.cargo/bin/debcargo"
else
	abort 1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it"
fi

CRATE="$1"
VER="$2"
if test -z "$VER" -o -f "$VER"; then
	VER=""
	shift
else
	shift 2
fi
DISTRIBUTION="${DISTRIBUTION:-unstable}"

PKGNAME=$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE")
DEBVER=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SVersion)
DEBSRC=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SSource)
DEBDIST=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SDistribution)
DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH)
SRCNAME="${DEBSRC}_${DEBVER}"
BUILDNAME="${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}"
if [ -z "$CHROOT" ]; then
	if schroot -i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then
		CHROOT="debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
	elif schroot -i -c "unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then
		CHROOT="unstable-${DEB_HOST_ARCH}-sbuild"
		echo >&2 "Automatically using sbuild chroot unstable-${DEB_HOST_ARCH}-sbuild; however it's"
		echo >&2 "strongly recommended to create a separate chroot debcargo-unstable-${DEB_HOST_ARCH}-sbuild"
		echo >&2 "so your builds won't have to re-download & re-install cargo, rustc, and llvm every time."
		echo >&2 "See README.rst section \"Build environment\" for details."
		sleep 1
	elif [ "$SOURCEONLY" != 1 ]; then
		abort 1 "could not automatically find a suitable chroot; set CHROOT"
	fi
fi

shouldbuild() {
	local dst="$1"
	local src="$2"
	test ! -e "$dst" -o "$src" -nt "$dst"
}

if shouldbuild "$SRCNAME.dsc" "$PKGNAME/debian/changelog" ]; then
	if [ "$REUSE_EXISTING_ORIG_TARBALL" = 1 ]; then
		UPSVER="${DEBVER%-*}"
		mv "${DEBSRC}_${UPSVER}.orig.tar.gz" "${DEBSRC}_${UPSVER}.orig.tar.gz.new"
		apt-get -t unstable source --download-only "${DEBSRC}" # "=${DEBVER}"
		# check that old tarball contains same contents as new tarball
		if ! diff -ru \
			  --label "${DEBSRC}_${UPSVER}.orig.tar.gz.new" \
			  <(zcat  "${DEBSRC}_${UPSVER}.orig.tar.gz.new" | tar -tvvf-) \
			  --label "${DEBSRC}_${UPSVER}.orig.tar.gz" \
			  <(zcat  "${DEBSRC}_${UPSVER}.orig.tar.gz" | tar -tvvf-); then
			read -p "contents differ, continue with old tarball or abort? [y/N] " x
			if [ "$x" != "y" ]; then exit 1; fi
		fi
		# extract old tarball into new directory, to avoid "modified files" problems with dpkg-source later
		( cd "$PKGNAME" && dpkg-source --after-build . && tar --strip-components=1 -xf "../${DEBSRC}_${UPSVER}.orig.tar.gz" )
	fi
	( cd "$PKGNAME" && dpkg-buildpackage -d -S --no-sign )
	# sign if not UNRELEASED
	if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
		debsign "${SRCNAME}_source.changes"
	fi
fi

EXTRA_DEBS=( "$@" )

check_build_deps() {
	mkdir -p dpkg-dummy
	if shouldbuild dpkg-dummy/status /var/cache/apt/pkgcache.bin; then
		# pretend dpkg status file that marks all packages as installed
		# this is because dpkg-checkbuilddeps only works on installed pkgs
		( apt-cache dumpavail -o APT::Default-Release=unstable && \
			for i in ${EXTRA_DEBS[*]}; do apt-cache show $(echo $i | cut -d_ -f1); done ) | \
		sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy/status
		if ! test -s dpkg-dummy/status; then
			abort 1 "couldn't generate dpkg-dummy/status, is Debian unstable in your APT sources?"
		fi
	fi
	( cd "$PKGNAME" && dpkg-checkbuilddeps --admindir=../dpkg-dummy )
}

if ! check_build_deps; then
	if [ "$IGNORE_MISSING_BUILD_DEPS" != 1 ]; then
		abort 1 "Missing build-dependencies, but maybe try '{apt,cargo} update'"
	fi
fi

if [ "$SOURCEONLY" = 1 ]; then
	exit
fi

if [ -n "${EXTRA_DEBS[*]}" ]; then
    EXTRA_DEBS_SBUILD=("${EXTRA_DEBS[@]/#/--extra-package=}")
    EXTRA_DEBS_REPO_TMP=$(mktemp -d "${SRCNAME}_REPO_XXXXXXXX")
    # trap cleans up even if user does Ctrl-C
    # https://stackoverflow.com/a/14812383 inside "trap" avoids running handler twice
    trap 'excode=$?; rm -rf "'"$EXTRA_DEBS_REPO_TMP"'"; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
    # symlinks don't work here
    ln -f "${EXTRA_DEBS[@]}" "$EXTRA_DEBS_REPO_TMP/"
    ( cd "$EXTRA_DEBS_REPO_TMP"; apt-ftparchive packages . > Packages )
    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 ./")
fi

AUTOPKGTEST_OPTS=("--run-autopkgtest" "--autopkgtest-root-arg=" "--autopkgtest-opts=-- schroot ${CHROOT}")
if [ "$SKIP_AUTOPKGTEST" = 1 ]; then
	AUTOPKGTEST_OPTS=()
	EXTRA_DEBS_AUTOPKGTEST_OPTS=()
fi

LINTIAN_OPTS=()
if echo "$DEBDIST" | grep -q UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
	LINTIAN_OPTS=([0]="--lintian-opt=--suppress-tags" [1]="--lintian-opt=bad-distribution-in-changes-file")
fi

SBUILD_CONFIG="$SCRIPTDIR/dev/sbuildrc" sbuild --no-source --arch-any --arch-all \
  ${CHROOT:+-c $CHROOT} \
  ${DISTRIBUTION:+-d $DISTRIBUTION} \
  "${EXTRA_DEBS_SBUILD[@]}" \
  "${EXTRA_DEBS_AUTOPKGTEST_OPTS[@]}" \
  "${AUTOPKGTEST_OPTS[@]}" \
  "${LINTIAN_OPTS[@]}" \
  "$SRCNAME.dsc"
if [ "$SKIP_AUTOPKGTEST" != 1 ]; then
	report "analyzing autopkgtest log: $BUILDNAME.test.log"
	# this is a bit of a hack but works OK for now, until sbuild supports %SBUILD_BUILD_DIR in --autopkgtest-opt
	sed -ne '/autopkgtest .*: testing package .* version .*/,$p' "$BUILDNAME.build" > "$BUILDNAME.test.log"
	"$SCRIPTDIR/dev/rust-regressions.sh" "$BUILDNAME.test.log"
fi

changestool "$BUILDNAME.changes" adddsc "$SRCNAME.dsc"
report "build complete: $BUILDNAME.changes"

# sign if not UNRELEASED
if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
	debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign "$BUILDNAME.changes"
fi