From 81c67b3e05fc4229aa4a16e1c6ef379f779ca1a9 Mon Sep 17 00:00:00 2001 From: John Thacker Date: Wed, 27 Apr 2022 07:42:34 -0400 Subject: [PATCH] packaging: Provide workaround for rpm-package from source tarball Users might want to download a source tarball and build an RPM package from it. Have git-export-release.sh use git-archive's 'export-subst' feature so that it can detect whether it is being run from a git repository versus run from source extracted from a tarball produced by git-archive. In the latter case, produce a helpful console message telling the user to copy the downloaded tarball into the binary directory so that the rpm-package target can succeed. Also update the Developer's Guide to suggest this as well. We could try to create our own archive using tar, but there are several possible gotchas, such as in-source builds, excluding a build directory that is a subdirectory of the source dir, excluding unknown different build directories from previous builds, dealing with different options in different versions of tar, etc. This is good enough for the common case, and anyone who wants something more complicated can hopefully create their own tarball. Fix #15167 --- .gitattributes | 1 + docbook/wsdg_src/WSDG_chapter_sources.adoc | 9 ++++--- packaging/source/git-export-release.sh.in | 31 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.gitattributes b/.gitattributes index c9ca36b067..d6e99cb389 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,3 +6,4 @@ .gitignore export-ignore .gitreview export-ignore tools/make-version.pl export-subst +packaging/source/git-export-release.sh.in export-subst diff --git a/docbook/wsdg_src/WSDG_chapter_sources.adoc b/docbook/wsdg_src/WSDG_chapter_sources.adoc index 9be495372a..754dc20cfd 100644 --- a/docbook/wsdg_src/WSDG_chapter_sources.adoc +++ b/docbook/wsdg_src/WSDG_chapter_sources.adoc @@ -940,9 +940,12 @@ to build the Debian Package. ==== Red Hat: .rpm Packages -You can build an RPM package using the `rpm-package` target. The package -version is derived from the current git HEAD, so you must build from a -git checkout. +You can build an RPM package using the `rpm-package` target. If you +are building from a git checkout, the package version is derived from +the current git HEAD. If you are building from source extracted from a +tarball created with `git archive` (such as those downloaded from +http://www.wireshark.org/download.html), you must place the original +tarball into your build directory. The package is built using https://rpm.org/[rpmbuild], which comes as standard on many flavours of Linux, including Red Hat, Fedora, and diff --git a/packaging/source/git-export-release.sh.in b/packaging/source/git-export-release.sh.in index 7242619977..2fc6169875 100755 --- a/packaging/source/git-export-release.sh.in +++ b/packaging/source/git-export-release.sh.in @@ -41,6 +41,37 @@ fi TARBALL="${DESTDIR}/wireshark-${VERSION}.tar.xz" +# A tarball produced by 'git archive' will have the $Format string +# substituted due to the use of 'export-subst' in .gitattributes. +# shellcheck disable=SC2016 +COMMIT='$Format:%H$' + +if [[ $COMMIT != \$F* ]] ; then + # This file was extracted from a tarball produced by git archive + # and so we are not in a git repository. + if [[ -f "$TARBALL" ]] ; then + # git get-tar-commit-id works outside a git repo, as it + # only reads the first 1024 bytes of the tar extended header. + if [[ $(git get-tar-commit-id < <(xzcat "$TARBALL")) == "$COMMIT" ]] ; then + echo "$TARBALL commit ID matches $COMMIT." + else + # Allow people to make changes to a downloaded source tarball + # and re-tar it? + echo "WARNING: $TARBALL is not the original git archive." + fi + exit 0 + fi + + echo "" + echo "The build system cannot produce a source tarball outside of a git repository." + echo "If you are trying to build an RPM package from source extracted from a tarball," + echo "copy it (i.e., wireshark-${VERSION}.tar.xz) to" + echo "$DESTDIR" + echo "and run the build command again." + + exit 1 +fi + COMMIT="${CI_COMMIT_SHA:-HEAD}" STASH_ID=$(git stash create)