Permalink
Browse files

Merge remote-tracking branch 'origin/master' into postgrest

Conflicts:
	README
  • Loading branch information...
2 parents 862c16d + f919997 commit 8327886564700ef5c21a22afcfe19d5538fe50a9 @audreyt committed Dec 28, 2012
Showing with 1,962 additions and 107 deletions.
  1. +14 −0 Changes
  2. +7 −7 META.json
  3. +40 −43 Makefile
  4. +38 −0 Makefile.v8
  5. +33 −14 README
  6. +134 −2 doc/plv8.md
  7. +20 −0 expected/json_conv.out
  8. +88 −0 expected/plv8.out
  9. +371 −0 expected/window.out
  10. +145 −40 plv8.cc
  11. +102 −1 plv8.h
  12. +7 −0 plv8.sql.common
  13. +465 −0 plv8_func.cc
  14. +190 −0 plv8_type.cc
  15. +11 −0 sql/json_conv.sql
  16. +63 −0 sql/plv8.sql
  17. +229 −0 sql/window.sql
  18. +5 −0 uninstall_plv8.sql
View
@@ -1,5 +1,19 @@
Revision history for plv8
+1.3.0 2012-12-08
+ - Make two dialects (plcoffee, plls) official sub-extensions.
+ - Implement builtin json type conversion.
+ - Static build and automatic v8 build via 'static' target.
+ - Implement v8's remote debugger if enabled.
+ - Implement bytea type conversion and typed array.
+ - Allow polymorphic and internal types in argument and return types.
+ - Support user defined window functions.
+ - Potential bug fixes.
+
+1.2.1 2012-12-08
+ - Fix a crash in returning array value from array-return function.
+ - Fix trigger so that returned NULL can be handled correctly.
+
1.2.0 2012-07-20
- Check the field names match for SRFs.
- Fix EpochToDate to handle non integer timestamp case.
View
@@ -2,7 +2,7 @@
"name": "plv8",
"abstract": "A procedural language in JavaScript powered by V8",
"description": "plv8 is a trusted procedural language that is safe to use, fast to run and easy to develop.",
- "version": "1.3.0devel",
+ "version": "1.3.0",
"maintainer": [
"Hitoshi Harada <umi.tanuki@gmail.com>",
"Andrew Dunstan <AMDunstan@gmail.com>",
@@ -26,21 +26,21 @@
},
"provides": {
"plv8": {
- "file": "plv8--1.3.0devel.sql",
+ "file": "plv8--1.3.0.sql",
"docfile": "doc/plv8.md",
- "version": "1.3.0devel",
+ "version": "1.3.0",
"abstract": "A procedural language in JavaScript"
},
"plcoffee": {
- "file": "plcoffee--1.3.0devel.sql",
+ "file": "plcoffee--1.3.0.sql",
"docfile": "doc/plv8.md",
- "version": "1.3.0devel",
+ "version": "1.3.0",
"abstract": "A procedural language in CoffeeScript"
},
"plls": {
- "file": "plls--1.3.0devel.sql",
+ "file": "plls--1.3.0.sql",
"docfile": "doc/plv8.md",
- "version": "1.3.0devel",
+ "version": "1.3.0",
"abstract": "A procedural language in LiveScript"
}
},
View
@@ -2,21 +2,17 @@
#
# Makefile for plv8
#
-# @param V8_SRCDIR path to V8 source directory, used for include files
-# @param V8_OUTDIR path to V8 output directory, used for library files
-# @param V8_STATIC_SNAPSHOT if defined, statically link to v8 with snapshot
-# @param V8_STATIC_NOSNAPSHOT if defined, statically link to v8 w/o snapshot
# @param DISABLE_DIALECT if defined, not build dialects (i.e. plcoffee, etc)
+# @param ENABLE_DEBUGGER_SUPPORT enables v8 deubbger agent
#
-# There are three ways to build plv8.
+# There are two ways to build plv8.
# 1. Dynamic link to v8 (default)
-# 2. Static link to v8 with snapshot, if V8_STATIC_SNAPSHOT is defined
-# 3. Static link to v8 w/o snapshot, if V8_STATIC_NOSNAPSHOT is defined
-# In either case, V8_OUTDIR should point to the v8 output directory (such as
-# $(HOME)/v8/out/native) if linker doesn't find it automatically.
+# You need to have libv8.so and header file installed.
+# 2. Static link to v8 with snapshot
+# 'make static' will download v8 and build, then statically link to it.
#
#-----------------------------------------------------------------------------#
-PLV8_VERSION = 1.3.0devel
+PLV8_VERSION = 1.3.0
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
@@ -40,47 +36,27 @@ DATA += plcoffee.control plcoffee--$(PLV8_VERSION).sql \
plls.control plls--$(PLV8_VERSION).sql
endif
DATA_built = plv8.sql
-REGRESS = init-extension plv8 inline json startup_pre startup varparam
+REGRESS = init-extension plv8 inline json startup_pre startup varparam json_conv \
+ window
ifndef DISABLE_DIALECT
REGRESS += dialect
endif
-
-# V8 build options. See the top comment.
-V8_STATIC_SNAPSHOT_LIBS = libv8_base.a libv8_snapshot.a
-V8_STATIC_NOSNAPSHOT_LIBS = libv8_base.a libv8_nosnapshot.a
-ifdef V8_STATIC_SNAPSHOT
- ifdef V8_OUTDIR
-SHLIB_LINK += $(addprefix $(V8_OUTDIR)/, $(V8_STATIC_SNAPSHOT_LIBS))
- else
-SHLIB_LINK += $(V8_STATIC_SNAPSHOT_LIBS)
- endif
-else
- ifdef V8_STATIC_NOSNAPSHOT
- ifdef V8_OUTDIR
-SHLIB_LINK += $(addprefix $(V8_OUTDIR)/, $(V8_STATIC_NOSNAPSHOT_LIBS))
- else
-SHLIB_LINK += $(V8_STATIC_NOSNAPSHOT_LIBS)
- endif
- else
SHLIB_LINK += -lv8
- ifdef V8_OUTDIR
-SHLIB_LINK += -L$(V8_OUTDIR)
- endif
- endif
-endif
-OPTFLAGS = -O2
-CCFLAGS = -Wall $(OPTFLAGS)
-ifdef V8_SRCDIR
-override CPPFLAGS += -I$(V8_SRCDIR)/include
+# v8's remote debugger is optional at the moment, since we don't know
+# how much of the v8 installation is built with debugger enabled.
+ifdef ENABLE_DEBUGGER_SUPPORT
+OPT_ENABLE_DEBUGGER_SUPPORT = -DENABLE_DEBUGGER_SUPPORT
endif
+OPTFLAGS = -O2
+CCFLAGS = -Wall $(OPTFLAGS) $(OPT_ENABLE_DEBUGGER_SUPPORT)
all:
plv8_config.h: plv8_config.h.in Makefile
sed -e 's/^#undef PLV8_VERSION/#define PLV8_VERSION "$(PLV8_VERSION)"/' $< > $@
-%.o : %.cc plv8_config.h
+%.o : %.cc plv8_config.h plv8.h
$(CUSTOM_CC) $(CCFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $<
# Convert .js to .cc
@@ -98,7 +74,7 @@ ifeq ($(shell test $(PG_VERSION_NUM) -ge 90100 && echo yes), yes)
DATA_built =
all: $(DATA)
%--$(PLV8_VERSION).sql: plv8.sql.common
- sed -e 's/@LANG_NAME@/$*/g' $< | $(CC) -E -P $(CPPFLAGS) - > $@
+ sed -e 's/@LANG_NAME@/$*/g' $< | $(CC) -E -P $(CPPFLAGS) -DLANG_$* - > $@
%.control: plv8.control.common
sed -e 's/@PLV8_VERSION@/$(PLV8_VERSION)/g' $< | $(CC) -E -P -DLANG_$* - > $@
modules:
@@ -109,27 +85,39 @@ modules:
subclean:
rm -f plv8_config.h $(DATA) $(JSCS)
+ifeq ($(shell test $(PG_VERSION_NUM) -lt 90200 && echo yes), yes)
+REGRESS := $(filter-out json_conv, $(REGRESS))
+endif
+
else # < 9.1
ifeq ($(shell test $(PG_VERSION_NUM) -ge 90000 && echo yes), yes)
-REGRESS := init $(filter-out init-extension dialect, $(REGRESS))
+REGRESS := init $(filter-out init-extension dialect json_conv, $(REGRESS))
else # < 9.0
-REGRESS := init $(filter-out init-extension inline startup varparam dialect, $(REGRESS))
+REGRESS := init $(filter-out init-extension inline startup \
+ varparam dialect json_conv window, $(REGRESS))
endif
DATA = uninstall_plv8.sql
%.sql.in: plv8.sql.common
- sed -e 's/@LANG_NAME@/$*/g' $< | $(CC) -E -P $(CPPFLAGS) - > $@
+ sed -e 's/@LANG_NAME@/$*/g' $< | $(CC) -E -P $(CPPFLAGS) -DLANG_$* - > $@
subclean:
rm -f plv8_config.h *.sql.in $(JSCS)
endif
clean: subclean
+# build will be created by Makefile.v8
+distclean:
+ rm -rf build
+
+static:
+ $(MAKE) -f Makefile.v8
+
# Check if META.json.version and PLV8_VERSION is equal.
# Ideally we want to have only one place for this number, but parsing META.json
# is a bit challenging; at one time we had v8/d8 parsing META.json to pass
@@ -141,6 +129,15 @@ META_VER := $(shell v8 -e 'print(JSON.parse(read("META.json")).version)' 2>/dev/
ifndef META_VER
META_VER := $(shell d8 -e 'print(JSON.parse(read("META.json")).version)' 2>/dev/null)
endif
+ifndef META_VER
+META_VER := $(shell lsc -e 'console.log(JSON.parse(require("fs").readFileSync("META.json")).version)' 2>/dev/null)
+endif
+ifndef META_VER
+META_VER := $(shell coffee -e 'console.log(JSON.parse(require("fs").readFileSync("META.json")).version)' 2>/dev/null)
+endif
+ifndef META_VER
+META_VER := $(shell node -e 'console.log(JSON.parse(require("fs").readFileSync("META.json")).version)')
+endif
integritycheck:
ifneq ($(META_VER),)
View
@@ -0,0 +1,38 @@
+#-----------------------------------------------------------------------------#
+#
+# Makefile for v8 static link
+#
+# 'make static' will download the v8 source and build it, then build plv8
+# with statically link to v8 with snapshot. This assumes certain directory
+# structure in v8 which may be different from version to another, but user
+# can specify the v8 version by AUTOV8_VERSION, too.
+#-----------------------------------------------------------------------------#
+AUTOV8_VERSION = 3.14.5
+AUTOV8_DIR = build/v8-$(AUTOV8_VERSION)
+AUTOV8_OUT = build/v8-$(AUTOV8_VERSION)/out/native
+AUTOV8_LIB = $(AUTOV8_OUT)/libv8_snapshot.a
+AUTOV8_STATIC_LIBS = libv8_base.a libv8_snapshot.a
+
+SHLIB_LINK += $(addprefix $(AUTOV8_OUT)/, $(AUTOV8_STATIC_LIBS))
+# We are sure the static buid can support debugger
+ENABLE_DEBUGGER_SUPPORT=1
+
+all: $(AUTOV8_LIB)
+
+# For some reason, this solves parallel make dependency.
+plv8_config.h: $(AUTOV8_LIB)
+
+$(AUTOV8_DIR):
+ mkdir -p build
+ curl -L 'https://github.com/v8/v8/archive/$(AUTOV8_VERSION).tar.gz' \
+ | tar zxf - -C build
+
+$(AUTOV8_LIB): $(AUTOV8_DIR)
+ $(MAKE) -C build/v8-$(AUTOV8_VERSION) dependencies
+ $(MAKE) -C build/v8-$(AUTOV8_VERSION) native
+
+include Makefile
+
+CCFLAGS += -I$(AUTOV8_DIR)/include
+# We're gonna build static link. Rip it out after include Makefile
+SHLIB_LINK := $(filter-out -lv8, $(SHLIB_LINK))
View
@@ -30,44 +30,48 @@ REQUIREMENT
plv8 is tested with:
-- PG: version 8.4, 9.0, 9.1 and 9.2dev (maybe older are allowed)
-- V8: version 3.6.2
+- PG: version 8.4, 9.0, 9.1, 9.2 and 9.3dev (maybe older are allowed)
+- V8: version 3.14.5
- g++: version 4.5.1
Also all tools that PostgreSQL and V8 require to be built are required.
INSTALL
-------
-If you use pgxn client, you don't have to worry much. It does everything.
-If you are building plv8 from source, make sure V8 include files are in the
-system include directories, or you can pass V8 source path via V8_SRCDIR, and
-if so, you'll probably need V8_OUTDIR pointing where libv8 is located.
-Run make:
+There are two ways to build plv8. The first is default `make`, which depends
+on system-installed libv8 and plv8 will be dynamically link to it. The second
+is `make static`, which will download v8 soure at a specific version and build
+it, and statically link plv8 to it. PGXN install will use the former, while
+you can do the latter manually if you have not installed v8 yet.
- $ make V8_SRCDIR=/path/to/v8 V8_OUTDIR=/path/to/v8/out/native install
- $ make modules
-
-If you prefer to build plv8 statically linking with v8, try V8_STATIC_SNAPSHOT
-or V8_STATIC_NOSNAPSHOT. Consult Makefile for more detail.
+To install native FS connectivity, run `make modules` after `make install`.
Once you installed plv8 into your dabase, create language via
$ psql -c 'CREATE EXTENSION plv8'
$ psql -c 'CREATE EXTENSION plls'
$ psql -c 'CREATE EXTENSION plcoffee'
-in 9.1, or in the prior versions
+in 9.1 or later, or in the prior versions
$ psql -f plv8.sql
to create database objects.
+In mingw64, you may have difficulty in building plv8. If so, try to make
+the following changes in Makefile.
+
+ CUSTOM_CC = gcc
+ SHLIB_LINK := $(SHLIB_LINK) -lv8 -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic -lm
+
+For more detail, please refer to http://code.google.com/p/plv8js/issues/detail?id=29
+
TEST
----
plv8 supports installcheck test. Make sure set custom_variable_classes = 'plv8'
-in your postgresql.conf and
+in your postgresql.conf (before 9.2) and run
$ make installcheck
@@ -89,6 +93,21 @@ EXAMPLE (JAVASCRIPT)
{"name":"Tom","age":"29"}
(1 row)
+EXAMPLE (COFFEESCRIPT)
+----------------------
+
+ CREATE OR REPLACE FUNCTION plcoffee_test(keys text[], vals text[])
+ RETURNS text AS $$
+ return JSON.stringify(keys.reduce(((o, key, idx) ->
+ o[key] = vals[idx]; return o), {}), {})
+ $$ LANGUAGE plcoffee IMMUTABLE STRICT;
+
+ SELECT plcoffee_test(ARRAY['name', 'age'], ARRAY['Tom', '29']);
+ plcoffee_test
+ ---------------------------
+ {"name":"Tom","age":"29"}
+ (1 row)
+
EXAMPLE (LIVESCRIPT)
--------------------
Oops, something went wrong.

0 comments on commit 8327886

Please sign in to comment.