Explorar o código

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.
Nathan Kinder %!s(int64=12) %!d(string=hai) anos
pai
achega
463f879b36
Modificáronse 2 ficheiros con 71 adicións e 0 borrados
  1. 16 0
      rpm.mk
  2. 55 0
      rpm/add_patches.sh

+ 16 - 0
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)

+ 55 - 0
rpm/add_patches.sh

@@ -0,0 +1,55 @@
+#!/bin/sh
+
+function usage()
+{
+    echo "Adds patches to a specfile"
+    echo ""
+    echo "$0 <patchdir> <specfile>"
+    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