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 \
@@ -203,21 +238,37 @@ REGRESS += drop
203238srcdir =` pwd `
204239
205240ag_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
208249ag_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
211259GEN_KEYWORDLIST = $(PERL ) -I ./tools/ ./tools/gen_keywordlist.pl
212260GEN_KEYWORDLIST_DEPS = ./tools/gen_keywordlist.pl tools/PerfectHash.pm
213261
214262ag_include_dir = $(srcdir ) /src/include
215263PG_CPPFLAGS = -I$(ag_include_dir ) -I$(ag_include_dir ) /parser
216264
265+ # ===== PGXS =====
217266PG_CONFIG ?= pg_config
218267PGXS := $(shell $(PG_CONFIG ) --pgxs)
219268include $(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
235286src/backend/parser/cypher_parser.bc : src/backend/parser/cypher_gram.c src/include/parser/cypher_gram_def.h
236287src/backend/parser/cypher_keywords.o : src/backend/parser/cypher_gram.c src/include/parser/cypher_gram_def.h
237288src/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 $@
248300endif
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" $< > $@
267325endif
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)
288344installcheck : export LC_COLLATE=C
289345ifneq ($(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
297353installcheck : _install_upgrade_test_files
298354endif
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