[PATCH] build - apply patchfiles to rpm build dir using git
by Laine Stump
Rather than requiring a matching "patchXXX -p1" line in the specfile
for each "PatchXXX: blah.patch", this patch modifies the specfile so
that all that is needed is a list of patches ala "Patch XXX:
blah.patch", and uses git in a cleverly written (by Jirka Denemark
<jdenemar(a)redhat.com> for the libvirt specfile) script to apply any
patches found in the spec. Here is Jirka's comment from the commit log
in libvirt:
With this change, any patch declared in libvirt.spec with Patch[0-9]* is
automatically applied in %prep. Unlike with the standard %patch[0-9]*,
patches are applied with "git am" to avoid some unexpected results.
However, as a result of this, all patches must be in the right format
for "git am" to be able to apply them; they should ideally be generated
from git using "git format-patch".
It also has the advantage that when you "prep" a new source directory,
it is setup with a git tree so that you can easily create new patches
to add to the rpm (by "git commit"ing the changes, then "git
format-patch ..." to create the patchfiles).
---
netcf.spec.in | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/netcf.spec.in b/netcf.spec.in
index ed17402..1b64ff1 100644
--- a/netcf.spec.in
+++ b/netcf.spec.in
@@ -9,11 +9,26 @@ URL: https://fedorahosted.org/netcf/
Source0: https://fedorahosted.org/released/%{name}/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+# Patches
+# One patch per line, in this format:
+# Patch001: file1.patch
+# Patch002: file2.patch
+# ...
+#
+# The patches will automatically be put into the build source tree
+# during the %prep stage (using git, which is now required for an rpm
+# build)
+#
+
# Default to skipping autoreconf. Distros can change just this one
# line (or provide a command-line override) if they backport any
# patches that touch configure.ac or Makefile.am.
%{!?enable_autotools:%define enable_autotools 0}
+# git is used to build a source tree with patches applied (see the
+# %prep section)
+BuildRequires: git
+
# Fedora 20 / RHEL-7 are where netcf first uses systemd. Although earlier
# Fedora has systemd, netcf still used sysvinit there.
%if 0%{?fedora} >= 20 || 0%{?rhel} >= 7
@@ -88,6 +103,42 @@ The libraries for %{name}.
%prep
%setup -q
+# Patches have to be stored in a temporary file because RPM has
+# a limit on the length of the result of any macro expansion;
+# if the string is longer, it's silently cropped
+%{lua:
+ tmp = os.tmpname();
+ f = io.open(tmp, "w+");
+ count = 0;
+ for i, p in ipairs(patches) do
+ f:write(p.."\n");
+ count = count + 1;
+ end;
+ f:close();
+ print("PATCHCOUNT="..count.."\n")
+ print("PATCHLIST="..tmp.."\n")
+}
+
+git init -q
+git config user.name rpm-build
+git config user.email rpm-build
+git config gc.auto 0
+git add .
+git commit -q -a --author 'rpm-build <rpm-build>' \
+ -m '%{name}-%{version} base'
+
+COUNT=$(grep '\.patch$' $PATCHLIST | wc -l)
+if [ $COUNT -ne $PATCHCOUNT ]; then
+ echo "Found $COUNT patches in $PATCHLIST, expected $PATCHCOUNT"
+ exit 1
+fi
+if [ $COUNT -gt 0 ]; then
+ xargs git am <$PATCHLIST || exit 1
+fi
+echo "Applied $COUNT patches"
+rm -f $PATCHLIST
+
+
%build
%if %{with_libnl1}
%define _with_libnl1 --with-libnl1
--
1.9.3
9 years, 4 months