Skip to content

Commit 7b84eeb

Browse files
committed
Get the program and library version from the META file
1 parent 71af7f2 commit 7b84eeb

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

bin/Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ REGRESS = init repack
1212

1313
EXTRA_CLEAN = sql/init-$(MAJORVERSION).sql sql/init.sql
1414

15-
ifdef DEBUG_REORG
16-
PG_CPPFLAGS = -I$(libpq_srcdir) -DDEBUG_REORG
17-
else
18-
PG_CPPFLAGS = -I$(libpq_srcdir)
15+
# The version number of the program. It should be the same of the library.
16+
REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \
17+
| sed -e 's/\s*"version":\s*"\(.*\)",/\1/')
18+
19+
PG_CPPFLAGS = -I$(libpq_srcdir) -DREPACK_VERSION=$(REPACK_VERSION)
20+
21+
ifdef DEBUG_REPACK
22+
PG_CPPFLAGS += -DDEBUG_REPACK
1923
endif
24+
2025
PG_LIBS = $(libpq)
2126

2227
USE_PGXS = 1 # use pgxs if not in contrib directory

bin/pg_repack.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@
1010
* @brief Client Modules
1111
*/
1212

13-
const char *PROGRAM_VERSION = "1.1.7";
1413
const char *PROGRAM_URL = "https://github.com/reorg/pg_reorg";
1514
const char *PROGRAM_EMAIL = "reorg-general@lists.pgfoundry.org";
1615

16+
#ifdef REPACK_VERSION
17+
/* macro trick to stringify a macro expansion */
18+
#define xstr(s) str(s)
19+
#define str(s) #s
20+
const char *PROGRAM_VERSION = xstr(REPACK_VERSION);
21+
#else
22+
const char *PROGRAM_VERSION = "unknown";
23+
#endif
24+
1725
#include "pgut/pgut-fe.h"
1826

1927
#include <string.h>

lib/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ OBJS = repack.o pgut/pgut-be.o pgut/pgut-spi.o
1010

1111
EXTENSION = pg_repack
1212

13+
# The version number of the program. It should be the same of the library.
14+
REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \
15+
| sed -e 's/\s*"version":\s*"\(.*\)",/\1/')
16+
1317
# The version of the extension, read from the .control file.
1418
# Note that it doesn't need to be the same of the library version: it should
1519
# be increased only when the sql changes.
1620
EXTVER = $(shell grep -e '^default_version' $(EXTENSION).control \
1721
| sed -e "s/[^']*'\([^']*\)'.*/\1/")
1822

23+
PG_CPPFLAGS = -DREPACK_VERSION=$(REPACK_VERSION)
24+
1925
#supports both EXTENSION (for >=9.1) and without_EXTENSION (for <PG 9.1)
2026
DATA_built = pg_repack.sql pg_repack--$(EXTVER).sql
2127
DATA = pg_repack--1.1.7--1.1.8.sql uninstall_pg_repack.sql

lib/repack.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,19 @@ static void RenameRelationInternal(Oid myrelid, const char *newrelname, Oid name
9494
#define RENAME_REL(relid, newrelname) RenameRelationInternal(relid, newrelname);
9595
#endif
9696

97+
#ifdef REPACK_VERSION
98+
/* macro trick to stringify a macro expansion */
99+
#define xstr(s) str(s)
100+
#define str(s) #s
101+
#define LIBRARY_VERSION xstr(REPACK_VERSION)
102+
#else
103+
#define LIBRARY_VERSION "unknown"
104+
#endif
97105

98106
Datum
99107
repack_version(PG_FUNCTION_ARGS)
100108
{
101-
return CStringGetTextDatum("pg_repack 1.1.6");
109+
return CStringGetTextDatum("pg_repack " LIBRARY_VERSION);
102110
}
103111

104112
/**

0 commit comments

Comments
 (0)