Skip to content

Commit 32ef993

Browse files
committed
more progress on lua-cjson bundling. it now works on Mac OS X, FreeBSD, and Linux, at least.
1 parent 6a75ebc commit 32ef993

File tree

4 files changed

+94
-12
lines changed

4 files changed

+94
-12
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/lua_cjson.c b/lua_cjson.c
2+
index 4b1915a..b46e915 100644
3+
--- a/lua_cjson.c
4+
+++ b/lua_cjson.c
5+
@@ -501,7 +501,7 @@ static int lua_array_length(lua_State *l, json_config_t *cfg)
6+
/* table, startkey */
7+
while (lua_next(l, -2) != 0) {
8+
/* table, key, value */
9+
- if (lua_isnumber(l, -2) &&
10+
+ if (lua_type(l, -2) == LUA_TNUMBER &&
11+
(k = lua_tonumber(l, -2))) {
12+
/* Integer >= 1 ? */
13+
if (floor(k) == k && k >= 1) {

t/sanity.t

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ Type the following commands to build and install:
219219
220220
all:
221221
cd $OPENRESTY_BUILD_DIR/lua-5.1.4 && $(MAKE) linux
222-
cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib
222+
cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib CC=gcc
223223
cd $OPENRESTY_BUILD_DIR/nginx-1.0.5 && $(MAKE)
224224
225225
install:
226226
cd $OPENRESTY_BUILD_DIR/lua-5.1.4 && $(MAKE) install INSTALL_TOP=$(DESTDIR)/usr/local/openresty/lua
227-
cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) install DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib
227+
cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) install DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib CC=gcc
228228
cd $OPENRESTY_BUILD_DIR/nginx-1.0.5 && $(MAKE) install DESTDIR=$(DESTDIR)
229229
230230
clean:
@@ -1483,3 +1483,57 @@ install:
14831483
clean:
14841484
rm -rf build
14851485
1486+
1487+
1488+
=== TEST 30: default (on Mac OS X)
1489+
--- ONLY
1490+
--- cmd: ./configure --dry-run --platform=darwin
1491+
--- out
1492+
platform: macosx (darwin)
1493+
cp -rp bundle/ build/
1494+
cd build
1495+
cd lua-5.1.4
1496+
gmake macosx
1497+
gmake install INSTALL_TOP=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua
1498+
export LUA_LIB='$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/lib'
1499+
export LUA_INC='$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include'
1500+
cd ..
1501+
cd nginx-1.0.5
1502+
./configure --prefix=/usr/local/openresty/nginx \
1503+
--add-module=../ngx_devel_kit-0.2.17 \
1504+
--add-module=../echo-nginx-module-0.37rc1 \
1505+
--add-module=../xss-nginx-module-0.03rc3 \
1506+
--add-module=../set-misc-nginx-module-0.22rc2 \
1507+
--add-module=../form-input-nginx-module-0.07rc5 \
1508+
--add-module=../encrypted-session-nginx-module-0.01 \
1509+
--add-module=../ngx_lua-0.2.1rc4 \
1510+
--add-module=../headers-more-nginx-module-0.15 \
1511+
--add-module=../srcache-nginx-module-0.12 \
1512+
--add-module=../array-var-nginx-module-0.03rc1 \
1513+
--add-module=../memc-nginx-module-0.12 \
1514+
--add-module=../redis2-nginx-module-0.07 \
1515+
--add-module=../upstream-keepalive-nginx-module-0.3 \
1516+
--add-module=../auth-request-nginx-module-0.2 \
1517+
--add-module=../rds-json-nginx-module-0.12rc1 \
1518+
--with-http_ssl_module
1519+
cd ../..
1520+
Type the following commands to build and install:
1521+
gmake
1522+
gmake install
1523+
--- makefile
1524+
.PHONY: all install clean
1525+
1526+
all:
1527+
cd $OPENRESTY_BUILD_DIR/lua-5.1.4 && $(MAKE) macosx
1528+
cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib LDFLAGS='-bundle -undefined dynamic_lookup' CC=gcc
1529+
cd $OPENRESTY_BUILD_DIR/nginx-1.0.5 && $(MAKE)
1530+
1531+
install:
1532+
cd $OPENRESTY_BUILD_DIR/lua-5.1.4 && $(MAKE) install INSTALL_TOP=$(DESTDIR)/usr/local/openresty/lua
1533+
cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) install DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib LDFLAGS='-bundle -undefined dynamic_lookup' CC=gcc
1534+
cd $OPENRESTY_BUILD_DIR/nginx-1.0.5 && $(MAKE) install DESTDIR=$(DESTDIR)
1535+
1536+
clean:
1537+
rm -rf build
1538+
1539+

util/configure

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -528,32 +528,44 @@ _END_
528528

529529
print $in <<"_EOC_";
530530
531-
CFLAGS=\$"\$CFLAGS -DLUA_DEFAULT_PATH='\\"$lualib_prefix/?.lua\\"'"
532-
CFLAGS=\$"\$CFLAGS -DLUA_DEFAULT_CPATH='\\"$lualib_prefix/?.so\\"'"
531+
ngx_lua_dquote='"'
532+
CFLAGS="\$CFLAGS -DLUA_DEFAULT_PATH='\$ngx_lua_dquote$lualib_prefix/?.lua\$ngx_lua_dquote'"
533+
CFLAGS="\$CFLAGS -DLUA_DEFAULT_CPATH='\$ngx_lua_dquote$lualib_prefix/?.so\$ngx_lua_dquote'"
533534
_EOC_
534535

535536
close $in;
536537

537538
unless ($opts->{no_lua_cjson}) {
538539
my $dir = auto_complete 'lua-cjson';
539-
540-
541540
if (!defined $dir) {
542541
die "No lua-cjson found";
543542
}
544543

545-
my $install;
546-
if ($on_solaris) {
547-
$install = "$root_dir/build/install";
544+
my $lua_inc;
545+
if ($opts->{luajit}) {
546+
$lua_inc = $ENV{LUAJIT_INC};
547+
548548
} else {
549-
$install = "install";
549+
$lua_inc = $ENV{LUA_INC};
550550
}
551551

552-
my $lua_inc = $ENV{LUA_INC};
553-
554552
my $extra_opts = " DESTDIR=\$(DESTDIR) LUA_INCLUDE_DIR=$lua_inc " .
555553
"LUA_LIB_DIR=$lualib_prefix";
556554

555+
if ($on_solaris) {
556+
$extra_opts .= " INSTALL=$root_dir/build/install";
557+
}
558+
559+
if ($platform eq 'macosx') {
560+
$extra_opts .= " LDFLAGS='-bundle -undefined dynamic_lookup'";
561+
}
562+
563+
if (defined $cc) {
564+
$extra_opts .= " CC=$cc";
565+
} else {
566+
$extra_opts .= " CC=gcc";
567+
}
568+
557569
push @make_cmds, "cd $root_dir/build/$dir && ".
558570
"\$(MAKE)$extra_opts";
559571

util/mirror-tarballs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ cd ..
206206
ver=1.0.2
207207
$root/util/get-tarball "http://www.kyne.com.au/~mark/software/lua-cjson-$ver.tar.gz" -O "lua-cjson-$ver.tar.gz" || exit 1
208208
tar -xzf lua-cjson-$ver.tar.gz || exit 1
209+
cd lua-cjson-$ver || exit 1
210+
patch -p1 < $root/patches/lua_cjson-$ver-array_detection_fix.patch || exit 1
211+
cd ..
209212

210213
#################################
211214

0 commit comments

Comments
 (0)