[libvirt] [PATCH] spec: Automatically apply all patches with git

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". Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- libvirt.spec.in | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/libvirt.spec.in b/libvirt.spec.in index 6fcaa3e..0959483 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -425,6 +425,7 @@ BuildRequires: gettext-devel BuildRequires: libtool BuildRequires: /usr/bin/pod2man %endif +BuildRequires: git BuildRequires: perl BuildRequires: python %if %{with_systemd} @@ -1198,6 +1199,41 @@ driver %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_xen} %define _without_xen --without-xen -- 2.1.3

On 11/21/2014 12:20 PM, Jiri Denemark wrote:
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".
I've tried this out in the netcf specfile and it works well there too. So a functional ACK from me. Someone else may have comments on the finer details. (The one thing I wonder about is this - once this patch is in, git will be required for a build even if there are no patches beyond the original tarball. I don't know if this concerns anyone or not...)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- libvirt.spec.in | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
diff --git a/libvirt.spec.in b/libvirt.spec.in index 6fcaa3e..0959483 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -425,6 +425,7 @@ BuildRequires: gettext-devel BuildRequires: libtool BuildRequires: /usr/bin/pod2man %endif +BuildRequires: git BuildRequires: perl BuildRequires: python %if %{with_systemd} @@ -1198,6 +1199,41 @@ driver %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
This is the first I noticed it doesn't use git am -3 (which I always use), but since that option would require the upstream git history to be available, I guess that is pointless here anyway :-)

On 11/21/2014 01:41 PM, Laine Stump wrote:
On 11/21/2014 12:20 PM, Jiri Denemark wrote:
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".
I've tried this out in the netcf specfile and it works well there too. So a functional ACK from me. Someone else may have comments on the finer details.
(The one thing I wonder about is this - once this patch is in, git will be required for a build even if there are no patches beyond the original tarball. I don't know if this concerns anyone or not...)
Doesn't bother me :) Anyone liable to be developing rpms can be assumed to know about git by now.
+if [ $COUNT -gt 0 ]; then + xargs git am <$PATCHLIST || exit 1
This is the first I noticed it doesn't use git am -3 (which I always use), but since that option would require the upstream git history to be available, I guess that is pointless here anyway :-)
Also, _not_ using -3 forces the patch application to be a bit stricter (nothing to 3-way fuzz against), so it is actually desirable as proof that the patches were generated correctly. I'm not seeing any problems in the patch either, and it's had some runtime testing in downstream RHEL builds already, so ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Fri, Nov 21, 2014 at 17:21:07 -0700, Eric Blake wrote:
On 11/21/2014 01:41 PM, Laine Stump wrote:
On 11/21/2014 12:20 PM, Jiri Denemark wrote:
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".
I've tried this out in the netcf specfile and it works well there too. So a functional ACK from me. Someone else may have comments on the finer details.
(The one thing I wonder about is this - once this patch is in, git will be required for a build even if there are no patches beyond the original tarball. I don't know if this concerns anyone or not...)
Doesn't bother me :) Anyone liable to be developing rpms can be assumed to know about git by now.
+if [ $COUNT -gt 0 ]; then + xargs git am <$PATCHLIST || exit 1
This is the first I noticed it doesn't use git am -3 (which I always use), but since that option would require the upstream git history to be available, I guess that is pointless here anyway :-)
Also, _not_ using -3 forces the patch application to be a bit stricter (nothing to 3-way fuzz against), so it is actually desirable as proof that the patches were generated correctly.
I'm not seeing any problems in the patch either, and it's had some runtime testing in downstream RHEL builds already, so ACK.
Pushed, thanks. Jirka
participants (3)
-
Eric Blake
-
Jiri Denemark
-
Laine Stump