summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConrad Kostecki <conikost@gentoo.org>2020-12-01 00:24:26 +0100
committerConrad Kostecki <conikost@gentoo.org>2020-12-01 11:15:06 +0100
commita7d176da22f2ec428c88cd2514c190f757d9ee26 (patch)
tree71ddeec3211ff68a279b85d28c64d602bd5437e9
parentdev-lua/lua-cjson: bump to version 2.1.0.8 (diff)
downloadgentoo-a7d176da22f2ec428c88cd2514c190f757d9ee26.tar.gz
gentoo-a7d176da22f2ec428c88cd2514c190f757d9ee26.tar.bz2
gentoo-a7d176da22f2ec428c88cd2514c190f757d9ee26.zip
dev-lua/lua-cjson: migrate to lua eclass
Closes: https://bugs.gentoo.org/752618 Package-Manager: Portage-3.0.9, Repoman-3.0.2 Signed-off-by: Conrad Kostecki <conikost@gentoo.org>
-rw-r--r--dev-lua/lua-cjson/files/lua-cjson-2.1.0.8-lua52.patch143
-rw-r--r--dev-lua/lua-cjson/lua-cjson-2.1.0.8-r100.ebuild105
-rw-r--r--profiles/package.mask1
3 files changed, 249 insertions, 0 deletions
diff --git a/dev-lua/lua-cjson/files/lua-cjson-2.1.0.8-lua52.patch b/dev-lua/lua-cjson/files/lua-cjson-2.1.0.8-lua52.patch
new file mode 100644
index 00000000000..8f8c98243f1
--- /dev/null
+++ b/dev-lua/lua-cjson/files/lua-cjson-2.1.0.8-lua52.patch
@@ -0,0 +1,143 @@
+From e8dddaf2c9c370f3676441304955d81543c5cceb Mon Sep 17 00:00:00 2001
+From: leaf corcoran <leafot@gmail.com>
+Date: Sat, 21 Sep 2019 17:31:38 -0700
+Subject: [PATCH 1/5] support lua 5.2 with LUA_COMPAT_ALL
+
+---
+ lua_cjson.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/lua_cjson.c b/lua_cjson.c
+index 2a69699..83118b1 100644
+--- a/lua_cjson.c
++++ b/lua_cjson.c
+@@ -36,6 +36,9 @@
+ * difficult to know object/array sizes ahead of time.
+ */
+
++
++#define LUA_COMPAT_ALL 1
++
+ #include <assert.h>
+ #include <stdint.h>
+ #include <string.h>
+
+From 2b3c3c866701a0110a6ac50a9bec9f23adc2956e Mon Sep 17 00:00:00 2001
+From: leaf corcoran <leafot@gmail.com>
+Date: Sat, 21 Sep 2019 18:01:05 -0700
+Subject: [PATCH 2/5] support lua 5.3 with LUA_COMPAT_5_1
+
+---
+ lua_cjson.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/lua_cjson.c b/lua_cjson.c
+index 83118b1..9d25f7c 100644
+--- a/lua_cjson.c
++++ b/lua_cjson.c
+@@ -38,6 +38,7 @@
+
+
+ #define LUA_COMPAT_ALL 1
++#define LUA_COMPAT_5_1 1
+
+ #include <assert.h>
+ #include <stdint.h>
+
+From 639c4a38bf0b1bddef4bfdb22bb6a3f8493cc3fe Mon Sep 17 00:00:00 2001
+From: leaf corcoran <leafot@gmail.com>
+Date: Sat, 21 Sep 2019 18:18:27 -0700
+Subject: [PATCH 3/5] Lua 5.2+ unpack support
+
+---
+ lua/cjson/util.lua | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/lua/cjson/util.lua b/lua/cjson/util.lua
+index 5d80106..48fa33c 100644
+--- a/lua/cjson/util.lua
++++ b/lua/cjson/util.lua
+@@ -1,5 +1,7 @@
+ local json = require "cjson"
+
++local unpack = unpack or table.unpack
++
+ -- Various common routines used by the Lua CJSON package
+ --
+ -- Mark Pulford <mark@kyne.com.au>
+
+From 9163dd3c431bd7ab45bdb218c32c8c9633ddf2cc Mon Sep 17 00:00:00 2001
+From: leaf corcoran <leafot@gmail.com>
+Date: Sat, 21 Sep 2019 18:43:47 -0700
+Subject: [PATCH 4/5] Lua 5.2+ maxn support
+
+---
+ lua/cjson/util.lua | 12 +++++++++++-
+ 1 file changed, 11 insertions(+), 1 deletion(-)
+
+diff --git a/lua/cjson/util.lua b/lua/cjson/util.lua
+index 48fa33c..2405257 100644
+--- a/lua/cjson/util.lua
++++ b/lua/cjson/util.lua
+@@ -2,6 +2,16 @@ local json = require "cjson"
+
+ local unpack = unpack or table.unpack
+
++local maxn = table.maxn or function(t)
++ local max = 0
++ for k,v in pairs(t) do
++ if type(k) == "number" and k > max then
++ max = k
++ end
++ end
++ return max
++end
++
+ -- Various common routines used by the Lua CJSON package
+ --
+ -- Mark Pulford <mark@kyne.com.au>
+@@ -194,7 +204,7 @@ local function run_test(testname, func, input, should_work, output)
+ local result = {}
+ local tmp = { pcall(func, unpack(input)) }
+ local success = tmp[1]
+- for i = 2, table.maxn(tmp) do
++ for i = 2, maxn(tmp) do
+ result[i - 1] = tmp[i]
+ end
+
+
+From c390998582b959389d0fc039743c96e861902587 Mon Sep 17 00:00:00 2001
+From: leaf corcoran <leafot@gmail.com>
+Date: Sun, 22 Sep 2019 13:43:18 -0700
+Subject: [PATCH 5/5] use macro instead of header defines for Lua 5.2+ support
+
+---
+ lua_cjson.c | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/lua_cjson.c b/lua_cjson.c
+index 9d25f7c..718a5b9 100644
+--- a/lua_cjson.c
++++ b/lua_cjson.c
+@@ -36,10 +36,6 @@
+ * difficult to know object/array sizes ahead of time.
+ */
+
+-
+-#define LUA_COMPAT_ALL 1
+-#define LUA_COMPAT_5_1 1
+-
+ #include <assert.h>
+ #include <stdint.h>
+ #include <string.h>
+@@ -105,6 +101,10 @@
+ #define json_lightudata_mask(ludata) (ludata)
+ #endif
+
++#if LUA_VERSION_NUM > 501
++#define lua_objlen(L,i) lua_rawlen(L, (i))
++#endif
++
+ static const char * const *json_empty_array;
+ static const char * const *json_array;
+
diff --git a/dev-lua/lua-cjson/lua-cjson-2.1.0.8-r100.ebuild b/dev-lua/lua-cjson/lua-cjson-2.1.0.8-r100.ebuild
new file mode 100644
index 00000000000..c7ff3172c0b
--- /dev/null
+++ b/dev-lua/lua-cjson/lua-cjson-2.1.0.8-r100.ebuild
@@ -0,0 +1,105 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+LUA_COMPAT=( lua5-{1..3} luajit )
+
+inherit lua toolchain-funcs
+
+DESCRIPTION="A fast JSON encoding/parsing module for Lua"
+HOMEPAGE="https://www.kyne.com.au/~mark/software/lua-cjson.php https://github.com/openresty/lua-cjson"
+SRC_URI="https://github.com/openresty/${PN}/archive/${PV}.tar.gz -> ${P}.tar.gz"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~amd64 ~arm ~arm64 ~x86"
+IUSE="+internal-fpconv test +threads"
+REQUIRED_USE="
+ threads? ( internal-fpconv )
+ ${LUA_REQUIRED_USE}
+"
+RESTRICT="!test? ( test )"
+
+RDEPEND="${LUA_DEPS}"
+DEPEND="${RDEPEND}"
+BDEPEND="test? ( dev-lang/perl )"
+
+DOCS=( "manual.txt" "NEWS" "performance.txt" "README.md" "THANKS" )
+
+PATCHES=(
+ "${FILESDIR}/${PN}-2.1.0.8-sparse_array_test_fix.patch"
+ "${FILESDIR}/${PN}-2.1.0.8-lua52.patch"
+)
+
+src_prepare() {
+ default
+
+ # Don't install tests
+ sed -e '/cd tests/d' -i Makefile || die
+
+ lua_copy_sources
+}
+
+lua_src_compile() {
+ pushd "${BUILD_DIR}" || die
+
+ local myemakeargs=(
+ "CC=$(tc-getCC)"
+ "CFLAGS=${CFLAGS}"
+ "LDFLAGS=${LDFLAGS}"
+ "LUA_INCLUDE_DIR=$(lua_get_include_dir)"
+ )
+
+ emake "${myemakeargs[@]}"
+
+ popd
+}
+
+src_compile() {
+ lua_foreach_impl lua_src_compile
+}
+
+lua_src_test() {
+ if ! [[ ${ELUA} == "lua5.3" ]]; then
+ pushd "${BUILD_DIR}" || die
+ cd tests || die
+
+ ln -s "${BUILD_DIR}"/cjson.so ./ || die
+ ln -s "${S}"/lua/cjson ./ || die
+
+ ./genutf8.pl || die
+ ./test.lua || die
+
+ popd
+ else
+ ewarn "Not running tests under ${ELUA} because they are known to fail"
+ ewarn "See: https://github.com/openresty/lua-cjson/pull/50"
+ return
+ fi
+}
+
+src_test() {
+ lua_foreach_impl lua_src_test
+}
+
+lua_src_install() {
+ pushd "${BUILD_DIR}" || die
+
+ local myemakeargs=(
+ "DESTDIR=${D}"
+ "LUA_CMODULE_DIR=$(lua_get_lmod_dir)"
+ "LUA_MODULE_DIR=$(lua_get_lmod_dir)"
+ "PREFIX=${EPREFIX}/usr"
+ )
+
+ emake "${myemakeargs[@]}" install install-extra
+
+ popd
+}
+
+src_install() {
+ lua_foreach_impl lua_src_install
+
+ einstalldocs
+}
diff --git a/profiles/package.mask b/profiles/package.mask
index bbaafb49b59..8e2f28c10d2 100644
--- a/profiles/package.mask
+++ b/profiles/package.mask
@@ -531,6 +531,7 @@ dev-lua/luacrypto
>=dev-lua/lpeg-1.0.2-r100
>=dev-lua/lua-argparse-0.6.0-r100
>=dev-lua/lua-bit32-5.3.5-r100
+>=dev-lua/lua-cjson-2.1.0.8-r100
>=dev-lua/lua-term-0.7-r100
>=dev-lua/lua-utf8-0.1.3-r100
>=dev-lua/lua-zlib-1.2-r100