Permalink
Browse files

Update installer to use pgxs.

Moved `t/handler/Makefile` to the root and updated it to support `make installecheck` and an installer script. Other relevant changes.

* Moved the test from `t/test/sql` to `t/sql/test.sql` and added a symlink from `sql` to `t/sql`. This is because `pg_regress` is hard-coded to look for test scripts in `sql`.
* Added `expected/test.out`. This is for `pg_regress` to compare test results.
* Added `test` target using `pg_prove`. You need to install pgTAP to get pg_prove. I'll look at embedding it here soon. Either way, you'll need a recent Test::Harness to use it. It's best to use it for development, though.
* Replace `HOWTO` with `README.plparrot`. It's copied from the first 100 lines or so of pgTAP's `README.pgtap`, and contains build instructions with and without pgxs, as well as testing instructions.
* Added `plparrot.sql.in`. This is the script that can be used to install PL/Parrot. Inserting into `pg_pltemplate` does not appear to be the supported way to add a non-core PL.
  • Loading branch information...
theory committed Jan 28, 2010
1 parent 6c1667d commit 5f7bb98c6b60de44b2bd5f7dc50bd05469442e64
Showing with 149 additions and 130 deletions.
  1. +0 −40 HOWTO
  2. +34 −11 Makefile
  3. +96 −0 README.plparrot
  4. +7 −0 expected/test.out
  5. +6 −0 plparrot.sql.in
  6. +1 −0 sql
  7. +0 −34 src/handler/Makefile
  8. +5 −45 t/{ → sql}/test.sql
