diff --git a/README.rst b/README.rst index 3c571d5..761f2cb 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,12 @@ Instructions ============ -First, ``cargo install debcargo``. Then for each new package: +To get set up, run:: + + apt update && apt build-dep cargo && apt install cargo dh-cargo + cargo install debcargo # eventually will be replaced by "apt install debcargo" + +Then for each new package: **To package a new crate, or to update an existing crate:** diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..1035daf --- /dev/null +++ b/build.sh @@ -0,0 +1,72 @@ +#!/bin/sh +set -e + +abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; } + +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" +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) +if [ -z "$CHROOT" ] && schroot -i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then + CHROOT="debcargo-unstable-${DEB_HOST_ARCH}-sbuild" +fi + +shouldbuild() { + local dst="$1" + local src="$2" + test ! -e "$dst" -o "$src" -nt "$dst" +} + +if shouldbuild ${DEBSRC}_${DEBVER}.dsc "$PKGNAME/debian/changelog" ]; then + ( cd "$PKGNAME" && dpkg-buildpackage -d -S --no-sign ) + # sign if not UNRELEASED + if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then + debsign ${DEBSRC}_${DEBVER}_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 | \ + sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy/status + fi + cd "$PKGNAME" && dpkg-checkbuilddeps --admindir=../dpkg-dummy +} + +if ! check_build_deps; then + abort 1 "Missing build-dependencies, but maybe try '{apt,cargo} update'" +fi + +if [ "$SOURCEONLY" = 1 ]; then + exit +fi + +sbuild --no-source --arch-any --arch-all ${CHROOT:+-c $CHROOT }${DISTRIBUTION:+-d $DISTRIBUTION }${DEBSRC}_${DEBVER}.dsc +changestool ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes adddsc ${DEBSRC}_${DEBVER}.dsc + +# sign if not UNRELEASED +if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then + debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes +fi diff --git a/dev/filter-builddeps-ok.sh b/dev/filter-builddeps-ok.sh new file mode 100755 index 0000000..07c7a4f --- /dev/null +++ b/dev/filter-builddeps-ok.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Filter list of crates by whether all their build-deps are in Debian +# Use like, e.g. `dev/list-unreleased.sh | dev/filter-builddeps-ok.sh` +set -e + +shouldbuild() { + local dst="$1" + local src="$2" + test ! -e "$dst" -o "$src" -nt "$dst" +} + +echo >&2 "redirecting all other output e.g. from debcargo to stderr" +while read crate ver; do + pkgname="${crate//_/-}${ver:+-$ver}" + if shouldbuild "build/$pkgname/debian/changelog" "src/$pkgname/debian/changelog"; then + ./update.sh "$crate" $ver >&2 # TODO: no-overlay-write-back + fi + if ( cd build && SOURCEONLY=1 ./build.sh "$crate" $ver >&2 ); then + ok=1 + else + ok=0 + fi + echo "$crate $ver $ok" +done diff --git a/dev/list-unreleased.sh b/dev/list-unreleased.sh index f06a8d3..c158249 100755 --- a/dev/list-unreleased.sh +++ b/dev/list-unreleased.sh @@ -8,5 +8,5 @@ cut '-d ' -f1 | \ while read crate; do pkg="${crate//_/-}" - head -n1 src/$pkg/debian/changelog + sed -nre "s/.*Package (.*) .* from crates.io.*/\1/gp" src/$pkg/debian/changelog | head -n1 done diff --git a/release.sh b/release.sh index 52f9d32..f1eacc2 100755 --- a/release.sh +++ b/release.sh @@ -11,6 +11,9 @@ git diff --quiet -- "$PKGDIR_REL" || \ abort 1 "Please git-add your changes to $PKGDIR_REL before running" + +type dch >/dev/null || \ +abort 1 "Install devscripts, we need to run dch." RELBRANCH="pending-$PKGNAME" git fetch origin --prune @@ -59,61 +62,15 @@ abort 1 "Release attempt resulted in git diffs to $PKGDIR_REL, probably the package needs updating (./update.sh $*)" fi -check_build_deps() { - local success=true - sed -ne '/Build-Depends/,/^[^ ]/p' "build/$PKGNAME/debian/control" | \ - grep -Eo 'librust-.*+.*-dev' | \ - { while read pkg; do - if [ $(apt-cache showpkg "$pkg" | grep ^Package: | wc -l) = 0 ]; then - echo >&2 "Build-Dependency not yet in debian: $pkg (don't forget to '{apt,cargo} update')" - success=false - fi - done; $success; } -} - -if ! check_build_deps; then +if ! ( cd build && SOURCEONLY=1 ./build.sh "$CRATE" $VER ); then revert_git_changes abort 1 "Release attempt detected build-dependencies not in Debian (see messages above), release those first." fi git commit -m "Release package $PKGNAME" -( cd "$BUILDDIR" && dpkg-buildpackage -d -S --no-sign ) - -cat >"$BUILDDIR/../sbuild-and-sign.sh" <<'eof' -#!/bin/sh -set -e - -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" -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) -DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH) -if [ -z "$CHROOT" ] && schroot -i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then - CHROOT="debcargo-unstable-${DEB_HOST_ARCH}-sbuild" -fi - -sbuild --no-source --arch-any --arch-all ${CHROOT:+-c $CHROOT }${DISTRIBUTION:+-d $DISTRIBUTION }${DEBSRC}_${DEBVER}.dsc -changestool ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes adddsc ${DEBSRC}_${DEBVER}.dsc -debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID }--no-re-sign ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes -eof -chmod +x "$BUILDDIR/../sbuild-and-sign.sh" - -DEBVER=$(dpkg-parsechangelog -l build/$PKGNAME/debian/changelog -SVersion) -DEBSRC=$(dpkg-parsechangelog -l build/$PKGNAME/debian/changelog -SSource) +DEBVER=$(dpkg-parsechangelog -l $BUILDDIR/debian/changelog -SVersion) +DEBSRC=$(dpkg-parsechangelog -l $BUILDDIR/debian/changelog -SSource) DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH) cat >&2 <&2 "-- end of git diff --" fi @@ -79,10 +79,20 @@ any auto-generated hint files. If so, you should make the equivalent changes to the non-hint files, and git-add these too. -When satisfied with the output, you can commit and push all your changes. Then, -ask a Debian Developer to run \`./release.sh $*\` to finalise your changes in -the changelog and build a release-ready .dsc in build/. Assuming it runs -successfully, they may \`dput\` the results afterwards. If you're not a Debian -Developer and are unable to upload, please don't run that script because it -will add inaccurate commits to git stating that the package has been uploaded. +You can test-build your package by running: + + cd build && ./build.sh $CRATE $VER + +This assumes that you have set up sbuild; see "DD instructions" in README.rst +for details. Try to fix any lintian errors, but note that some errors are due +to lintian being out-of-date and/or are expected at this stage of the process +(e.g. bad-distribution-in-changes-file). Ask on IRC when in doubt. + +When satisfied with the output (both of debcargo after running ./update.sh, and +of lintian after running ./build.sh), you can commit and push all your changes. + +Then, ask a Debian Developer to run \`./release.sh $*\`. This finalises your +changes in the changelog, and allows them to build and upload the package. If +you're not a Debian Developer and are unable to upload, please don't run that +script or else you will need to revert the changes that it makes to your git. eof diff --git a/vars.sh.frag b/vars.sh.frag index 10b2d78..4a39c5a 100644 --- a/vars.sh.frag +++ b/vars.sh.frag @@ -58,6 +58,8 @@ PKGCFG="$PKGDIR/debian/debcargo.toml" mkdir -p "$(dirname $BUILDDIR)" +cp "$PWD/build.sh" "$PWD/build/build.sh" +chmod +x "$PWD/build/build.sh" if [ -z "$CRATE" ]; then abort 2 "Usage: $0 []"