From ec7c8eb8ca85c584ca80e215bbb2397c24a14687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20Wie=C3=ABrs?= Date: Wed, 1 Aug 2012 14:52:37 +0200 Subject: [PATCH 1/2] Implements git commit date into RPM release With this patch one can do `make rpm` and get an RPM file that looks like: rpm-build/noarch/ansible-0.6-0.git201208010541.el6.noarch.rpm My goal was not to rewrite the original SPEC file, and/or the tarball. In other projects what I tend to do is prepare the SPEC file in the tarball with the correct version/release so that rpmbuild works on the (released) tarball as well. If this is wanted, we will have to rewrite the SPEC file on the fly as part of creating the tarball. If there is no git or .git/ available, we will use the current time. --- Makefile | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ad872502ef..6cb7e32478 100644 --- a/Makefile +++ b/Makefile @@ -28,13 +28,21 @@ SITELIB = $(shell python -c "from distutils.sysconfig import get_python_lib; pri # VERSION file provides one place to update the software version VERSION := $(shell cat VERSION) +### Get the branch information from git +ifneq ($(shell which git),) +GIT_DATE := $(shell git log -n 1 --format="%ai") +endif +DATE := $(shell date --date="$(GIT_DATE)" +%Y%m%d%H%M) + # RPM build parameters RPMSPECDIR= packaging/rpm RPMSPEC = $(RPMSPECDIR)/ansible.spec -RPMVERSION := $(shell awk '/Version/{print $$2; exit}' < $(RPMSPEC) | cut -d "%" -f1) -RPMRELEASE := $(shell awk '/Release/{print $$2; exit}' < $(RPMSPEC) | cut -d "%" -f1) RPMDIST = $(shell rpm --eval '%dist') -RPMNVR = "$(NAME)-$(RPMVERSION)-$(RPMRELEASE)$(RPMDIST)" +RPMRELEASE = 1 +ifeq ($(OFFICIAL),) + RPMRELEASE = 0.git$(DATE) +endif +RPMNVR = "$(NAME)-$(VERSION)-$(RPMRELEASE)$(RPMDIST)" ######################################################## @@ -102,6 +110,7 @@ sdist: clean rpmcommon: sdist @mkdir -p rpm-build @cp dist/*.gz rpm-build/ + @sed -e 's#^Version:.*#Version: $(VERSION)#' -e 's#^Release:.*#Release: $(RPMRELEASE)%{?dist}#' $(RPMSPEC) >rpm-build/$(NAME).spec srpm: rpmcommon @rpmbuild --define "_topdir %(pwd)/rpm-build" \ @@ -110,7 +119,8 @@ srpm: rpmcommon --define "_srcrpmdir %{_topdir}" \ --define "_specdir $(RPMSPECDIR)" \ --define "_sourcedir %{_topdir}" \ - -bs $(RPMSPEC) + -bs rpm-build/$(NAME).spec + @rm -f rpm-build/$(NAME).spec @echo "#############################################" @echo "Ansible SRPM is built:" @echo " rpm-build/$(RPMNVR).src.rpm" @@ -123,7 +133,8 @@ rpm: rpmcommon --define "_srcrpmdir %{_topdir}" \ --define "_specdir $(RPMSPECDIR)" \ --define "_sourcedir %{_topdir}" \ - -ba $(RPMSPEC) + -ba rpm-build/$(NAME).spec + @rm -f rpm-build/$(NAME).spec @echo "#############################################" @echo "Ansible RPM is built:" @echo " rpm-build/noarch/$(RPMNVR).noarch.rpm" From 6b774f8cf5202a5a20b2f7004a08c736b189d2b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20Wie=C3=ABrs?= Date: Wed, 1 Aug 2012 15:25:19 +0200 Subject: [PATCH 2/2] Place the freshly built RPM directly into rpm-build/ So we get the exact behavior as the SRPM build --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6cb7e32478..ba0d94f021 100644 --- a/Makefile +++ b/Makefile @@ -133,11 +133,12 @@ rpm: rpmcommon --define "_srcrpmdir %{_topdir}" \ --define "_specdir $(RPMSPECDIR)" \ --define "_sourcedir %{_topdir}" \ + --define "_rpmfilename $(RPMNVR).%%{ARCH}.rpm" \ -ba rpm-build/$(NAME).spec @rm -f rpm-build/$(NAME).spec @echo "#############################################" @echo "Ansible RPM is built:" - @echo " rpm-build/noarch/$(RPMNVR).noarch.rpm" + @echo " rpm-build/$(RPMNVR).noarch.rpm" @echo "#############################################" debian: sdist