[Rpm-maint] [patch 2/2] add %{sources} %{patches} and %{macronames}

Panu Matilainen pmatilai at redhat.com
Fri Feb 22 12:11:36 UTC 2008


On Fri, 2 Nov 2007, Peter Jones wrote:

> This Xpatch adds %{sources}, %{patches}, and %{macronames} .  If anybody has 
> any input regarding a better way to do any of this, I'm open to 
> suggestions...

Finally got around to have a proper look at this... there indeed is a 
much easier way to do it: push the sources and patches into a lua table as 
we parse them. This is all it takes (against current rpm.org head, but 
would be easily applicaple to 4.4.2.yawn too):

diff -r 618e925329a9 build/spec.c
--- a/build/spec.c	Fri Feb 15 15:21:22 2008 +0200
+++ b/build/spec.c	Fri Feb 22 13:55:40 2008 +0200
@@ -13,6 +13,7 @@
  #include <rpm/rpmfileutil.h>

  #include "build/buildio.h"
+#include "rpmio/rpmlua.h"

  #include "debug.h"

@@ -329,6 +330,18 @@ int addSource(rpmSpec spec, Package pkg,
  	sprintf(buf, "%sURL%d",
  		(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
  	addMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
+#ifdef WITH_LUA
+	{
+	rpmlua lua = NULL; /* global state */
+	rpmluaPushTable(lua, (flag & RPMBUILD_ISPATCH) ? "patches" : "sources");
+	rpmluav var = rpmluavNew();
+	rpmluavSetListMode(var, 1);
+	rpmluavSetValue(var, RPMLUAV_STRING, body);
+	rpmluaSetVar(lua, var);
+	var = rpmluavFree(var);
+	rpmluaPop(lua);
+	}
+#endif
  	body = _free(body);
      }

diff -r 618e925329a9 macros.in
--- a/macros.in	Fri Feb 15 15:21:22 2008 +0200
+++ b/macros.in	Fri Feb 22 13:55:40 2008 +0200
@@ -1156,6 +1156,9 @@ done \
    %{-C:${_mydir}}%{!-C:.}/configure %{_target_platform} --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} --infodir=%{_infodir} %* ; \
    %{-C:cd ${_mydir}; unset _mydir}

+%patches %{lua: for i, p in ipairs(patches) do print(p.." ") end}
+%sources %{lua: for i, s in ipairs(sources) do print(s.." ") end}
+
  #------------------------------------------------------------------------------
  # Useful perl macros (from Artur Frysiak <wiget at t17.ds.pwr.wroc.pl>)
  #


> Anyway, this means in .spec files you can do something like:
>
> ...
> Patch0: foo.patch
> Patch1: bar.patch
> ...
> %prep
> %setup %setup -q
> git-am -p1 %{patches}
> %build
> ...

This has had me thinking... gendiff is nice to a point but having the 
patches in SCM would be just soooooooo much better. Doable manually of 
course, but even better would be having it automated with build macros,
think of something like:

%setup -q --git
%applypatches -p1 --git

And before some git hater chimes in, replace --git with 
--scm-of-your-choice, no reason why it couldn't support others too.

 	- Panu -





More information about the Rpm-maint mailing list