mirror of
https://git.proxmox.com/git/debcargo-conf
synced 2025-04-28 13:24:24 +00:00
134 lines
4.9 KiB
Bash
Executable File
134 lines
4.9 KiB
Bash
Executable File
#!/bin/bash
|
|
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"
|
|
#el
|
|
if 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
|
|
else
|
|
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
|
|
|
|
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 | \
|
|
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
|
|
|
|
AUTOPKGTEST_OPTS=(--run-autopkgtest --autopkgtest-root-arg= --autopkgtest-opts="-- schroot ${CHROOT}")
|
|
if [ "$SKIP_AUTOPKGTEST" = 1 ]; then
|
|
AUTOPKGTEST_OPTS=()
|
|
fi
|
|
|
|
sbuild --no-source --arch-any --arch-all \
|
|
${CHROOT:+-c $CHROOT} \
|
|
${DISTRIBUTION:+-d $DISTRIBUTION} \
|
|
${@/#/--extra-package=} \
|
|
"${AUTOPKGTEST_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
|