Skip to content

Commit 581d236

Browse files
authored
Makefile: add installcheck-existing target and improve readability (#2437)
Add an "installcheck-existing" target that runs the regression suite against an already-running PostgreSQL server, complementing the default "installcheck" (which builds a private temp instance). It points pg_regress at the server via the standard libpq variables (PGHOST/PGPORT/PGUSER; PGDATABASE defaults to contrib_regression) and lets pg_regress create the database and load the extension through --load-extension=age. It deliberately avoids --use-existing -- that option skips database creation and disables --load-extension -- so no manual CREATE EXTENSION step is required. The upgrade test (age_upgrade) is excluded because it stages synthetic extension files into the local sharedir that a running server would not see. Readability and maintainability improvements (no behavior change): - Derive age_sql from AGE_CURR_VER (read from age.control) so the version number is defined in exactly one place. - Add section banners and a top-of-file layout/target index; group the scattered upgrade-test pieces and move the ag_scanner flex rule in with the other parser-generation rules. - Wrap the long REGRESS_OPTS and EXTRA_CLEAN assignments across lines. - Fix the DATA filter-out pattern to use a double dash (age--%--y.y.y.sql) matching the actual template filename; the prior single-dash pattern only matched via greedy '%' expansion. - Anchor the age.control version regex (/^default_version/). - Replace the hardcoded "31 tests" comment with generic wording and add a "help" target listing the common targets. Verified on PostgreSQL 18: make installcheck (temp instance) and make installcheck-existing both pass; clean rebuild and make clean unaffected. Co-authored-by: GitHub Copilot <noreply@github.com> modified: Makefile
1 parent 34483ef commit 581d236

1 file changed

Lines changed: 125 additions & 12 deletions

File tree

Makefile

Lines changed: 125 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,38 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
# ===========================================================================
19+
# Apache AGE extension build
20+
#
21+
# File layout (top to bottom):
22+
# * Module
23+
# * Upgrade regression-test support (1/2: variables)
24+
# * Extension SQL & data files
25+
# * Regression test suite (REGRESS / REGRESS_OPTS)
26+
# * PGXS include
27+
# * Build rules
28+
# * Upgrade regression-test support (2/2: rules + installcheck lifecycle)
29+
# * installcheck-existing (run against a running server)
30+
# * help
31+
#
32+
# Common targets:
33+
# all Build the extension (default)
34+
# install Install into the PostgreSQL tree
35+
# installcheck Run regression tests in a private temp instance
36+
# installcheck-existing Run regression tests against a running server
37+
# clean Remove build artifacts
38+
# help Show the target list
39+
# ===========================================================================
40+
41+
# ===== Module =====
1842
MODULE_big = age
1943

20-
age_sql = age--1.7.0.sql
21-
22-
# --- Extension upgrade regression test support ---
44+
# ===== Upgrade regression-test support (1/2: variables) =====
45+
#
46+
# This feature spans two sections (the PGXS include forces the split):
47+
# * 1/2 (here, pre-include): variables -- must be defined before DATA,
48+
# REGRESS, and EXTRA_CLEAN reference them.
49+
# * 2/2 (below the PGXS include): build rules + installcheck lifecycle.
2350
#
2451
# Validates the upgrade template (age--<VER>--y.y.y.sql) by simulating an
2552
# extension version upgrade entirely within "make installcheck". The test:
@@ -53,7 +80,7 @@ age_sql = age--1.7.0.sql
5380
# (e.g., age--1.7.0--1.8.0.sql is committed): the synthetic test is
5481
# redundant because the real script ships with the extension.
5582
# Current version from age.control (e.g., "1.7.0")
56-
AGE_CURR_VER := $(shell awk -F"'" '/default_version/ {print $$2}' age.control 2>/dev/null)
83+
AGE_CURR_VER := $(shell awk -F"'" '/^default_version/ {print $$2}' age.control 2>/dev/null)
5784
# Git commit that last changed age.control — the "initial release" commit
5885
AGE_VER_COMMIT := $(shell git log -1 --format=%H -- age.control 2>/dev/null)
5986
# Synthetic initial version: current version with _initial suffix
@@ -80,6 +107,7 @@ AGE_REAL_UPGRADE := $(shell git ls-files 'age--$(AGE_CURR_VER)--*.sql' 2>/dev/nu
80107
# supersedes the synthetic one and has its own validation path.
81108
AGE_HAS_UPGRADE_TEST = $(and $(AGE_VER_COMMIT),$(AGE_UPGRADE_TEMPLATE),$(if $(AGE_REAL_UPGRADE),,yes))
82109

110+
# ===== Object files =====
83111
OBJS = src/backend/age.o \
84112
src/backend/catalog/ag_catalog.o \
85113
src/backend/catalog/ag_graph.o \
@@ -134,6 +162,7 @@ OBJS = src/backend/age.o \
134162
src/backend/utils/name_validation.o \
135163
src/backend/utils/ag_guc.o
136164

165+
# ===== Extension SQL & data files =====
137166
EXTENSION = age
138167

139168
# to allow cleaning of previous (old) age--.sql files
@@ -143,12 +172,18 @@ SQLS := $(shell cat sql/sql_files)
143172
SQLS := $(addprefix sql/,$(SQLS))
144173
SQLS := $(addsuffix .sql,$(SQLS))
145174

175+
# Name of the generated install SQL (age--<version>.sql).
176+
# Derived from AGE_CURR_VER (read from age.control above) so the version
177+
# number lives in exactly one place.
178+
age_sql = age--$(AGE_CURR_VER).sql
179+
146180
DATA_built = $(age_sql)
147181

148182
# Git-tracked upgrade scripts shipped with the extension (e.g., age--1.6.0--1.7.0.sql).
149183
# Excludes the upgrade template (y.y.y) and the synthetic stamped test file.
150-
DATA = $(filter-out age--%-y.y.y.sql $(age_upgrade_test_sql),$(wildcard age--*--*.sql))
184+
DATA = $(filter-out age--%--y.y.y.sql $(age_upgrade_test_sql),$(wildcard age--*--*.sql))
151185

186+
# ===== Regression test suite =====
152187
# sorted in dependency order
153188
REGRESS = scan \
154189
graphid \
@@ -203,21 +238,37 @@ REGRESS += drop
203238
srcdir=`pwd`
204239

205240
ag_regress_dir = $(srcdir)/regress
206-
REGRESS_OPTS = --load-extension=age --inputdir=$(ag_regress_dir) --outputdir=$(ag_regress_dir) --temp-instance=$(ag_regress_dir)/instance --port=61958 --encoding=UTF-8 --temp-config $(ag_regress_dir)/age_regression.conf
241+
REGRESS_OPTS = --load-extension=age \
242+
--inputdir=$(ag_regress_dir) \
243+
--outputdir=$(ag_regress_dir) \
244+
--temp-instance=$(ag_regress_dir)/instance \
245+
--port=61958 \
246+
--encoding=UTF-8 \
247+
--temp-config $(ag_regress_dir)/age_regression.conf
207248

208249
ag_regress_out = instance/ log/ results/ regression.*
209-
EXTRA_CLEAN = $(addprefix $(ag_regress_dir)/, $(ag_regress_out)) src/backend/parser/cypher_gram.c src/include/parser/cypher_gram_def.h src/include/parser/cypher_kwlist_d.h $(all_age_sql) $(age_init_sql) $(age_upgrade_test_sql) $(ag_regress_dir)/age_upgrade_cleanup.sh
250+
EXTRA_CLEAN = $(addprefix $(ag_regress_dir)/, $(ag_regress_out)) \
251+
src/backend/parser/cypher_gram.c \
252+
src/include/parser/cypher_gram_def.h \
253+
src/include/parser/cypher_kwlist_d.h \
254+
$(all_age_sql) \
255+
$(age_init_sql) \
256+
$(age_upgrade_test_sql) \
257+
$(ag_regress_dir)/age_upgrade_cleanup.sh
210258

211259
GEN_KEYWORDLIST = $(PERL) -I ./tools/ ./tools/gen_keywordlist.pl
212260
GEN_KEYWORDLIST_DEPS = ./tools/gen_keywordlist.pl tools/PerfectHash.pm
213261

214262
ag_include_dir = $(srcdir)/src/include
215263
PG_CPPFLAGS = -I$(ag_include_dir) -I$(ag_include_dir)/parser
216264

265+
# ===== PGXS =====
217266
PG_CONFIG ?= pg_config
218267
PGXS := $(shell $(PG_CONFIG) --pgxs)
219268
include $(PGXS)
220269

270+
# ===== Build rules =====
271+
221272
# 32-bit platform support: pass SIZEOF_DATUM=4 to enable (e.g., make SIZEOF_DATUM=4)
222273
# When SIZEOF_DATUM=4, PASSEDBYVALUE is stripped from graphid type for pass-by-reference.
223274
# If not specified, normal 64-bit behavior is used (PASSEDBYVALUE preserved).
@@ -235,10 +286,11 @@ src/backend/parser/cypher_parser.o: src/backend/parser/cypher_gram.c src/include
235286
src/backend/parser/cypher_parser.bc: src/backend/parser/cypher_gram.c src/include/parser/cypher_gram_def.h
236287
src/backend/parser/cypher_keywords.o: src/backend/parser/cypher_gram.c src/include/parser/cypher_gram_def.h
237288
src/backend/parser/cypher_keywords.bc: src/backend/parser/cypher_gram.c src/include/parser/cypher_gram_def.h
289+
src/backend/parser/ag_scanner.c: FLEX_NO_BACKUP=yes
238290

239291
# Build the default install SQL (age--<VER>.sql) from current HEAD's sql/sql_files.
240292
# This is what CREATE EXTENSION age installs — it contains ALL current functions.
241-
# All 31 non-upgrade regression tests run against this complete SQL.
293+
# Every non-upgrade regression test runs against this complete SQL.
242294
$(age_sql): $(SQLS)
243295
@echo "Building install SQL: $@ from HEAD"
244296
@cat $(SQLS) > $@
@@ -247,6 +299,12 @@ ifeq ($(SIZEOF_DATUM),4)
247299
@sed 's/^ PASSEDBYVALUE,$$/ -- PASSEDBYVALUE removed for 32-bit (see Makefile)/' $@ > $@.tmp && mv $@.tmp $@
248300
endif
249301

302+
# ===== Upgrade regression-test support (2/2: rules + installcheck lifecycle) =====
303+
#
304+
# Part 1/2 (variables) is above the PGXS include; the rules and target
305+
# hooks below must follow the include.
306+
#
307+
# --- Synthetic SQL rules ---
250308
# Build synthetic "initial" version install SQL from the version-bump commit.
251309
# This represents the pre-upgrade state — the SQL at the time the version was
252310
# bumped in age.control. Used only by the upgrade test.
@@ -266,9 +324,7 @@ $(age_upgrade_test_sql): $(AGE_UPGRADE_TEMPLATE)
266324
@sed -e "s/1\.X\.0/$(AGE_CURR_VER)/g" -e "s/y\.y\.y/$(AGE_CURR_VER)/g" $< > $@
267325
endif
268326

269-
src/backend/parser/ag_scanner.c: FLEX_NO_BACKUP=yes
270-
271-
# --- Upgrade test file lifecycle during installcheck ---
327+
# --- installcheck lifecycle: stage synthetic files, then clean up ---
272328
#
273329
# Problem: The upgrade test needs age--<INIT>.sql and age--<INIT>--<CURR>.sql
274330
# in the PG extension directory for CREATE EXTENSION VERSION and ALTER
@@ -288,11 +344,68 @@ SHAREDIR = $(shell $(PG_CONFIG) --sharedir)
288344
installcheck: export LC_COLLATE=C
289345
ifneq ($(AGE_HAS_UPGRADE_TEST),)
290346
.PHONY: _install_upgrade_test_files
291-
_install_upgrade_test_files: $(age_init_sql) $(age_upgrade_test_sql) ## Build, install synthetic files, generate cleanup script
347+
_install_upgrade_test_files: $(age_init_sql) $(age_upgrade_test_sql) # Build, install synthetic files, generate cleanup script
292348
@echo "Installing upgrade test files to $(SHAREDIR)/extension/"
293349
@$(INSTALL_DATA) $(age_init_sql) $(age_upgrade_test_sql) '$(SHAREDIR)/extension/'
294350
@printf '#!/bin/sh\nrm -f "$(SHAREDIR)/extension/$(age_init_sql)" "$(SHAREDIR)/extension/$(age_upgrade_test_sql)"\nrm -f "$(age_init_sql)" "$(age_upgrade_test_sql)" "$(ag_regress_dir)/age_upgrade_cleanup.sh"\n' > $(ag_regress_dir)/age_upgrade_cleanup.sh
295351
@chmod +x $(ag_regress_dir)/age_upgrade_cleanup.sh
296352

297353
installcheck: _install_upgrade_test_files
298354
endif
355+
356+
# ===== installcheck-existing: run tests against a running server =====
357+
#
358+
# Runs the regression suite against an already-running PostgreSQL server
359+
# instead of the private temp instance built by "make installcheck".
360+
#
361+
# "make installcheck" appends --temp-instance to REGRESS_OPTS, so it builds
362+
# its own throwaway cluster and needs no running server. This target instead
363+
# connects to the server selected by the standard libpq environment variables
364+
# (PGHOST/PGPORT/PGUSER); PGDATABASE defaults to contrib_regression. Override
365+
# any of them on the command line, e.g.:
366+
#
367+
# make installcheck-existing PGHOST=localhost PGPORT=5432 PGUSER=postgres
368+
#
369+
# pg_regress creates the database and loads the extension itself through
370+
# --load-extension=age -- exactly as the temp-instance path does -- so no
371+
# manual "CREATE EXTENSION" step is required. The connecting role must be
372+
# allowed to CREATE DATABASE.
373+
#
374+
# This deliberately does NOT pass pg_regress --use-existing: that option skips
375+
# database creation (which also disables --load-extension) and is only needed
376+
# on clusters where the test role cannot CREATE DATABASE. For that narrow
377+
# case, pre-create the database and extension and add --use-existing to
378+
# EXTRA_REGRESS_OPTS.
379+
#
380+
# The upgrade test (age_upgrade) is excluded here: it installs synthetic
381+
# extension files into the local $(SHAREDIR), which an existing or remote
382+
# server would not see. Validate the upgrade path with "make installcheck".
383+
#
384+
# Locale note: locale-sensitive comparisons follow the existing server's own
385+
# collation (fixed at its initdb time); the temp-instance locale flags do not
386+
# apply to an already-running server.
387+
PGDATABASE ?= contrib_regression
388+
REGRESS_EXISTING = $(filter-out age_upgrade,$(REGRESS))
389+
390+
.PHONY: installcheck-existing
391+
installcheck-existing:
392+
$(pg_regress_installcheck) \
393+
--inputdir=$(ag_regress_dir) \
394+
--outputdir=$(ag_regress_dir) \
395+
--load-extension=age \
396+
$(if $(PGHOST),--host=$(PGHOST)) \
397+
$(if $(PGPORT),--port=$(PGPORT)) \
398+
$(if $(PGUSER),--user=$(PGUSER)) \
399+
--dbname=$(PGDATABASE) \
400+
$(REGRESS_EXISTING)
401+
402+
# ===== Help =====
403+
.PHONY: help
404+
help:
405+
@echo "Apache AGE - common make targets:"
406+
@echo " all Build the extension (default target)"
407+
@echo " install Install the extension into the PostgreSQL tree"
408+
@echo " installcheck Run the regression suite in a private temp instance"
409+
@echo " installcheck-existing Run the regression suite against a running server"
410+
@echo " clean Remove build artifacts"
411+
@echo " help Show this message"

0 commit comments

Comments
 (0)