Skip to content

Commit 6c43a1a

Browse files
authored
Automatically set the module version based on git describe (#994)
In the last two releases I forgot to update the version number in `PG_MODULE_MAGIC_EXT`. This stars assigning this version the value reported by git describe. Without having committed these changes, that looks like this: ``` > select * from pg_get_loaded_modules(); module_name │ version │ file_name ─────────────┼──────────────────────────┼────────────── pg_duckdb │ v1.1.1-3-gc7c8fd1d-dirty │ pg_duckdb.so ``` For tagged releases it will be a plain version number, like `v1.1.2`. Related to #993
1 parent c7c8fd1 commit 6c43a1a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.PHONY: duckdb install-duckdb clean-duckdb clean-all lintcheck check-regression-duckdb clean-regression
22

3+
PG_DUCKDB_VERSION ?= $(shell git describe --always --dirty 2>/dev/null || echo "unknown")
4+
35
MODULE_big = pg_duckdb
46
EXTENSION = pg_duckdb
57
DATA = pg_duckdb.control $(wildcard sql/pg_duckdb--*.sql)
@@ -84,6 +86,10 @@ SHLIB_LINK += $(PG_DUCKDB_LINK_FLAGS)
8486

8587
include Makefile.global
8688

89+
# Only pass the version define to the one file that needs it, so that ccache
90+
# doesn't invalidate everything on every commit.
91+
src/pgduckdb.o: PG_CPPFLAGS += -DPG_DUCKDB_VERSION="\"$(PG_DUCKDB_VERSION)\""
92+
8793
# We need the DuckDB header files to build our own .o files. We depend on the
8894
# duckdb submodule HEAD, because that target pulls in the submodule which
8995
# includes those header files. This does mean that we rebuild our .o files

src/pgduckdb.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ extern "C" {
1515
extern "C" {
1616

1717
#ifdef PG_MODULE_MAGIC_EXT
18-
PG_MODULE_MAGIC_EXT(.name = "pg_duckdb", .version = "1.0.0");
18+
#ifndef PG_DUCKDB_VERSION
19+
// Should always be defined via build system, but keep a fallback here for
20+
// static analysis tools etc.
21+
#define PG_DUCKDB_VERSION "unknown"
22+
#endif
23+
PG_MODULE_MAGIC_EXT(.name = "pg_duckdb", .version = PG_DUCKDB_VERSION);
1924
#else
2025
PG_MODULE_MAGIC;
2126
#endif

0 commit comments

Comments
 (0)