pg_repack.git / summary / log / commit / refs

commit    7b84eeb010e341716fbc994eef3eef989b2b74d2
Author:   Daniele Varrazzo <daniele.varrazzo@gmail.com>
Date:     Sun Nov 11 18:30:27 2012 +0000

    Get the program and library version from the META file


bin/Makefile | 13 +++++++++---- bin/pg_repack.c | 10 +++++++++- lib/Makefile | 6 ++++++ lib/repack.c | 10 +++++++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/bin/Makefile b/bin/Makefile index 7c3c331..78fc2ff 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -12,11 +12,16 @@ REGRESS = init repack EXTRA_CLEAN = sql/init-$(MAJORVERSION).sql sql/init.sql -ifdef DEBUG_REORG -PG_CPPFLAGS = -I$(libpq_srcdir) -DDEBUG_REORG -else -PG_CPPFLAGS = -I$(libpq_srcdir) +# The version number of the program. It should be the same of the library. +REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \ + | sed -e 's/\s*"version":\s*"\(.*\)",/\1/') + +PG_CPPFLAGS = -I$(libpq_srcdir) -DREPACK_VERSION=$(REPACK_VERSION) + +ifdef DEBUG_REPACK +PG_CPPFLAGS += -DDEBUG_REPACK endif + PG_LIBS = $(libpq) USE_PGXS = 1 # use pgxs if not in contrib directory diff --git a/bin/pg_repack.c b/bin/pg_repack.c index c91c3e2..670da4d 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -10,10 +10,18 @@ * @brief Client Modules */ -const char *PROGRAM_VERSION = "1.1.7"; const char *PROGRAM_URL = "https://github.com/reorg/pg_reorg"; const char *PROGRAM_EMAIL = "reorg-general@lists.pgfoundry.org"; +#ifdef REPACK_VERSION +/* macro trick to stringify a macro expansion */ +#define xstr(s) str(s) +#define str(s) #s +const char *PROGRAM_VERSION = xstr(REPACK_VERSION); +#else +const char *PROGRAM_VERSION = "unknown"; +#endif + #include "pgut/pgut-fe.h" #include <string.h> diff --git a/lib/Makefile b/lib/Makefile index 804b430..8057319 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -10,12 +10,18 @@ OBJS = repack.o pgut/pgut-be.o pgut/pgut-spi.o EXTENSION = pg_repack +# The version number of the program. It should be the same of the library. +REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \ + | sed -e 's/\s*"version":\s*"\(.*\)",/\1/') + # The version of the extension, read from the .control file. # Note that it doesn't need to be the same of the library version: it should # be increased only when the sql changes. EXTVER = $(shell grep -e '^default_version' $(EXTENSION).control \ | sed -e "s/[^']*'\([^']*\)'.*/\1/") +PG_CPPFLAGS = -DREPACK_VERSION=$(REPACK_VERSION) + #supports both EXTENSION (for >=9.1) and without_EXTENSION (for <PG 9.1) DATA_built = pg_repack.sql pg_repack--$(EXTVER).sql DATA = pg_repack--1.1.7--1.1.8.sql uninstall_pg_repack.sql diff --git a/lib/repack.c b/lib/repack.c index dae6baf..4451153 100644 --- a/lib/repack.c +++ b/lib/repack.c @@ -94,11 +94,19 @@ static void RenameRelationInternal(Oid myrelid, const char *newrelname, Oid name #define RENAME_REL(relid, newrelname) RenameRelationInternal(relid, newrelname); #endif +#ifdef REPACK_VERSION +/* macro trick to stringify a macro expansion */ +#define xstr(s) str(s) +#define str(s) #s +#define LIBRARY_VERSION xstr(REPACK_VERSION) +#else +#define LIBRARY_VERSION "unknown" +#endif Datum repack_version(PG_FUNCTION_ARGS) { - return CStringGetTextDatum("pg_repack 1.1.6"); + return CStringGetTextDatum("pg_repack " LIBRARY_VERSION); } /** [parent: 71af7f20be12]