From d429dcf1ea2a831c3e99017f421bb7891ccdd8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Mon, 23 Jan 2017 11:42:32 +0100 Subject: [PATCH] packaging/debs: Simplify the Makefile wrapping dpkg-buildpackage(1) The `check-changelog.sh` script is transformed to `update-changelog.sh`. It doesn't care anymore if $UNOFFICIAL_RELEASE is set or not. It simply verifies if the given version matches the last entry of `debian/changelog` (without taking the package revision into account). If the last entry doesn't match, it prepends a new automatically generated entry. Also, the Makefile takes both `VERSION` and `DEBIAN_VERSION` as input variables. `VERSION` is the RabbitMQ version (eg. `3.6.7-alpha.62`) and `DEBIAN_VERSION` is the same version formatted for Debian (eg. `3.6.7~lpha.62`). If the latter is missing, it's computed from `VERSION`. Regarding package signing, `GNUPG_PATH` is deprecated. The caller should instead directly use `GNUPGHOME`, the documented variable expected by GnuPG. In the end, the Makefile is still compatible with the current way of building a RabbitMQ release but it will simplify the job of Concourse. As a bonus, there are two new scripts: o scripts/get-debian-package-files-list.sh: List all files making a Debian package, based on a specified `.changes` file. o scripts/compare-debian-versions.py: Compare two given versions (including the package revision) using APT. This helps when testing versioning. [#131645209] --- packaging/debs/Debian/Makefile | 91 +++++++++++++++---- .../additional_changelog_comments_3.3.5 | 9 -- .../additional_changelog_comments_x.x.x | 11 --- packaging/debs/Debian/check-changelog.sh | 29 ------ .../Debian/scripts/compare-debian-versions.py | 22 +++++ .../scripts/get-debian-package-files-list.sh | 33 +++++++ .../debs/Debian/scripts/update-changelog.sh | 27 ++++++ 7 files changed, 153 insertions(+), 69 deletions(-) delete mode 100644 packaging/debs/Debian/changelog_comments/additional_changelog_comments_3.3.5 delete mode 100644 packaging/debs/Debian/changelog_comments/additional_changelog_comments_x.x.x delete mode 100755 packaging/debs/Debian/check-changelog.sh create mode 100755 packaging/debs/Debian/scripts/compare-debian-versions.py create mode 100755 packaging/debs/Debian/scripts/get-debian-package-files-list.sh create mode 100755 packaging/debs/Debian/scripts/update-changelog.sh diff --git a/packaging/debs/Debian/Makefile b/packaging/debs/Debian/Makefile index b89cd41c3d..1259119da4 100644 --- a/packaging/debs/Debian/Makefile +++ b/packaging/debs/Debian/Makefile @@ -7,51 +7,102 @@ endif ifneq ($(words $(SOURCE_DIST_FILE)),1) $(error Multiple source archives found; please specify SOURCE_DIST_FILE) endif +endif VERSION ?= $(patsubst rabbitmq-server-%.tar.xz,%,$(notdir $(SOURCE_DIST_FILE))) ifeq ($(VERSION),) $(error Cannot determine version; please specify VERSION) endif + +# $(DEBIAN_VERSION) doesn't include the package revision: this one is +# only set in debian/changelog. +DEBIAN_VERSION = $(subst -,~,$(VERSION)) +DEBIAN_ORIG_TARBALL = rabbitmq-server_$(DEBIAN_VERSION).orig.tar.xz +UNPACKED_DIR = $(patsubst %.tar.xz,%,$(notdir $(SOURCE_DIST_FILE))) + +DEB_HOST_ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH) +CHANGES_FILE = rabbitmq-server_$(DEBIAN_VERSION)-*_$(DEB_HOST_ARCH).changes + +# Package signing. +# +# At least the key ID is mandatory ($(SIGNING_KEY)). If it's set, we +# enable signing in dpkg-build-package(1), otherwise we ask for an +# unsigned package. +# +# To maintain backward compatibility, the caller can also specify +# $(GNUPG_PATH) and we set GNUPGHOME accordingly. + +ifneq ($(SIGNING_KEY),) + SIGNING_FLAG = -k$(SIGNING_KEY) +ifneq ($(GNUPG_PATH),) + GNUPGHOME = $(GNUPG_PATH)/.gnupg + export GNUPGHOME endif - -DEBIAN_ORIG_TARBALL = rabbitmq-server_$(VERSION).orig.tar.xz -UNPACKED_DIR = rabbitmq-server-$(VERSION) -PACKAGENAME = rabbitmq-server - -ifneq "$(UNOFFICIAL_RELEASE)" "" - SIGNING=-us -uc else - SIGNING=-k$(SIGNING_KEY) + SIGNING_FLAG = -us -uc endif unexport DEPS_DIR unexport ERL_LIBS MAKEOVERRIDES = +.PHONY: all package clean + all: package @: package: clean - cp -a $(SOURCE_DIST_FILE) $(DEBIAN_ORIG_TARBALL) - xzcat $(DEBIAN_ORIG_TARBALL) | tar -xf - +# If a signing key ID was specified, verify that the key is available +# before starting a possibly long build. At the same time, display some +# useful informations on the key so the caller can double-check if he +# wants. + @set -e; \ + if test "$(SIGNING_KEY)"; then \ + echo; \ + echo '--------------------------------------------------'; \ + echo "The package will be signed with key $(SIGNING_KEY):"; \ + gpg -K "$(SIGNING_KEY)"; \ + echo '--------------------------------------------------'; \ + echo; \ + fi +# Because we are creating a source package as well, Debian expects the +# source archive to have a specially formatted name. Copy the original +# archive to a correctly named file. + cp -a "$(SOURCE_DIST_FILE)" "$(DEBIAN_ORIG_TARBALL)" +# Prepare the source directory: we extract the source archive and copy +# the debian/ subdirectory. + xzcat "$(DEBIAN_ORIG_TARBALL)" | tar -xf - rsync -a \ --exclude '.sw?' --exclude '.*.sw?' \ --exclude '.git*' \ --delete --delete-excluded \ - debian/ $(UNPACKED_DIR)/debian/ - UNOFFICIAL_RELEASE=$(UNOFFICIAL_RELEASE) VERSION=$(VERSION) ./check-changelog.sh rabbitmq-server $(UNPACKED_DIR) - cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -sa $(SIGNING) - rm -rf $(UNPACKED_DIR) - + debian/ "$(UNPACKED_DIR)/debian/" +# Possibly update debian/changelog (in the created source directory): +# - if it contains an entry for the specified version, do nothing; +# - otherwise, prepend a generated entry using "1" as the package +# revision. + cd "$(UNPACKED_DIR)"; \ + ../scripts/update-changelog.sh "$(DEBIAN_VERSION)" +# Finally build the package! We ask for both the source package and one +# or more binary packages. + cd "$(UNPACKED_DIR)"; \ + dpkg-buildpackage -sa $(SIGNING_FLAG) +# Before we remove the source directory, copy the possibly updated +# debian/changelog to the original debian subdirectory, if the caller +# asks for it. He is then responsible for committing it. + if test "$(SAVE_DEBIAN_CHANGELOG)" = 'yes'; then \ + cp -a "$(UNPACKED_DIR)/debian/changelog" debian/changelog; \ + fi + rm -rf "$(UNPACKED_DIR)" +# If $(PACKAGES_DIR) is specified, move all package files to that +# location. if test "$(PACKAGES_DIR)"; then \ mkdir -p "$(PACKAGES_DIR)"; \ - mv $(PACKAGENAME)_$(VERSION)* "$(PACKAGES_DIR)"; \ + mv $$(./scripts/get-debian-package-files-list.sh $(CHANGES_FILE)) \ + "$(PACKAGES_DIR)"; \ fi clean: rm -rf $(UNPACKED_DIR) rm -f $(DEBIAN_ORIG_TARBALL) - rm -f $(PACKAGENAME)_*.debian.tar.gz - rm -f $(PACKAGENAME)_*.dsc - rm -f $(PACKAGENAME)_*_*.changes - rm -f $(PACKAGENAME)_*_*.deb + ./scripts/get-debian-package-files-list.sh $(CHANGES_FILE) | xargs rm -f diff --git a/packaging/debs/Debian/changelog_comments/additional_changelog_comments_3.3.5 b/packaging/debs/Debian/changelog_comments/additional_changelog_comments_3.3.5 deleted file mode 100644 index b9a9551c6b..0000000000 --- a/packaging/debs/Debian/changelog_comments/additional_changelog_comments_3.3.5 +++ /dev/null @@ -1,9 +0,0 @@ -# This file contains additional comments for the debian/changelog to be -# appended within the current version's changelog entry. -# Each line will be a separate comment. Do not begin with an *, dch will -# add that. -# For comments longer than one line do not put a line break and dch will -# neatly format it. -# Shell comments are ignored. -# -Changed Uploaders from Emile Joubert to Blair Hester diff --git a/packaging/debs/Debian/changelog_comments/additional_changelog_comments_x.x.x b/packaging/debs/Debian/changelog_comments/additional_changelog_comments_x.x.x deleted file mode 100644 index bbab75965e..0000000000 --- a/packaging/debs/Debian/changelog_comments/additional_changelog_comments_x.x.x +++ /dev/null @@ -1,11 +0,0 @@ -# This file contains additional comments for the debian/changelog to be -# appended within the current version's changelog entry. -# Each line will be a separate comment. Do not begin with an *, dch will -# add that. -# For comments longer than one line do not put a line break and dch will -# neatly format it. -# Shell comments are ignored. -# -# Examples: -#Remove parts made of undercooked chicken -#This is a long line which is the beginning of a long two line comment which I am sure is going to be needed if the script cannot handle it diff --git a/packaging/debs/Debian/check-changelog.sh b/packaging/debs/Debian/check-changelog.sh deleted file mode 100755 index ff25e648fc..0000000000 --- a/packaging/debs/Debian/check-changelog.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -PACKAGE_NAME=$1 -cd $2 - -CHANGELOG_VERSION=$(dpkg-parsechangelog | sed -n 's/^Version: \(.*\)-[^-]*$/\1/p') - -if [ "${CHANGELOG_VERSION}" != "${VERSION}" ]; then - if [ -n "${UNOFFICIAL_RELEASE}" ]; then - echo "${PACKAGE_NAME} (${VERSION}-1) unstable; urgency=low" > debian/changelog.tmp - echo >> debian/changelog.tmp - echo " * Unofficial release" >> debian/changelog.tmp - echo >> debian/changelog.tmp - echo " -- Nobody $(date -R)" >> debian/changelog.tmp - echo >> debian/changelog.tmp - cat debian/changelog >> debian/changelog.tmp - mv -f debian/changelog.tmp debian/changelog - - exit 0 - else - echo - echo There is no entry in debian/changelog for version ${VERSION}! - echo Please create a changelog entry, or set the variable - echo UNOFFICIAL_RELEASE to automatically create one. - echo - - exit 1 - fi -fi diff --git a/packaging/debs/Debian/scripts/compare-debian-versions.py b/packaging/debs/Debian/scripts/compare-debian-versions.py new file mode 100755 index 0000000000..ec138fa623 --- /dev/null +++ b/packaging/debs/Debian/scripts/compare-debian-versions.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python2 + +import apt_pkg +import os.path +import sys + +if len(sys.argv) != 3: + print('Syntax: %s ' % (os.path.basename(sys.argv[0]))) + sys.exit(64) + +a = sys.argv[1] +b = sys.argv[2] + +apt_pkg.init_system() +vc = apt_pkg.version_compare(a,b) + +if vc > 0: + print('%s < %s' % (b, a)) +elif vc == 0: + print('%s = %s' % (a, b)) +elif vc < 0: + print('%s < %s' % (a, b)) diff --git a/packaging/debs/Debian/scripts/get-debian-package-files-list.sh b/packaging/debs/Debian/scripts/get-debian-package-files-list.sh new file mode 100755 index 0000000000..5865ede557 --- /dev/null +++ b/packaging/debs/Debian/scripts/get-debian-package-files-list.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +set -e + +changes_file=$1 +if [ -z "$changes_file" ]; then + echo "Syntax: $(basename $0) " 1>&2 + exit 64 +fi + +if [ ! -f "$changes_file" ]; then + exit 0 +fi + +changes_file_dir=$(dirname "$changes_file") +if test "$changes_file_dir" = '.'; then + changes_file_dir= +else + changes_file_dir="$changes_file_dir/" +fi + +# Include the .changes file itself in the list. +echo "$changes_file_dir$(basename "$changes_file")" + +# We want to match lines with the following format (it starts +# with a single space): +# f752d307528f0ca87d57995c217344ec 5184732 net extra rabbitmq-(...) +awk ' +/^ [a-fA-F0-9]+ / { + if (length($1) == 32) { + print "'$changes_file_dir'" $5; + } +}' < "$changes_file" diff --git a/packaging/debs/Debian/scripts/update-changelog.sh b/packaging/debs/Debian/scripts/update-changelog.sh new file mode 100755 index 0000000000..56dab2227f --- /dev/null +++ b/packaging/debs/Debian/scripts/update-changelog.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +PACKAGE_VERSION=$1 + +PACKAGE_NAME=$(awk '/^Source:/ { print $2; }' < debian/control) +CHANGELOG_VERSION=$(dpkg-parsechangelog | sed -n 's/^Version: \(.*\)-[^-]*$/\1/p') +CHANGELOG_DATE=$(date -R) + +if [ "${CHANGELOG_VERSION}" != "${PACKAGE_VERSION}" ]; then + cat > debian/changelog.tmp < ${CHANGELOG_DATE} + +EOF + + cat debian/changelog >> debian/changelog.tmp + mv -f debian/changelog.tmp debian/changelog +fi + +echo +echo '--------------------------------------------------' +dpkg-parsechangelog +echo '--------------------------------------------------' +echo