dcavalca / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone

Blame SOURCES/0001-Introduce-patch_nums-and-source_nums-Lua-variables-i.patch

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