Skip to content

Commit

Permalink
Update installer to use pgxs.
Browse files Browse the repository at this point in the history
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 5f7bb98
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 130 deletions.
40 changes: 0 additions & 40 deletions HOWTO

This file was deleted.

45 changes: 34 additions & 11 deletions Makefile
@@ -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)
96 changes: 96 additions & 0 deletions README.plparrot
@@ -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
7 changes: 7 additions & 0 deletions expected/test.out
@@ -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
6 changes: 6 additions & 0 deletions plparrot.sql.in
@@ -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;
1 change: 1 addition & 0 deletions sql
34 changes: 0 additions & 34 deletions src/handler/Makefile

This file was deleted.

50 changes: 5 additions & 45 deletions t/test.sql → t/sql/test.sql
@@ -1,4 +1,4 @@
\set ECHO
\unset ECHO
\set QUIET 1
-- Turn off echo and keep things quiet.
-- Format the output for nice TAP.
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 5f7bb98

Please sign in to comment.