View
40 HOWTO
@@ -1,40 +0,0 @@
-You will need to have a GNU make, and a Postgres database instance running (8.2x, 8.3x, 8.4x, 8.5x) with the plpgsql PL language installed:
-
-If you will be creating a new database:
- cd ~/postgresql
- createdb test
- createlang plpgsql test # currently required by pgTAP
-
-Now to build PL/Parrot:
-
- cd ~/git/plparrot
- make
-
-Install it in $libdir
-
- cd src/handler
- make install
-
-Install it in the test database. (Works in PostgreSQL 8.3 or better, as should you ;)
-
- psql test
- INSERT INTO pg_catalog.pg_pltemplate(
- tmplname,
- tmpltrusted,
- tmpldbacreate,
- tmplhandler,
- tmpllibrary
- )
- VALUES (
- 'plparrot',
- true,
- true,
- 'plparrot_call_handler',
- '$libdir/plparrot'
- );
- CREATE LANGUAGE plparrot;
-
-To test PL/Parrot (uses pgTAP)
-
- psql -f t/test.sql test
-
View
@@ -1,17 +1,40 @@
+NAME = plparrot
+MODULE_big = src/handler/plparrot
+OBJS= src/handler/plparrot.o
+DATA_built = plparrot.sql
+REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=plpgsql
+TESTS = $(wildcard t/sql/*.sql)
+REGRESS = $(patsubst t/sql/%.sql,%,$(TESTS))
-all:
- cd src/handler; make
+EXTRA_CLEAN =
-test: all
- psql test --no-psqlrc --no-align --quiet --pset pager= --pset tuples_only=true \
- --set ON_ERROR_ROLLBACK=1 --set ON_ERROR_STOP=1 -f t/test.sql
+ifndef NO_PGXS
+PGXS := $(shell pg_config --pgxs)
+include $(PGXS)
+else
+subdir = contrib/plparrot
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
-clean:
- cd src/handler; make clean
+PARROTINCLUDEDIR = $(shell parrot_config includedir)
+PARROTVERSION = $(shell parrot_config versiondir)
+PARROTINC = "$(PARROTINCLUDEDIR)$(PARROTVERSION)"
+PARROTLDFLAGS = $(shell parrot_config ldflags)
+PARROTLINKFLAGS = $(shell parrot_config inst_libparrot_linkflags)
-redo: clean all
+# We need to do various things with various versions of PostgreSQL.
+# VERSION = $(shell $(PG_CONFIG) --version | awk '{print $$2}')
+# PGVER_MAJOR = $(shell echo $(VERSION) | awk -F. '{ print ($$1 + 0) }')
+# PGVER_MINOR = $(shell echo $(VERSION) | awk -F. '{ print ($$2 + 0) }')
+# PGVER_PATCH = $(shell echo $(VERSION) | awk -F. '{ print ($$3 + 0) }')
-redotest: clean test
+# this is not quite working yet
+#PARROT_CCFLAGS=$(shell ~/svn/parrot/parrot_config ccflags)
+#PARROT_CCFLAGS2=$(shell ~/svn/parrot/parrot_config ccflags_provisional)
+override CPPFLAGS := -I$(PARROTINC) -I$(srcdir) $(CPPFLAGS)
+override CFLAGS := $(PARROTLDFLAGS) $(PARROTLINKFLAGS) $(CFLAGS)
-install: all
- cd src/handler; make install
+test:
+ pg_prove --pset tuples_only=1 $(TESTS)
View
@@ -0,0 +1,96 @@
+PL/Parrot 0.01
+==============
+
+PL/Parrot is a PostgreSQL procedural language for the Parrot virtual machine.
+
+Installation
+============
+
+For the impatient, to install PL/Parrot into a PostgreSQL database, just do this:
+
+ make
+ make install
+ make installcheck
+
+If you encounter an error such as:
+
+ "Makefile", line 8: Need an operator
+
+You need to use GNU make, which may well be installed on your system as
+'gmake':
+
+ gmake
+ gmake install
+ gmake installcheck
+
+If you encounter an error such as:
+
+ make: pg_config: Command not found
+
+Be sure that you have `pg_config` installed and in your path. If you used a
+package management system such as RPM to install PostgreSQL, be sure that the
+`-devel` package is also installed. If necessary, add the path to `pg_config`
+to your `$PATH` environment variable:
+
+ env PATH=$PATH:/path/to/pgsql/bin \
+ make && make install && make installcheck
+
+And finally, if all that fails, copy the entire distribution directory to the
+`contrib/` subdirectory of the PostgreSQL source tree and try it there without
+the `$USE_PGXS` variable:
+
+ make NO_PGXS=1
+ make install NO_PGXS=1
+ make installcheck NO_PGXS=1
+
+If you encounter an error such as:
+
+ ERROR: must be owner of database regression
+
+You need to run the test suite using a super user, such as the default
+"postgres" super user:
+
+ make installcheck PGUSER=postgres
+
+Testing PL/Parrot with PL/Parrot
+------------------------
+
+In addition to the PostgreSQL-standard `installcheck` target, the `test`
+target uses the `pg_prove` Perl program to do its testing, which requires
+TAP::Harness, included in
+[Test::Harness](http://search.cpan.org/dist/Test-Harness/ "Test::Harness on
+CPAN") 3.x. You'll need to make sure that you use a database with PL/pgSQL
+loaded, or else the tests won't work. `pg_prove` supports a number of
+environment variables that you might need to use, including all the usual
+PostgreSQL client environment variables:
+
+* `$PGDATABASE`
+* `$PGHOST`
+* `$PGPORT`
+* `$PGUSER`
+
+You can use it to run the test suite as a database super user like so:
+
+ make test PGUSER=postgres
+
+Of course, if you're running the tests from the `contrib/` directory, you
+should add the `NO_PGXS` variable.
+
+Adding PL/Parrot to a Database
+--------------------------
+
+Once PL/Parrot has been built and tested, you can install it into a
+PL/pgSQL-enabled database:
+
+ psql -d dbname -f plparrot.sql
+
+If you want PL/Parrot to be available to all new databases, install it into the
+"template1" database:
+
+ psql -d template1 -f plparrot.sql
+
+The `plparrot.sql script will also be installed in the `contrib` directory
+under the directory output by `pg_config --sharedir`. So you can always do
+this:
+
+ psql -d template1 -f `pg_config --sharedir`/contrib/plparrot.sql
View
@@ -0,0 +1,7 @@
+\unset ECHO
+1..5
+ok 1 - We can return void
+ok 2 - We can return an int
+ok 3 - We can return an int that was passed as an arg
+ok 4 - We can return a float
+ok 5 - We can return a varchar
View
@@ -0,0 +1,6 @@
+-- handler function
+CREATE FUNCTION plparrot_call_handler ()
+RETURNS language_handler AS 'MODULE_PATHNAME' LANGUAGE C;
+
+-- language
+CREATE LANGUAGE plparrot HANDLER plparrot_call_handler;
View
1 sql
View
@@ -1,34 +0,0 @@
-MODULE_big = plparrot
-NAME = plparrot
-
-OBJS = plparrot.o
-
-EXTRA_CLEAN =
-
-ifndef DONT_USE_PGXS
-PGXS := $(shell pg_config --pgxs)
-include $(PGXS)
-else
-subdir = contrib/plparrot
-top_builddir = ../..
-include $(top_builddir)/src/Makefile.global
-include $(top_srcdir)/contrib/contrib-global.mk
-endif
-
-PARROTINCLUDEDIR = $(shell parrot_config includedir)
-PARROTVERSION = $(shell parrot_config versiondir)
-PARROTINC = "$(PARROTINCLUDEDIR)$(PARROTVERSION)"
-PARROTLDFLAGS = $(shell parrot_config ldflags)
-PARROTLINKFLAGS = $(shell parrot_config inst_libparrot_linkflags)
-
-# We need to do various things with various versions of PostgreSQL.
-VERSION = $(shell $(PG_CONFIG) --version | awk '{print $$2}')
-PGVER_MAJOR = $(shell echo $(VERSION) | awk -F. '{ print ($$1 + 0) }')
-PGVER_MINOR = $(shell echo $(VERSION) | awk -F. '{ print ($$2 + 0) }')
-PGVER_PATCH = $(shell echo $(VERSION) | awk -F. '{ print ($$3 + 0) }')
-
-# this is not quite working yet
-#PARROT_CCFLAGS=$(shell ~/svn/parrot/parrot_config ccflags)
-#PARROT_CCFLAGS2=$(shell ~/svn/parrot/parrot_config ccflags_provisional)
-override CPPFLAGS := -I$(PARROTINC) -I$(srcdir) $(CPPFLAGS)
-override CFLAGS := $(PARROTLDFLAGS) $(PARROTLINKFLAGS) $(CFLAGS)
@@ -1,4 +1,4 @@
-\set ECHO
+\unset ECHO
\set QUIET 1
-- Turn off echo and keep things quiet.
-- Format the output for nice TAP.
@@ -8,35 +8,15 @@
-- Revert all changes on failure.
\set ON_ERROR_ROLLBACK 1
\set ON_ERROR_STOP true
-\set QUIET 1
+
-- Load the TAP functions.
BEGIN;
- \i pgtap.sql
+\i pgtap.sql
+\i plparrot.sql
+
-- Plan the tests.
SELECT plan(5);
--- TODO: Make this configurable
-CREATE OR REPLACE FUNCTION setup_plparrot()
-RETURNS BOOLEAN
-LANGUAGE SQL
-AS $$
-INSERT INTO pg_catalog.pg_pltemplate(
- tmplname,
- tmpltrusted,
- tmpldbacreate,
- tmplhandler,
- tmpllibrary
-)
-VALUES (
- 'plparrot',
- true,
- true,
- 'plparrot_call_handler',
- '$libdir/plparrot'
-);
-SELECT true;
-$$;
-
CREATE OR REPLACE FUNCTION create_plparrot()
RETURNS BOOLEAN
LANGUAGE SQL
@@ -46,26 +26,6 @@ SELECT true;
$$;
-- These functions should be written in PIR
-SELECT
- CASE WHEN EXISTS(
- SELECT 1 FROM pg_catalog.pg_pltemplate WHERE tmplname='plparrot'
- )
- THEN
- true
- ELSE
- setup_plparrot()
- END;
-
-SELECT
- CASE WHEN EXISTS(
- SELECT 1 FROM pg_catalog.pg_language WHERE lanname='plparrot'
- )
- THEN
- true
- ELSE
- create_plparrot()
- END;
-
CREATE FUNCTION test_void() RETURNS void AS $$ FAIL $$ LANGUAGE plparrot;
CREATE FUNCTION test_int() RETURNS int AS $$ select 1 as result $$ LANGUAGE plparrot;

0 comments on commit 5f7bb98

Please sign in to comment.