Skip to content

Commit

Permalink
Merge pull request #2949 from kgaillot/rpm
Browse files Browse the repository at this point in the history
Fix building RPMs from source distribution
  • Loading branch information
kgaillot committed Nov 21, 2022
2 parents f251a46 + 5df0932 commit 6e9a018
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 21 deletions.
18 changes: 18 additions & 0 deletions doc/abi-check.in
@@ -1,4 +1,13 @@
#!@BASH_PATH@
#
# Copyright 2011-2022 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#

#
# abi-check [-u] <package-name> <version> [...]
#
Expand Down Expand Up @@ -113,6 +122,15 @@ extract_all() {
done
}

die() {
echo "$@" 1>&2
exit 1
}

which git 2>/dev/null || die "abi-check: git must be installed"
git rev-parse --git-dir >/dev/null 2>/dev/null \
|| die "abi-check: must be run from git checkout"

UPLOAD=0
if [ "$1" = "-u" ]; then
UPLOAD=1; shift
Expand Down
64 changes: 47 additions & 17 deletions mk/release.mk
@@ -1,5 +1,5 @@
#
# Copyright 2008-2021 the Pacemaker project contributors
# Copyright 2008-2022 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
Expand All @@ -9,27 +9,56 @@

# Define variables related to release version and such

COMMIT ?= HEAD
COMMIT ?= HEAD

# TAG defaults to DIST when not in a git checkout (e.g. from a distribution),
# TAG defaults to DIST when in a source distribution instead of a git checkout,
# the tag name if COMMIT is tagged, and the full commit ID otherwise.
TAG ?= $(shell T=$$(git describe --tags --exact-match '$(COMMIT)' 2>/dev/null); \
test -n "$${T}" && echo "$${T}" \
|| git log --pretty=format:%H -n 1 '$(COMMIT)' 2>/dev/null || echo DIST)
TAG ?= $(shell \
T=$$(git describe --tags --exact-match '$(COMMIT)' 2>/dev/null); \
[ -n "$${T}" ] && echo "$${T}" \
|| git log --pretty=format:%H -n 1 '$(COMMIT)' 2>/dev/null \
|| echo DIST)

# If DIRTY=anything is passed to make, generated versions will end in ".mod"
# as long as there are uncommitted changes and COMMIT is not set.
DIRTY_EXT = $(shell if [ -n "$(DIRTY)" ] && [ "$(COMMIT)" == "HEAD" ] \
&& ! git diff-index --quiet HEAD --; then \
echo .mod ; fi)
# as long as there are uncommitted changes and COMMIT is not changed from the
# default.
DIRTY_EXT = $(shell [ -n "$(DIRTY)" ] \
&& [ "$(COMMIT)" == "HEAD" ] \
&& ! git diff-index --quiet HEAD -- 2>/dev/null \
&& echo .mod)

# These can be used in case statements to avoid make interpreting parentheses
lparen = (
rparen = )

LAST_RC ?= $(shell git tag -l|sed -n -e 's/^\(Pacemaker-[0-9.]*-rc[0-9]*\)$$/\1/p'|sort -Vr|head -n 1)
LAST_FINAL ?= $(shell git tag -l|sed -n -e 's/^\(Pacemaker-[0-9.]*\)$$/\1/p'|sort -Vr|head -n 1)
LAST_RELEASE ?= $(shell test "Pacemaker-$(VERSION)" = "Pacemaker-" && echo "$(LAST_FINAL)" || echo "Pacemaker-$(VERSION)")
NEXT_RELEASE ?= $(shell echo $(LAST_RELEASE) | awk -F. '/[0-9]+\./{$$3+=1;OFS=".";print $$1,$$2,$$3}')
# git tag of highest-versioned release candidate (such as "Pacemaker-2.1.5-rc2")
# or empty if not in git checkout
LAST_RC ?= $(shell git tag -l 2>/dev/null \
| sed -n -e 's/^\(Pacemaker-[0-9.]*-rc[0-9]*\)$$/\1/p' \
| sort -Vr | head -n 1)

# true if in a git checkout
CHECKOUT = $(shell git rev-parse --git-dir >/dev/null 2>/dev/null \
&& echo true)

# VERSION is set by configure, but we allow some make targets to be run without
# running configure first, so set a reasonable default in that case.
VERSION ?= $(shell if [ -z "$(CHECKOUT)" ]; then \
echo 0.0.0; \
else \
git tag -l \
| sed -n -e 's/^\(Pacemaker-[0-9.]*\)$$/\1/p' \
| sort -Vr | head -n 1; \
fi)

# What the git tag would be for configured VERSION (such as "Pacemaker-2.1.5")
LAST_RELEASE ?= Pacemaker-$(VERSION)

# What the git tag would be for configured VERSION with minor-minor version bump
# (such as "Pacemaker-2.1.6"; this should be manually overriden when bumping
# the major or minor version)
NEXT_RELEASE ?= $(shell echo $(LAST_RELEASE) \
| awk -F. '/[0-9]+\./{$$3+=1;OFS=".";print $$1,$$2,$$3}')

