From 02353ac7e1ea13914d8817ab088d122dfccc2dfd Mon Sep 17 00:00:00 2001 From: Nathan Kinder Date: Wed, 27 Nov 2013 05:23:50 +0000 Subject: [PATCH] Ticket 47611 - Add script to build patched RPMs This adds the ability to build patched RPMs, which can be useful for using with scanning tools like Coverity. The script will create the source tarball from HEAD of the current branch, but it will also add patch files to the specfile if any are found in the rpm directory in the source tree. The intended way of using this is as follows: git diff master workbranch > rpm/workbranch.patch make -f rpm.mk patch_rpms The patch files must end in .patch. Make targets are added for patch_srpms and patch_rpms. --- rpm.mk | 16 ++++++++++++++++ rpm/add_patches.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100755 rpm/add_patches.sh diff --git a/rpm.mk b/rpm.mk index dfbadc6..fffc528 100644 --- a/rpm.mk +++ b/rpm.mk @@ -43,9 +43,25 @@ srpms: rpmroot srpmdistdir tarballs rpmbuildprep cp $(RPMBUILD)/SRPMS/$(RPM_NAME_VERSION)-*.src.rpm dist/srpms/ rm -rf $(RPMBUILD) +patch_srpms: rpmroot srpmdistdir tarballs rpmbuildprep + cp rpm/*.patch $(RPMBUILD)/SOURCES/ + rpm/add_patches.sh rpm $(RPMBUILD)/SPECS/$(PACKAGE).spec + rpmbuild --define "_topdir $(RPMBUILD)" -bs $(RPMBUILD)/SPECS/$(PACKAGE).spec + cp $(RPMBUILD)/SRPMS/$(RPM_NAME_VERSION)-*.src.rpm dist/srpms/ + rm -rf $(RPMBUILD) + rpms: rpmroot srpmdistdir rpmdistdir tarballs rpmbuildprep rpmbuild --define "_topdir $(RPMBUILD)" -ba $(RPMBUILD)/SPECS/$(PACKAGE).spec cp $(RPMBUILD)/RPMS/*/$(RPM_NAME_VERSION)-*.rpm dist/rpms/ cp $(RPMBUILD)/RPMS/*/$(PACKAGE)-*-$(RPM_VERSION)-*.rpm dist/rpms/ cp $(RPMBUILD)/SRPMS/$(RPM_NAME_VERSION)-*.src.rpm dist/srpms/ rm -rf $(RPMBUILD) + +patch_rpms: rpmroot srpmdistdir rpmdistdir tarballs rpmbuildprep + cp rpm/*.patch $(RPMBUILD)/SOURCES/ + rpm/add_patches.sh rpm $(RPMBUILD)/SPECS/$(PACKAGE).spec + rpmbuild --define "_topdir $(RPMBUILD)" -ba $(RPMBUILD)/SPECS/$(PACKAGE).spec + cp $(RPMBUILD)/RPMS/*/$(RPM_NAME_VERSION)-*.rpm dist/rpms/ + cp $(RPMBUILD)/RPMS/*/$(PACKAGE)-*-$(RPM_VERSION)-*.rpm dist/rpms/ + cp $(RPMBUILD)/SRPMS/$(RPM_NAME_VERSION)-*.src.rpm dist/srpms/ + rm -rf $(RPMBUILD) diff --git a/rpm/add_patches.sh b/rpm/add_patches.sh new file mode 100755 index 0000000..690d0b2 --- /dev/null +++ b/rpm/add_patches.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +function usage() +{ + echo "Adds patches to a specfile" + echo "" + echo "$0 " + echo "" + echo " patchdir - directory containing patches with" + echo " .patch extension." + echo " specfile - the specfile to patch." + exit 1 +} + + +if [ $# -ne 2 ]; then + usage +fi + +patchdir=$1 +specfile=$2 + +# Validate our arguments. +if [ ! -d $1 ]; then + echo "Patch directory $1 does not exist or is not a directory." + exit 1 +elif [ ! -f $2 ]; then + echo "Specfile $2 does not exist or is not a file." + exit 1 +fi + +# These keep track of our spec file substitutions. +i=1 +prefix="Source0:" +prepprefix="%setup" + +# Find all patches in the the patch directory. +# to the spec file. +patches=`ls ${patchdir}/*.patch 2>/dev/null` + +# If no patches exist, just exit. +if [ -z "$patches" ]; then + echo "No patches found in $patchdir." + exit 0 +fi + +# Add the patches to the specfile. +for p in $patches; do + p=`basename $p` + echo "Adding patch to spec file - $p" + sed -i -e "/${prefix}/a Patch${i}: ${p}" -e "/$prepprefix/a %patch${i} -p1" $specfile + prefix="Patch${i}:" + prepprefix="%patch${i}" + i=$(($i+1)) +done -- 1.8.1.4