Add %{sources} and %{patches} macros to build
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 25 Feb 2008 10:24:22 +0000 (12:24 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 25 Feb 2008 10:24:22 +0000 (12:24 +0200)
- push full patch + source paths to global lua tables
- %{sources} and %{patches} are just easy-access wrappers to accessing
  the lua tables
- "git-am -p1 %{patches}" and enjoy...

build/spec.c
macros.in

index c5915eb..9ec1d66 100644 (file)
@@ -13,6 +13,7 @@
 #include <rpm/rpmfileutil.h>
 
 #include "build/buildio.h"
+#include "rpmio/rpmlua.h"
 
 #include "debug.h"
 
@@ -329,6 +330,19 @@ int addSource(rpmSpec spec, Package pkg, const char *field, rpmTag tag)
        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 */
+       const char * what = (flag & RPMBUILD_ISPATCH) ? "patches" : "sources";
+       rpmluaPushTable(lua, what);
+       rpmluav var = rpmluavNew();
+       rpmluavSetListMode(var, 1);
+       rpmluavSetValue(var, RPMLUAV_STRING, body);
+       rpmluaSetVar(lua, var);
+       var = rpmluavFree(var);
+       rpmluaPop(lua);
+       }
+#endif
        body = _free(body);
     }
     
@@ -445,6 +459,16 @@ rpmSpec newSpec(void)
 
     spec->macros = rpmGlobalMacroContext;
     
+#ifdef WITH_LUA
+    {
+    /* make sure patches and sources tables always exist */
+    rpmlua lua = NULL; /* global state */
+    rpmluaPushTable(lua, "patches");
+    rpmluaPushTable(lua, "sources");
+    rpmluaPop(lua);
+    rpmluaPop(lua);
+    }
+#endif
     return spec;
 }
 
@@ -514,6 +538,12 @@ rpmSpec freeSpec(rpmSpec spec)
     spec->passPhrase = _free(spec->passPhrase);
     spec->cookie = _constfree(spec->cookie);
 
+#ifdef WITH_LUA
+    rpmlua lua = NULL; /* global state */
+    rpmluaDelVar(lua, "patches");
+    rpmluaDelVar(lua, "sources");      
+#endif
+
     spec->sources = freeSources(spec->sources);
     spec->packages = freePackages(spec->packages);
     
index 543e3bf..087b5da 100644 (file)
--- a/macros.in
+++ b/macros.in
@@ -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@t17.ds.pwr.wroc.pl>)
 #