# We have two make targets for creating distributions:
#
Expand All @@ -43,13 +72,14 @@ NEXT_RELEASE ?= $(shell echo $(LAST_RELEASE) | awk -F. '/[0-9]+\./{$$3+=1;OFS=".
# Both targets use the same name for the result, though they generate different
# contents.
#
# The directory is named pacemaker-DIST when not in a git checkout (e.g.
# from a distribution itself), pacemaker-<version_part_of_tag> for tagged
# The directory is named pacemaker-<version> when in a source distribution
# instead of a git checkout, pacemaker-<version_part_of_tag> for tagged
# commits, and pacemaker-<short_commit> otherwise.
top_distdir = $(PACKAGE)-$(shell \
case $(TAG) in \
DIST$(rparen) \
echo DIST;; \
[ -n "$(VERSION)" ] && echo "$(VERSION)" \
|| echo DIST;; \
Pacemaker-*$(rparen) \
echo '$(TAG)' | cut -c11-;; \
*$(rparen) \
Expand Down
21 changes: 17 additions & 4 deletions rpm/Makefile.am
@@ -1,5 +1,5 @@
#
# Copyright 2003-2021 the Pacemaker project contributors
# Copyright 2003-2022 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
Expand Down Expand Up @@ -113,9 +113,16 @@ MOCK_CFG ?= $(shell test -e /etc/fedora-release && echo fedora-$(F)-$(ARCH))
distdir = $(top_distdir)/rpm
TARFILE = $(abs_builddir)/../$(top_distdir).tar.gz

# Create a source distribution based on a git archive. (If we aren't in a git
# checkout, do a make dist instead.)
export:
cd $(abs_srcdir)/..; \
if [ -n "$(DIRTY_EXT)" ]; then \
if [ -z "$(CHECKOUT)" ] && [ -f "$(TARFILE)" ]; then \
echo "`date`: Using existing tarball: $(TARFILE)"; \
elif [ -z "$(CHECKOUT)" ]; then \
$(MAKE) $(AM_MAKEFLAGS) dist; \
echo "`date`: Rebuilt tarball: $(TARFILE)"; \
elif [ -n "$(DIRTY_EXT)" ]; then \
git commit -m "DO-NOT-PUSH" -a; \
git archive --prefix=$(top_distdir)/ -o "$(TARFILE)" HEAD^{tree}; \
git reset --mixed HEAD^; \
Expand Down Expand Up @@ -188,7 +195,12 @@ release:

.PHONY: rc
rc:
$(MAKE) $(AM_MAKEFLAGS) TAG=$(LAST_RC) rpm
if [ -n "$(LAST_RC)" ]; then \
@echo 'rc can only be used in git checkout'; \
false; \
else \
$(MAKE) $(AM_MAKEFLAGS) TAG=$(LAST_RC) rpm; \
fi

.PHONY: chroot
chroot: mock-$(MOCK_CFG) mock-install-$(MOCK_CFG) mock-sh-$(MOCK_CFG)
Expand Down Expand Up @@ -238,12 +250,13 @@ mock-clean:

# Make debugging makefile issues easier
vars:
@echo "CHECKOUT=$(CHECKOUT)"
@echo "VERSION=$(VERSION)"
@echo "COMMIT=$(COMMIT)"
@echo "TAG=$(TAG)"
@echo "DIRTY=$(DIRTY)"
@echo "DIRTY_EXT=$(DIRTY_EXT)"
@echo "LAST_RC=$(LAST_RC)"
@echo "LAST_FINAL=$(LAST_FINAL)"
@echo "LAST_RELEASE=$(LAST_RELEASE)"
@echo "NEXT_RELEASE=$(NEXT_RELEASE)"
@echo "top_distdir=$(top_distdir)"
Expand Down
10 changes: 10 additions & 0 deletions rpm/pacemaker.spec.in
Expand Up @@ -117,6 +117,15 @@
echo 0.%{specversion}.${c: -3} ;;
*%{rparen} echo %{specversion} ;; esac)
%else
%if "%{commit}" == "DIST"
%define archive_version %{pcmkversion}
%define archive_github_url %{archive_version}#/%{name}-%{pcmkversion}.tar.gz
%if %{with pre_release}
%define pcmk_release 0.%{specversion}
%else
%define pcmk_release %{specversion}
%endif
%else
%define archive_version %(c=%{commit}; echo ${c:0:%{commit_abbrev}})
%define archive_github_url %{archive_version}#/%{name}-%{archive_version}.tar.gz
%if %{with pre_release}
Expand All @@ -125,6 +134,7 @@
%define pcmk_release %{specversion}.%{archive_version}.git
%endif
%endif
%endif

## Whether this platform defaults to using systemd as an init system
## (needs to be evaluated prior to BuildRequires being enumerated and
Expand Down

0 comments on commit 6e9a018

Please sign in to comment.