Package: dh-lua
Version: 23+nmu2
Severity: wishlist
Tags: patch

Hello,

There is a new lua interpreter in Debian!

It's luasandbox which is a modified lua5.1 targeted at data parsing,
transformation, and analysis.

It's in Debian:
<https://packages.debian.org/unstable/libluasandbox-bin>

The attached patch 4 add support for it in dh-lua. The other patches
are missing bits in git repo.

I've requested on Alioth to be part of the pkg-heka team.

We'll do the following:
- Ensure that those patches don't introduce FTBFS in reverse build-
  dependencies
- Upload dh-lua 24 with those patches
- Patch lua-* package one by one to add luasandbox support.
  Probably starting with:
  - lua-bit32
  - lua-lpeg
  - lua-posix
  - lua-socket
  - lua-systemd (NEW)
>From c9653190b552a8dae855c178f6320a14b1368ed8 Mon Sep 17 00:00:00 2001
From: James McCoy <james...@debian.org>
Date: Fri, 12 Aug 2016 19:58:09 -0400
Subject: [PATCH 2/5] Changelog for 23+nmu1

---
 debian/changelog | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index c20f55f..c63c24a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+dh-lua (23+nmu1) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * Update app.c to emulate lua's ability to read a script from stdin, as used
+    by lua-luv's test suite.  (Closes: #832078)
+
+ -- James McCoy <james...@debian.org>  Fri, 12 Aug 2016 19:58:09 -0400
+
 dh-lua (23) unstable; urgency=medium
 
   * Build depend on txt2man (Closes: #796803) 
-- 
2.10.2

>From c39720bc2dc42e0108d477fd90f9232fb453c0af Mon Sep 17 00:00:00 2001
From: Mathieu Parent <math.par...@gmail.com>
Date: Sat, 5 Nov 2016 22:16:27 +0100
Subject: [PATCH 5/5] Release version 24

---
 debian/changelog | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 459ae3b..0aa07a1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+dh-lua (24) unstable; urgency=medium
+
+  * Team upload
+  * Acknowledge NMUs
+  * Add support for luasandbox (i.e. lua embedded in libluasandbox0)
+
+ -- Mathieu Parent <sath...@debian.org>  Fri, 18 Nov 2016 06:35:41 +0100
+
 dh-lua (23+nmu2) unstable; urgency=medium
 
   * Non-maintainer upload.
-- 
2.10.2

>From 9d56aaf9f3947b5063cd09415203a98f2ac446ee Mon Sep 17 00:00:00 2001
From: James McCoy <james...@debian.org>
Date: Thu, 21 Jul 2016 22:35:58 -0400
Subject: [PATCH 1/5] app.c: Emulate lua's ability to run a script from stdin

If the arg "-" is given, or there are no arguments supplied, tell
luaL_loadfile to load from stdin.

Signed-off-by: James McCoy <james...@debian.org>
---
 test/5.1/app.c | 10 ++++++++--
 test/5.2/app.c | 10 ++++++++--
 test/5.3/app.c | 10 ++++++++--
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/test/5.1/app.c b/test/5.1/app.c
index e5e3da6..781b683 100644
--- a/test/5.1/app.c
+++ b/test/5.1/app.c
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <lauxlib.h>
 #include <lualib.h>
@@ -41,7 +42,12 @@ int main(int argn,char** argv){
 	app_open(L);
 
 	// LOAD
-	rc = luaL_loadfile(L,argv[1]);
+	if (argn < 2 || !strcmp("-", argv[1])) {
+		rc = luaL_loadfile(L, NULL);
+	}
+	else {
+		rc = luaL_loadfile(L,argv[1]);
+	}
 
 	// check for errors
 	if (rc != 0){
@@ -61,7 +67,7 @@ int main(int argn,char** argv){
 	lua_setglobal(L,"arg");
 
 	for(i=2;i<argn;i++) lua_pushstring(L,argv[i]);
-	rc = lua_pcall(L,argn-2,LUA_MULTRET,0);
+	rc = lua_pcall(L,(argn > 2 ? argn-2 : 0),LUA_MULTRET,0);
 	
 	// check for errors
 	if (rc != 0){
diff --git a/test/5.2/app.c b/test/5.2/app.c
index 690751c..669d6b3 100644
--- a/test/5.2/app.c
+++ b/test/5.2/app.c
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <lauxlib.h>
 #include <lualib.h>
@@ -41,7 +42,12 @@ int main(int argn,char** argv){
 	app_open(L);
 
 	// LOAD
-	rc = luaL_loadfile(L,argv[1]);
+	if (argn < 2 || !strcmp("-", argv[1])) {
+		rc = luaL_loadfile(L, NULL);
+	}
+	else {
+		rc = luaL_loadfile(L,argv[1]);
+	}
 
 	// check for errors
 	if (rc != 0){
@@ -61,7 +67,7 @@ int main(int argn,char** argv){
 	lua_setglobal(L,"arg");
 
 	for(i=2;i<argn;i++) lua_pushstring(L,argv[i]);
-	rc = lua_pcall(L,argn-2,LUA_MULTRET,0);
+	rc = lua_pcall(L,(argn > 2 ? argn-2 : 0),LUA_MULTRET,0);
 	
 	// check for errors
 	if (rc != 0){
diff --git a/test/5.3/app.c b/test/5.3/app.c
index 690751c..669d6b3 100644
--- a/test/5.3/app.c
+++ b/test/5.3/app.c
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <lauxlib.h>
 #include <lualib.h>
@@ -41,7 +42,12 @@ int main(int argn,char** argv){
 	app_open(L);
 
 	// LOAD
-	rc = luaL_loadfile(L,argv[1]);
+	if (argn < 2 || !strcmp("-", argv[1])) {
+		rc = luaL_loadfile(L, NULL);
+	}
+	else {
+		rc = luaL_loadfile(L,argv[1]);
+	}
 
 	// check for errors
 	if (rc != 0){
@@ -61,7 +67,7 @@ int main(int argn,char** argv){
 	lua_setglobal(L,"arg");
 
 	for(i=2;i<argn;i++) lua_pushstring(L,argv[i]);
-	rc = lua_pcall(L,argn-2,LUA_MULTRET,0);
+	rc = lua_pcall(L,(argn > 2 ? argn-2 : 0),LUA_MULTRET,0);
 	
 	// check for errors
 	if (rc != 0){
-- 
2.10.2

>From 974149478c1c878cdab644eefb23a17bfabe9fb4 Mon Sep 17 00:00:00 2001
From: Daniel Silverstone <dsilv...@digital-scurf.org>
Date: Sat, 5 Nov 2016 09:58:47 +0000
Subject: [PATCH 3/5] Import Debian version 23+nmu2

---
 Makefile                      |  2 +-
 debian/changelog              | 12 ++++++++++++
 doc/Makefile                  |  2 +-
 make/dh-lua.Makefile.multiple |  2 +-
 make/dh-lua.Makefile.single   |  4 ++--
 5 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index a46c276..94559be 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
 
 DH_LUA_HOME=usr/share/dh-lua/
 DH_HOME=usr/share/perl5/Debian/Debhelper/
-POLICY_VERSION=$(shell dpkg-parsechangelog | grep Version | cut -d : -f 2)
+POLICY_VERSION=$(shell dpkg-parsechangelog | grep '^Version: ' | cut -d : -f 2)
 
 all build: man/dh_lua.1 man/lua-any.1
 	$(MAKE) -C doc/
diff --git a/debian/changelog b/debian/changelog
index c63c24a..459ae3b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,15 @@
+dh-lua (23+nmu2) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * Sort Lua-Versions, patch by Reiner Herrmann <rei...@reiner-h.de>
+    (Closes: #826051)
+  * Sort substvar content, patch by Chris Lamb <la...@debian.org>
+    (Closes: #835646)
+  * Tweak dpkg-parsechangelog usage to cope with changelog entries with
+    'Version' in their text.
+
+ -- Daniel Silverstone <dsilv...@digital-scurf.org>  Sat, 05 Nov 2016 09:58:47 +0000
+
 dh-lua (23+nmu1) unstable; urgency=medium
 
   * Non-maintainer upload.
diff --git a/doc/Makefile b/doc/Makefile
index bcb524d..4452875 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -1,6 +1,6 @@
 all: html/policy.html
 
-POLICY_VERSION=$(shell cd ..;dpkg-parsechangelog | grep Version | cut -d : -f 2)
+POLICY_VERSION=$(shell cd ..;dpkg-parsechangelog | grep '^Version: ' | cut -d : -f 2)
 
 used-vars:
 	lua get_used_vars.lua 
diff --git a/make/dh-lua.Makefile.multiple b/make/dh-lua.Makefile.multiple
index 156d00e..260c8b7 100644
--- a/make/dh-lua.Makefile.multiple
+++ b/make/dh-lua.Makefile.multiple
@@ -2,7 +2,7 @@
 # License: MIT/X
 # vim: ft=make
 
-MODULES=$(wildcard debian/*dh-lua.conf)
+MODULES=$(sort $(wildcard debian/*dh-lua.conf))
 LUA_SINGLE_MAKEFILE=/usr/share/dh-lua/make/dh-lua.Makefile.single
 H=@
 
diff --git a/make/dh-lua.Makefile.single b/make/dh-lua.Makefile.single
index 603d463..fa58745 100644
--- a/make/dh-lua.Makefile.single
+++ b/make/dh-lua.Makefile.single
@@ -414,12 +414,12 @@ installcommon:
 	# debian/substvars
 	$(H)for P in $(shell $(call all_packages_with_luaVersions)); do \
 		echo Filling in debian/$$P.substvars; \
-		echo lua:Versions=`cat debian/lua_versions` | \
+		echo lua:Versions=`LC_ALL=C sort debian/lua_versions` | \
 			$(call merge_with, debian/$$P.substvars);\
 	done
 	$(H)for P in $(shell $(call all_packages_with_luaProvides)); do \
 		ACC=""; \
-		for V in `cat debian/lua_versions`; do \
+		for V in `LC_ALL=C sort debian/lua_versions`; do \
 			PV=`echo $$P | sed "s/^lua-/lua$$V-/"`; \
 			ACC="$$PV, $$ACC"; \
 		done; \
-- 
2.10.2

>From 6523672ac72d3a96f97c04c2478d982cda5b26ba Mon Sep 17 00:00:00 2001
From: Mathieu Parent <math.par...@gmail.com>
Date: Sun, 23 Oct 2016 16:44:11 +0200
Subject: [PATCH 4/5] Add support for luasandbox (i.e. lua embedded in
 libluasandbox0)

---
 Makefile                    |  2 ++
 bin/dh_lua                  |  5 +++
 debian/control              |  2 +-
 doc/policy.txt              |  4 +--
 make/dh-lua.Makefile.single |  3 ++
 test/sandbox/app.c          | 85 +++++++++++++++++++++++++++++++++++++++++++++
 test/sandbox/app.c.conf.in  | 11 ++++++
 7 files changed, 109 insertions(+), 3 deletions(-)
 create mode 100644 test/sandbox/app.c
 create mode 100644 test/sandbox/app.c.conf.in

diff --git a/Makefile b/Makefile
index 94559be..88a5e14 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,7 @@ install:
 	mkdir -p $(DESTDIR)/$(DH_LUA_HOME)/test/5.1/
 	mkdir -p $(DESTDIR)/$(DH_LUA_HOME)/test/5.2/
 	mkdir -p $(DESTDIR)/$(DH_LUA_HOME)/test/5.3/
+	mkdir -p $(DESTDIR)/$(DH_LUA_HOME)/test/sandbox/
 	mkdir -p $(DESTDIR)/$(DH_HOME)/Buildsystem/
 	mkdir -p $(DESTDIR)/$(DH_HOME)/Sequence/
 	mkdir -p $(DESTDIR)/usr/bin/
@@ -29,6 +30,7 @@ install:
 	cp test/5.1/* $(DESTDIR)/$(DH_LUA_HOME)/test/5.1/
 	cp test/5.2/* $(DESTDIR)/$(DH_LUA_HOME)/test/5.2/
 	cp test/5.3/* $(DESTDIR)/$(DH_LUA_HOME)/test/5.3/
+	cp test/sandbox/* $(DESTDIR)/$(DH_LUA_HOME)/test/sandbox/
 	cp debhelper7/buildsystem/* $(DESTDIR)/$(DH_HOME)/Buildsystem/
 	cp debhelper7/sequence/* $(DESTDIR)/$(DH_HOME)/Sequence/
 	cat doc/policy.txt | sed 's/@@V@@/$(POLICY_VERSION)/' \
diff --git a/bin/dh_lua b/bin/dh_lua
index eeef10b..507962a 100755
--- a/bin/dh_lua
+++ b/bin/dh_lua
@@ -96,6 +96,11 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 			print "deduplicating $what\n";
 			doit("ln","-sf", mklorig($what), $dest);
 		}
+		$dest=mklfn($tmp,"sandbox",$what);
+		if (compare($src, $dest) == 0) {
+			print "deduplicating $what\n";
+			doit("ln","-sf", mklorig($what), $dest);
+		}
 	}
 }
 
diff --git a/debian/control b/debian/control
index 26dc733..0c8deb8 100644
--- a/debian/control
+++ b/debian/control
@@ -10,7 +10,7 @@ Homepage: http://pkg-lua.alioth.debian.org/
 
 Package: dh-lua
 Architecture: all
-Depends: ${misc:Depends}, ${perl:Depends}, debhelper (>= 8.0.0), dctrl-tools, libtool, libtool-bin, pkg-config, liblua5.3-dev, lua5.3, liblua5.2-dev, lua5.2, liblua5.1-0-dev, lua5.1, libfile-find-rule-perl
+Depends: ${misc:Depends}, ${perl:Depends}, debhelper (>= 8.0.0), dctrl-tools, libtool, libtool-bin, pkg-config, liblua5.3-dev, lua5.3, liblua5.2-dev, lua5.2, liblua5.1-0-dev, lua5.1, libluasandbox-dev (>=  1.2.1-2~), libluasandbox-bin (>= 1.2.1-2~), libfile-find-rule-perl
 Description: helper tools for maintaining Lua-related packages
  This package contains the Debian policy for the Debian packages relative to
  the Lua scripting language, as well as some tools to help build them.
diff --git a/doc/policy.txt b/doc/policy.txt
index 2a1b8b5..4e6ca9a 100644
--- a/doc/policy.txt
+++ b/doc/policy.txt
@@ -29,7 +29,7 @@ Conventions <a id="ch-conventions"></a>
 In the following we shall write `{VARIABLE}` to mean a schema of file names.
 The following ones are the most relevant:
 
-  - `{LUA_VERSION}` The Lua major version, like `5.1` or `5.2`
+  - `{LUA_VERSION}` The Lua major version, like `5.1`, `5.2`, `5.3` or `sandbox`
   - `{PKG_NAME}` The name of the library, like `expat`, `lpeg` and `sql`
   - `{LUA_MODNAME}` The string used to `require` the module, like `lxp`
 
@@ -342,7 +342,7 @@ while the former is used to infer the deb package name, substituting `.` with
 A special case is when the the configuration file name starts with
 `lua${LUA_VERSION}`.  In that case the `LUA_VERSION` variable can be omitted
 and it is automatically set to the value extracted from the file name.
-Supported values are `5.3`, `5.2` and `5.1`.
+Supported values are `5.3`, `5.2`, `5.1` and `sandbox`.
 This makes it possible to use one single
 conf file to build the library for many Lua version.  It is sufficient to
 name the file like `debian/lua5.1.lpeg.dh-lua.conf` and add a symlink to it
diff --git a/make/dh-lua.Makefile.single b/make/dh-lua.Makefile.single
index fa58745..8fa5b89 100644
--- a/make/dh-lua.Makefile.single
+++ b/make/dh-lua.Makefile.single
@@ -32,6 +32,9 @@ endif
 ifeq "$(LUA_VERSION)" ""
 LUA_VERSION:=$(if $(shell echo $(CONFIGURATION_FILE) | grep ^debian/luajit),jit)
 endif
+ifeq "$(LUA_VERSION)" ""
+LUA_VERSION:=$(if $(shell echo $(CONFIGURATION_FILE) | grep ^debian/luasandbox),sandbox)
+endif
 
 # UID for the LUA_VERSION
 UID=$(shell pwd)/$(LUA_VERSION)-$(PKG_NAME)
diff --git a/test/sandbox/app.c b/test/sandbox/app.c
new file mode 100644
index 0000000..781b683
--- /dev/null
+++ b/test/sandbox/app.c
@@ -0,0 +1,85 @@
+// Copyright: © 2012 Enrico Tassi <gareuselesi...@debian.org>
+// License: MIT/X
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <lauxlib.h>
+#include <lualib.h>
+
+// this should include all the needed libraries and
+// define 
+//   static void app_open(lua_State* L)
+#include "app.c.conf"
+
+int main(int argn,char** argv){
+	int rc;
+	int i;
+	const char *init = getenv("LUA_INIT");
+
+	// create a lua VM
+	lua_State* L = lua_open();
+	if (L == NULL) {
+		fprintf(stderr,"Unable to allocate a lua_State");
+		return 1;
+	}
+
+	// load stdlib
+	lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
+	luaL_openlibs(L);  /* open libraries */
+	lua_gc(L, LUA_GCRESTART, 0);
+
+	// LUA_INIT
+	if (init != NULL && luaL_dostring(L, init)) {
+		const char* error = NULL;
+		error = lua_tostring(L,-1);
+		fprintf(stderr,"app.c: %s\n",error);
+		return 1;
+	}
+
+	// here the specific luaopen_MODULENAME
+	app_open(L);
+
+	// LOAD
+	if (argn < 2 || !strcmp("-", argv[1])) {
+		rc = luaL_loadfile(L, NULL);
+	}
+	else {
+		rc = luaL_loadfile(L,argv[1]);
+	}
+
+	// check for errors
+	if (rc != 0){
+		const char* error = NULL;
+		error = lua_tostring(L,-1);
+		fprintf(stderr,"app.c: %s\n",error);
+		return 1;
+	}
+
+	// RUN!
+	lua_newtable(L);
+	for(i=1;i<argn;i++){
+		lua_pushnumber(L,i-1);
+		lua_pushstring(L,argv[i]);
+		lua_settable(L,-3);
+	}
+	lua_setglobal(L,"arg");
+
+	for(i=2;i<argn;i++) lua_pushstring(L,argv[i]);
+	rc = lua_pcall(L,(argn > 2 ? argn-2 : 0),LUA_MULTRET,0);
+	
+	// check for errors
+	if (rc != 0){
+		const char* error = NULL;
+		error = lua_tostring(L,-1);
+		fprintf(stderr,"app.c: %s\n",error);
+		return 1;
+	}
+
+	// shutdown lua VM
+	lua_close(L);
+
+	// bye!
+	return (rc == 0 ? EXIT_SUCCESS : 1);
+}
diff --git a/test/sandbox/app.c.conf.in b/test/sandbox/app.c.conf.in
new file mode 100644
index 0000000..d4b250b
--- /dev/null
+++ b/test/sandbox/app.c.conf.in
@@ -0,0 +1,11 @@
+// Copyright: © 2012 Enrico Tassi <gareuselesi...@debian.org>
+// License: MIT/X
+
+#include "@@LUA_HEADER@@"
+
+static void app_open(lua_State* L){
+  lua_getglobal(L,"package");
+  lua_getfield(L,-1,"preload");
+  lua_pushcfunction(L,luaopen_@@LUA_MODNAME_CPART_UNDERSCORE@@);
+  lua_setfield(L,-2,"@@LUA_MODNAME_CPART@@");
+}
-- 
2.10.2

Reply via email to