From 7724b734f321640a729d84599a3244084c769007 Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Thu, 9 Apr 2020 12:53:51 +0800
Subject: [PATCH 3/4] Support the install-tests target for the rest of the test
 suite

Install almost all the test suite when "make install-tests" is run,
so it can be used by extensions that want to ensure that their
behaviour doesn't break anything in PostgreSQL proper.

As this is fairly advanced usage it's expected that extensions
will provide their own Makefile support. PGXS does not attempt
to do so.
---
 GNUmakefile.in                   |  2 +-
 src/test/Makefile                |  2 ++
 src/test/authentication/Makefile |  9 +++++++++
 src/test/isolation/Makefile      | 34 +++++++++++++++++++++++++-------
 src/test/kerberos/Makefile       |  9 +++++++++
 src/test/ldap/Makefile           |  9 +++++++++
 src/test/locale/Makefile         |  4 ++++
 src/test/modules/Makefile        |  9 +++++++++
 src/test/perl/Makefile           |  6 ++++++
 src/test/recovery/Makefile       |  9 +++++++++
 src/test/ssl/Makefile            | 10 ++++++++++
 src/test/subscription/Makefile   |  9 +++++++++
 12 files changed, 104 insertions(+), 8 deletions(-)

diff --git a/GNUmakefile.in b/GNUmakefile.in
index bcbed94041..37cdfcb314 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -71,7 +71,7 @@ $(call recurse,check-world,src/test src/pl src/interfaces/ecpg contrib src/bin,c
 $(call recurse,checkprep,  src/test src/pl src/interfaces/ecpg contrib src/bin)
 
 $(call recurse,installcheck-world,src/test src/pl src/interfaces/ecpg contrib src/bin,installcheck)
-$(call recurse,install-tests,src/test/regress,install-tests)
+$(call recurse,install-tests,src/test,install-tests)
 
 GNUmakefile: GNUmakefile.in $(top_builddir)/config.status
 	./config.status $@
diff --git a/src/test/Makefile b/src/test/Makefile
index efb206aa75..b8df9428bc 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -48,5 +48,7 @@ installable_dirs := $(filter-out modules, $(SUBDIRS))
 $(call recurse,$(recurse_alldirs_targets))
 $(call recurse,installcheck, $(installable_dirs))
 $(call recurse,install, $(installable_dirs))
+# The install-tests target visits all subdirs
+$(call recurse,install-tests)
 
 $(recurse_always)
diff --git a/src/test/authentication/Makefile b/src/test/authentication/Makefile
index 124d1d0771..3ed3011a51 100644
--- a/src/test/authentication/Makefile
+++ b/src/test/authentication/Makefile
@@ -21,3 +21,12 @@ installcheck:
 
 clean distclean maintainer-clean:
 	rm -rf tmp_check
+
+install-tests-dirs:
+	$(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(subdir)/t'
+
+install-tests: install-tests-dirs
+	$(INSTALL_DATA) $(srcdir)/Makefile '$(DESTDIR)$(pgxsdir)/$(subdir)/Makefile'
+	$(foreach datafile,$(wildcard $(srcdir)/$(subdir)/t/*.pl), \
+	  $(INSTALL_DATA) $(datafile) '$(DESTDIR)$(pgxsdir)/$(subdir)/$(subst $(srcdir),,$(datafile))'; \
+	)
diff --git a/src/test/isolation/Makefile b/src/test/isolation/Makefile
index da5e088bdd..34038de7f3 100644
--- a/src/test/isolation/Makefile
+++ b/src/test/isolation/Makefile
@@ -18,13 +18,6 @@ OBJS = \
 
 all: isolationtester$(X) pg_isolation_regress$(X)
 
-# Though we don't install these binaries, build them during installation
-# (including temp-install).  Otherwise, "make -j check-world" and "make -j
-# installcheck-world" would spawn multiple, concurrent builds in this
-# directory.  Later builds would overwrite files while earlier builds are
-# reading them, causing occasional failures.
-install: | all
-
 submake-regress:
 	$(MAKE) -C $(top_builddir)/src/test/regress pg_regress.o
 
@@ -67,3 +60,30 @@ installcheck-prepared-txns: all temp-install
 
 check-prepared-txns: all temp-install
 	$(pg_isolation_regress_check) --schedule=$(srcdir)/isolation_schedule prepared-transactions
+
+installdirs:
+	$(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(subdir)'
+
+# The isolation tester is useful for running tests on extensions so we install and ship it.
+install: all installdirs
+	$(INSTALL_PROGRAM) pg_isolation_regress$(X) '$(DESTDIR)$(pgxsdir)/$(subdir)/pg_isolation_regress$(X)'
+
+# PostgreSQL's own test data is not installed by default, but is available for
+# install using the "install-tests" target in case extensions want to verify
+# that their own changes don't break anything in PostgreSQL proper.
+
+isolation_data_files = \
+	$(wildcard $(srcdir)/specs/*.spec) \
+	$(wildcard $(srcdir)/expected/*.out) \
+	$(wildcard $(srcdir)/data/*.data) \
+	$(srcdir)/isolation_schedule
+
+installdirs-tests: installdirs
+	$(MKDIR_P)  $(patsubst $(srcdir)/%/,'$(DESTDIR)$(pgxsdir)/$(subdir)/%',$(sort $(dir $(isolation_data_files))))
+
+install-tests: all install installdirs-tests installdirs-tests
+	$(MAKE) -C $(top_builddir)/contrib/spi install
+	$(foreach datafile,$(isolation_data_files), \
+	  $(INSTALL_DATA) $(datafile) '$(DESTDIR)$(pgxsdir)/$(subdir)/$(subst $(srcdir),,$(datafile))'; \
+	)
+	$(INSTALL_DATA) Makefile '$(DESTDIR)$(pgxsdir)/$(subdir)/'
diff --git a/src/test/kerberos/Makefile b/src/test/kerberos/Makefile
index 04a0f746b5..fefd6aac51 100644
--- a/src/test/kerberos/Makefile
+++ b/src/test/kerberos/Makefile
@@ -23,3 +23,12 @@ installcheck:
 
 clean distclean maintainer-clean:
 	rm -rf tmp_check
+
+install-tests-dirs:
+	$(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(subdir)/t'
+
+install-tests: install-tests-dirs
+	$(INSTALL_DATA) $(srcdir)/Makefile '$(DESTDIR)$(pgxsdir)/$(subdir)/Makefile'
+	$(foreach datafile,$(wildcard $(srcdir)/$(subdir)/t/*.pl), \
+	  $(INSTALL_DATA) $(datafile) '$(DESTDIR)$(pgxsdir)/$(subdir)/$(subst $(srcdir),,$(datafile))'; \
+	)
diff --git a/src/test/ldap/Makefile b/src/test/ldap/Makefile
index 3e5afd9777..a8f2db286b 100644
--- a/src/test/ldap/Makefile
+++ b/src/test/ldap/Makefile
@@ -23,3 +23,12 @@ installcheck:
 
 clean distclean maintainer-clean:
 	rm -rf tmp_check
+
+install-tests-dirs:
+	$(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(subdir)/t'
+
+install-tests: install-tests-dirs
+	$(INSTALL_DATA) $(srcdir)/Makefile $(srcdir)/authdata.ldif '$(DESTDIR)$(pgxsdir)/$(subdir)/'
+	$(foreach datafile,$(wildcard $(srcdir)/$(subdir)/t/*.pl), \
+	  $(INSTALL_DATA) $(datafile) '$(DESTDIR)$(pgxsdir)/$(subdir)/$(subst $(srcdir),,$(datafile))'; \
+	)
diff --git a/src/test/locale/Makefile b/src/test/locale/Makefile
index 22a45b65f2..c07b958b5e 100644
--- a/src/test/locale/Makefile
+++ b/src/test/locale/Makefile
@@ -19,3 +19,7 @@ clean distclean maintainer-clean:
 # These behave like installcheck targets.
 check-%: all
 	@$(MAKE) -C `echo $@ | sed 's/^check-//'` test
+
+# The locale tests can't really be run outside the source tree
+# right now so don't install them.
+install-tests: ;
diff --git a/src/test/modules/Makefile b/src/test/modules/Makefile
index 29de73c060..c11b06afb2 100644
--- a/src/test/modules/Makefile
+++ b/src/test/modules/Makefile
@@ -33,3 +33,12 @@ endif
 
 $(recurse)
 $(recurse_always)
+
+# Some of these modules are needed for the regress, isolation, or recovery
+# (TAP) test suites, so install them when install-tests is requested.
+#
+# We should probably put them in a separate non-default path but right now we
+# cannot do so due to the lack of any extension search path for extensions and
+# control files.
+#
+$(call recurse,install-tests,$(SUBDIRS),install)
diff --git a/src/test/perl/Makefile b/src/test/perl/Makefile
index acdd160620..1063262365 100644
--- a/src/test/perl/Makefile
+++ b/src/test/perl/Makefile
@@ -30,4 +30,10 @@ uninstall:
 	rm -f '$(DESTDIR)$(pgxsdir)/$(subdir)/RecursiveCopy.pm'
 	rm -f '$(DESTDIR)$(pgxsdir)/$(subdir)/PostgresNode.pm'
 
+else
+
+install: ;
+
 endif
+
+install-tests: install
diff --git a/src/test/recovery/Makefile b/src/test/recovery/Makefile
index fa8e031526..fbe98bb27c 100644
--- a/src/test/recovery/Makefile
+++ b/src/test/recovery/Makefile
@@ -23,3 +23,12 @@ installcheck:
 
 clean distclean maintainer-clean:
 	rm -rf tmp_check
+
+install-tests-dirs:
+	$(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(subdir)/t'
+
+install-tests: install-tests-dirs
+	$(INSTALL_DATA) $(srcdir)/Makefile '$(DESTDIR)$(pgxsdir)/$(subdir)/'
+	$(foreach datafile,$(wildcard $(srcdir)/$(subdir)/t/*.pl), \
+	  $(INSTALL_DATA) $(datafile) '$(DESTDIR)$(pgxsdir)/$(subdir)/$(subst $(srcdir),,$(datafile))'; \
+	)
diff --git a/src/test/ssl/Makefile b/src/test/ssl/Makefile
index 06e37d5269..606957c431 100644
--- a/src/test/ssl/Makefile
+++ b/src/test/ssl/Makefile
@@ -161,3 +161,13 @@ check:
 
 installcheck:
 	$(prove_installcheck)
+
+# Allow SSL tests to be run against an installed/packaged postgres too.
+install-tests-dirs:
+	$(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(subdir)/t'
+
+install-tests: install-tests-dirs
+	$(INSTALL_DATA) $(srcdir)/Makefile $(srcdir)/README $(wildcard $(srcdir)/*.config) '$(DESTDIR)$(pgxsdir)/$(subdir)/'
+	$(foreach datafile,$(wildcard $(srcdir)/$(subdir)/t/*.p[lm]), \
+	  $(INSTALL_DATA) $(datafile) '$(DESTDIR)$(pgxsdir)/$(subdir)/$(subst $(srcdir),,$(datafile))'; \
+	)
diff --git a/src/test/subscription/Makefile b/src/test/subscription/Makefile
index 3ac06aa3de..d691a28deb 100644
--- a/src/test/subscription/Makefile
+++ b/src/test/subscription/Makefile
@@ -25,3 +25,12 @@ installcheck:
 
 clean distclean maintainer-clean:
 	rm -rf tmp_check
+
+install-tests-dirs:
+	$(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(subdir)/t'
+
+install-tests: install-tests-dirs
+	$(INSTALL_DATA) $(srcdir)/Makefile $(srcdir)/README '$(DESTDIR)$(pgxsdir)/$(subdir)/'
+	$(foreach datafile,$(wildcard $(srcdir)/$(subdir)/t/*.pl), \
+	  $(INSTALL_DATA) $(datafile) '$(DESTDIR)$(pgxsdir)/$(subdir)/$(subst $(srcdir),,$(datafile))'; \
+	)
-- 
2.25.1

