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 =====
1842MODULE_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
5885AGE_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.
81108AGE_HAS_UPGRADE_TEST = $(and $(AGE_VER_COMMIT ) ,$(AGE_UPGRADE_TEMPLATE ) ,$(if $(AGE_REAL_UPGRADE ) ,,yes) )
82109
110+ # ===== Object files =====
83111OBJS = 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 =====
137166EXTENSION = age
138167
139168# to allow cleaning of previous (old) age--.sql files
@@ -143,12 +172,18 @@ SQLS := $(shell cat sql/sql_files)
143172SQLS := $(addprefix sql/,$(SQLS ) )
144173SQLS := $(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+
146180DATA_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
153188REGRESS = scan \
154189 graphid \
@@ -202,21 +237,37 @@ REGRESS += drop
202237srcdir =` pwd `
203238
204239ag_regress_dir = $(srcdir ) /regress
205- 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
240+ REGRESS_OPTS = --load-extension=age \
241+ --inputdir=$(ag_regress_dir ) \
242+ --outputdir=$(ag_regress_dir ) \
243+ --temp-instance=$(ag_regress_dir ) /instance \
244+ --port=61958 \
245+ --encoding=UTF-8 \
246+ --temp-config $(ag_regress_dir ) /age_regression.conf
206247
207248ag_regress_out = instance/ log/ results/ regression.*
208- 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
249+ EXTRA_CLEAN = $(addprefix $(ag_regress_dir ) /, $(ag_regress_out ) ) \
250+ src/backend/parser/cypher_gram.c \
251+ src/include/parser/cypher_gram_def.h \
252+ src/include/parser/cypher_kwlist_d.h \
253+ $(all_age_sql ) \
254+ $(age_init_sql ) \
255+ $(age_upgrade_test_sql ) \
256+ $(ag_regress_dir ) /age_upgrade_cleanup.sh
209257
210258GEN_KEYWORDLIST = $(PERL ) -I ./tools/ ./tools/gen_keywordlist.pl
211259GEN_KEYWORDLIST_DEPS = ./tools/gen_keywordlist.pl tools/PerfectHash.pm
212260
213261ag_include_dir = $(srcdir ) /src/include
214262PG_CPPFLAGS = -I$(ag_include_dir ) -I$(ag_include_dir ) /parser
215263
264+ # ===== PGXS =====
216265PG_CONFIG ?= pg_config
217266PGXS := $(shell $(PG_CONFIG ) --pgxs)
218267include $(PGXS )
219268
269+ # ===== Build rules =====
270+
220271# 32-bit platform support: pass SIZEOF_DATUM=4 to enable (e.g., make SIZEOF_DATUM=4)
221272# When SIZEOF_DATUM=4, PASSEDBYVALUE is stripped from graphid type for pass-by-reference.
222273# If not specified, normal 64-bit behavior is used (PASSEDBYVALUE preserved).
@@ -234,10 +285,11 @@ src/backend/parser/cypher_parser.o: src/backend/parser/cypher_gram.c src/include
234285src/backend/parser/cypher_parser.bc : src/backend/parser/cypher_gram.c src/include/parser/cypher_gram_def.h
235286src/backend/parser/cypher_keywords.o : src/backend/parser/cypher_gram.c src/include/parser/cypher_gram_def.h
236287src/backend/parser/cypher_keywords.bc : src/backend/parser/cypher_gram.c src/include/parser/cypher_gram_def.h
288+ src/backend/parser/ag_scanner.c : FLEX_NO_BACKUP=yes
237289
238290# Build the default install SQL (age--<VER>.sql) from current HEAD's sql/sql_files.
239291# This is what CREATE EXTENSION age installs — it contains ALL current functions.
240- # All 31 non-upgrade regression tests run against this complete SQL.
292+ # Every non-upgrade regression test runs against this complete SQL.
241293$(age_sql ) : $(SQLS )
242294 @echo " Building install SQL: $@ from HEAD"
243295 @cat $(SQLS ) > $@
@@ -246,6 +298,12 @@ ifeq ($(SIZEOF_DATUM),4)
246298 @sed 's/^ PASSEDBYVALUE,$$/ -- PASSEDBYVALUE removed for 32-bit (see Makefile)/' $@ > $@.tmp && mv $@.tmp $@
247299endif
248300
301+ # ===== Upgrade regression-test support (2/2: rules + installcheck lifecycle) =====
302+ #
303+ # Part 1/2 (variables) is above the PGXS include; the rules and target
304+ # hooks below must follow the include.
305+ #
306+ # --- Synthetic SQL rules ---
249307# Build synthetic "initial" version install SQL from the version-bump commit.
250308# This represents the pre-upgrade state — the SQL at the time the version was
251309# bumped in age.control. Used only by the upgrade test.
@@ -265,9 +323,7 @@ $(age_upgrade_test_sql): $(AGE_UPGRADE_TEMPLATE)
265323 @sed -e " s/1\.X\.0/$( AGE_CURR_VER) /g" -e " s/y\.y\.y/$( AGE_CURR_VER) /g" $< > $@
266324endif
267325
268- src/backend/parser/ag_scanner.c : FLEX_NO_BACKUP=yes
269-
270- # --- Upgrade test file lifecycle during installcheck ---
326+ # --- installcheck lifecycle: stage synthetic files, then clean up ---
271327#
272328# Problem: The upgrade test needs age--<INIT>.sql and age--<INIT>--<CURR>.sql
273329# in the PG extension directory for CREATE EXTENSION VERSION and ALTER
@@ -287,11 +343,68 @@ SHAREDIR = $(shell $(PG_CONFIG) --sharedir)
287343installcheck : export LC_COLLATE=C
288344ifneq ($(AGE_HAS_UPGRADE_TEST ) ,)
289345.PHONY : _install_upgrade_test_files
290- _install_upgrade_test_files : $(age_init_sql ) $(age_upgrade_test_sql ) # # Build, install synthetic files, generate cleanup script
346+ _install_upgrade_test_files : $(age_init_sql ) $(age_upgrade_test_sql ) # Build, install synthetic files, generate cleanup script
291347 @echo " Installing upgrade test files to $( SHAREDIR) /extension/"
292348 @$(INSTALL_DATA ) $(age_init_sql ) $(age_upgrade_test_sql ) ' $(SHAREDIR)/extension/'
293349 @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
294350 @chmod +x $(ag_regress_dir ) /age_upgrade_cleanup.sh
295351
296352installcheck : _install_upgrade_test_files
297353endif
354+
355+ # ===== installcheck-existing: run tests against a running server =====
356+ #
357+ # Runs the regression suite against an already-running PostgreSQL server
358+ # instead of the private temp instance built by "make installcheck".
359+ #
360+ # "make installcheck" appends --temp-instance to REGRESS_OPTS, so it builds
361+ # its own throwaway cluster and needs no running server. This target instead
362+ # connects to the server selected by the standard libpq environment variables
363+ # (PGHOST/PGPORT/PGUSER); PGDATABASE defaults to contrib_regression. Override
364+ # any of them on the command line, e.g.:
365+ #
366+ # make installcheck-existing PGHOST=localhost PGPORT=5432 PGUSER=postgres
367+ #
368+ # pg_regress creates the database and loads the extension itself through
369+ # --load-extension=age -- exactly as the temp-instance path does -- so no
370+ # manual "CREATE EXTENSION" step is required. The connecting role must be
371+ # allowed to CREATE DATABASE.
372+ #
373+ # This deliberately does NOT pass pg_regress --use-existing: that option skips
374+ # database creation (which also disables --load-extension) and is only needed
375+ # on clusters where the test role cannot CREATE DATABASE. For that narrow
376+ # case, pre-create the database and extension and add --use-existing to
377+ # EXTRA_REGRESS_OPTS.
378+ #
379+ # The upgrade test (age_upgrade) is excluded here: it installs synthetic
380+ # extension files into the local $(SHAREDIR), which an existing or remote
381+ # server would not see. Validate the upgrade path with "make installcheck".
382+ #
383+ # Locale note: locale-sensitive comparisons follow the existing server's own
384+ # collation (fixed at its initdb time); the temp-instance locale flags do not
385+ # apply to an already-running server.
386+ PGDATABASE ?= contrib_regression
387+ REGRESS_EXISTING = $(filter-out age_upgrade,$(REGRESS ) )
388+
389+ .PHONY : installcheck-existing
390+ installcheck-existing :
391+ $(pg_regress_installcheck ) \
392+ --inputdir=$(ag_regress_dir ) \
393+ --outputdir=$(ag_regress_dir ) \
394+ --load-extension=age \
395+ $(if $(PGHOST ) ,--host=$(PGHOST ) ) \
396+ $(if $(PGPORT ) ,--port=$(PGPORT ) ) \
397+ $(if $(PGUSER ) ,--user=$(PGUSER ) ) \
398+ --dbname=$(PGDATABASE ) \
399+ $(REGRESS_EXISTING )
400+
401+ # ===== Help =====
402+ .PHONY : help
403+ help :
404+ @echo " Apache AGE - common make targets:"
405+ @echo " all Build the extension (default target)"
406+ @echo " install Install the extension into the PostgreSQL tree"
407+ @echo " installcheck Run the regression suite in a private temp instance"
408+ @echo " installcheck-existing Run the regression suite against a running server"
409+ @echo " clean Remove build artifacts"
410+ @echo " help Show this message"
0 commit comments