alexk / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
b445f2
From 9ad4b813483f8cf6c641f56387248b33b6dfc570 Mon Sep 17 00:00:00 2001
b445f2
From: Panu Matilainen <pmatilai@redhat.com>
b445f2
Date: Wed, 20 Feb 2019 15:28:30 +0200
b445f2
Subject: [PATCH] Introduce patch_nums and source_nums Lua variables in spec
b445f2
 context
b445f2
b445f2
The pre-existing patches and sources variables only contains patch and
b445f2
source filenames, but for some purposes we need access to the associated
b445f2
patch/source number too. We could use the number as the table key, but
b445f2
that would make the table unsorted. That we could handle in our own
b445f2
macros, but would break compatibility for anybody doing custom stuff
b445f2
with these. So it seems best to just add parallel arrays sharing the
b445f2
same array indexes so that both values are as easily accessible,
b445f2
depending on the need.
b445f2
b445f2
Inspired by Pascal "Pixel" Rigaux's similar patch in Mageia, which differs
b445f2
in that the number-arrays are indexed by the filename and is unordered.
b445f2
Compared to patches/sources this seemed against principle of least
b445f2
surprise, and is slightly more cumbersome int the case we want the number
b445f2
directly, such as in PR #626. The variable names differ so there
b445f2
is no incompatibility to that downstream patch introduced.
b445f2
---
b445f2
 build/parsePreamble.c | 9 +++++++++
b445f2
 build/spec.c          | 3 ++-
b445f2
 2 files changed, 11 insertions(+), 1 deletion(-)
b445f2
b445f2
diff --git a/build/parsePreamble.c b/build/parsePreamble.c
b445f2
index 812c41f9f..9520bac4b 100644
b445f2
--- a/build/parsePreamble.c
b445f2
+++ b/build/parsePreamble.c
b445f2
@@ -322,6 +322,15 @@ static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag
b445f2
 	    rpmluaSetVar(lua, var);
b445f2
 	    rpmluavFree(var);
b445f2
 	    rpmluaPop(lua);
b445f2
+
b445f2
+	    what = (flag & RPMBUILD_ISPATCH) ? "patch_nums" : "source_nums";
b445f2
+	    rpmluaPushTable(lua, what);
b445f2
+	    var = rpmluavNew();
b445f2
+	    rpmluavSetListMode(var, 1);
b445f2
+	    rpmluavSetValueNum(var, p->num);
b445f2
+	    rpmluaSetVar(lua, var);
b445f2
+	    rpmluavFree(var);
b445f2
+	    rpmluaPop(lua);
b445f2
 	}
b445f2
 #endif
b445f2
 	free(body);
b445f2
diff --git a/build/spec.c b/build/spec.c
b445f2
index 80eaca611..55095c6ce 100644
b445f2
--- a/build/spec.c
b445f2
+++ b/build/spec.c
b445f2
@@ -305,7 +305,8 @@ rpmSpec newSpec(void)
b445f2
 #ifdef WITH_LUA
b445f2
     /* make sure patches and sources tables always exist */
b445f2
     rpmlua lua = NULL; /* global state */
b445f2
-    const char * luavars[] = { "patches", "sources", NULL, };
b445f2
+    const char * luavars[] = { "patches", "sources",
b445f2
+			       "patch_nums", "source_nums", NULL, };
b445f2
     for (const char **vp = luavars; vp && *vp; vp++) {
b445f2
 	rpmluaDelVar(lua, *vp);
b445f2
 	rpmluaPushTable(lua, *vp);
b445f2
-- 
b445f2
2.26.2
b445f2