meson: Prevent installation of test files during main install

Previously, meson installed modules under src/test/modules/ as part of
a normal installation, even though these files are only meant for use
by tests.  This is because there is no way to set up up the build
system to install extra things only when told.

This patch fixes that with a workaround: We don't install these
modules as part of meson install, but we create a new "test" that runs
before the real tests whose action it is to install these files.  The
installation is done by manual copies using a small helper script.

Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/2a039e8e-f31f-31e8-afe7-bab3130ad2de%40enterprisedb.com
This commit is contained in:
Peter Eisentraut 2023-03-03 07:18:20 +01:00
parent b1307b8b60
commit b6a0d469ca
29 changed files with 139 additions and 151 deletions

View File

@ -2801,6 +2801,10 @@ backend_code = declare_dependency(
dependencies: os_deps + backend_both_deps + backend_deps,
)
# install these files only during test, not main install
test_install_data = []
test_install_libs = []
# src/backend/meson.build defines backend_mod_code used for extension
# libraries.
@ -2821,6 +2825,10 @@ subdir('doc/src/sgml')
generated_sources_ac += {'': ['GNUmakefile']}
# After processing src/test, add test_install_libs to the testprep_targets
# to build them
testprep_targets += test_install_libs
# If there are any files in the source directory that we also generate in the
# build directory, they might get preferred over the newly generated files,
@ -2903,14 +2911,36 @@ meson_install_args = meson_args + ['install'] + {
'muon': []
}[meson_impl]
# setup tests should be run first,
# so define priority for these
setup_tests_priority = 100
test('tmp_install',
meson_bin, args: meson_install_args ,
env: {'DESTDIR':test_install_destdir},
priority: 100,
priority: setup_tests_priority,
timeout: 300,
is_parallel: false,
suite: ['setup'])
# get full paths of test_install_libs to copy them
test_install_libs_fp = []
foreach lib: test_install_libs
test_install_libs_fp += lib.full_path()
endforeach
install_test_files = files('src/tools/install_test_files')
test('install_test_files',
python, args: [
install_test_files,
'--datadir', test_install_location / contrib_data_args['install_dir'],
'--libdir', test_install_location / dir_lib_pkg,
'--install-data', test_install_data,
'--install-libs', test_install_libs_fp,
],
priority: setup_tests_priority,
is_parallel: false,
suite: ['setup'])
test_result_dir = meson.build_root() / 'testrun'

View File

@ -180,12 +180,19 @@ backend_mod_code = declare_dependency(
dependencies: backend_mod_deps,
)
# normal extension modules
pg_mod_args = default_mod_args + {
'dependencies': [backend_mod_code],
'cpp_args': pg_mod_cpp_args,
'link_depends': pg_mod_link_depend,
}
# extension modules that shouldn't be installed by default, as they're only
# for testing
pg_test_mod_args = pg_mod_args + {
'install': false
}
# Shared modules that, on some system, link against the server binary. Only

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
delay_execution_sources = files(
'delay_execution.c',
)
@ -14,9 +12,9 @@ endif
delay_execution = shared_module('delay_execution',
delay_execution_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += delay_execution
test_install_libs += delay_execution
tests += {
'name': 'delay_execution',

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
dummy_index_am_sources = files(
'dummy_index_am.c',
)
@ -14,14 +12,13 @@ endif
dummy_index_am = shared_module('dummy_index_am',
dummy_index_am_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += dummy_index_am
test_install_libs += dummy_index_am
install_data(
test_install_data += files(
'dummy_index_am.control',
'dummy_index_am--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
dummy_seclabel_sources = files(
'dummy_seclabel.c',
)
@ -14,14 +12,13 @@ endif
dummy_seclabel = shared_module('dummy_seclabel',
dummy_seclabel_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += dummy_seclabel
test_install_libs += dummy_seclabel
install_data(
test_install_data += files(
'dummy_seclabel.control',
'dummy_seclabel--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
plsample_sources = files(
'plsample.c',
)
@ -14,16 +12,14 @@ endif
plsample = shared_module('plsample',
plsample_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += plsample
test_install_libs += plsample
install_data(
test_install_data += files(
'plsample.control',
'plsample--1.0.sql',
kwargs: contrib_data_args,
)
tests += {
'name': 'plsample',
'sd': meson.current_source_dir(),

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
spgist_name_ops_sources = files(
'spgist_name_ops.c',
)
@ -14,16 +12,14 @@ endif
spgist_name_ops = shared_module('spgist_name_ops',
spgist_name_ops_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += spgist_name_ops
test_install_libs += spgist_name_ops
install_data(
test_install_data += files(
'spgist_name_ops.control',
'spgist_name_ops--1.0.sql',
kwargs: contrib_data_args,
)
tests += {
'name': 'spgist_name_ops',
'sd': meson.current_source_dir(),

View File

@ -4,8 +4,6 @@ if not ssl.found()
subdir_done()
endif
# FIXME: prevent install during main install, but not during test :/
ssl_passphrase_callback_sources = files(
'ssl_passphrase_func.c',
)
@ -18,11 +16,11 @@ endif
ssl_passphrase_callback = shared_module('ssl_passphrase_func',
ssl_passphrase_callback_sources,
kwargs: pg_mod_args + {
kwargs: pg_test_mod_args + {
'dependencies': [ssl, pg_mod_args['dependencies']],
},
)
testprep_targets += ssl_passphrase_callback
test_install_libs += ssl_passphrase_callback
# Targets to generate or remove the ssl certificate and key. Need to be copied
# to the source afterwards. Normally not needed.

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_bloomfilter_sources = files(
'test_bloomfilter.c',
)
@ -14,14 +12,13 @@ endif
test_bloomfilter = shared_module('test_bloomfilter',
test_bloomfilter_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_bloomfilter
test_install_libs += test_bloomfilter
install_data(
test_install_data += files(
'test_bloomfilter.control',
'test_bloomfilter--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_copy_callbacks_sources = files(
'test_copy_callbacks.c',
)
@ -14,14 +12,13 @@ endif
test_copy_callbacks = shared_module('test_copy_callbacks',
test_copy_callbacks_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_copy_callbacks
test_install_libs += test_copy_callbacks
install_data(
test_install_data += files(
'test_copy_callbacks.control',
'test_copy_callbacks--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_custom_rmgrs_sources = files(
'test_custom_rmgrs.c',
)
@ -14,14 +12,13 @@ endif
test_custom_rmgrs = shared_module('test_custom_rmgrs',
test_custom_rmgrs_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_custom_rmgrs
test_install_libs += test_custom_rmgrs
install_data(
test_install_data += files(
'test_custom_rmgrs.control',
'test_custom_rmgrs--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_ddl_deparse_sources = files(
'test_ddl_deparse.c',
)
@ -14,14 +12,13 @@ endif
test_ddl_deparse = shared_module('test_ddl_deparse',
test_ddl_deparse_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_ddl_deparse
test_install_libs += test_ddl_deparse
install_data(
test_install_data += files(
'test_ddl_deparse.control',
'test_ddl_deparse--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,6 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
install_data(
test_install_data += files(
'test_ext1--1.0.sql',
'test_ext1.control',
'test_ext2--1.0.sql',
@ -31,7 +30,6 @@ install_data(
'test_ext_evttrig--1.0--2.0.sql',
'test_ext_evttrig--1.0.sql',
'test_ext_evttrig.control',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_ginpostinglist_sources = files(
'test_ginpostinglist.c',
)
@ -14,14 +12,13 @@ endif
test_ginpostinglist = shared_module('test_ginpostinglist',
test_ginpostinglist_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_ginpostinglist
test_install_libs += test_ginpostinglist
install_data(
test_install_data += files(
'test_ginpostinglist.control',
'test_ginpostinglist--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_integerset_sources = files(
'test_integerset.c',
)
@ -14,14 +12,13 @@ endif
test_integerset = shared_module('test_integerset',
test_integerset_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_integerset
test_install_libs += test_integerset
install_data(
test_install_data += files(
'test_integerset.control',
'test_integerset--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_lfind_sources = files(
'test_lfind.c',
)
@ -14,14 +12,13 @@ endif
test_lfind = shared_module('test_lfind',
test_lfind_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_lfind
test_install_libs += test_lfind
install_data(
test_install_data += files(
'test_lfind.control',
'test_lfind--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_oat_hooks_sources = files(
'test_oat_hooks.c',
)
@ -14,9 +12,9 @@ endif
test_oat_hooks = shared_module('test_oat_hooks',
test_oat_hooks_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_oat_hooks
test_install_libs += test_oat_hooks
tests += {
'name': 'test_oat_hooks',

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_parser_sources = files(
'test_parser.c',
)
@ -14,14 +12,13 @@ endif
test_parser = shared_module('test_parser',
test_parser_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_parser
test_install_libs += test_parser
install_data(
test_install_data += files(
'test_parser.control',
'test_parser--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_pg_db_role_setting_sources = files(
'test_pg_db_role_setting.c',
)
@ -14,14 +12,13 @@ endif
test_pg_db_role_setting = shared_module('test_pg_db_role_setting',
test_pg_db_role_setting_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_pg_db_role_setting
test_install_libs += test_pg_db_role_setting
install_data(
test_install_data += files(
'test_pg_db_role_setting.control',
'test_pg_db_role_setting--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,10 +1,8 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
install_data(
test_install_data += files(
'test_pg_dump.control',
'test_pg_dump--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_predtest_sources = files(
'test_predtest.c',
)
@ -14,14 +12,13 @@ endif
test_predtest = shared_module('test_predtest',
test_predtest_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_predtest
test_install_libs += test_predtest
install_data(
test_install_data += files(
'test_predtest.control',
'test_predtest--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_rbtree_sources = files(
'test_rbtree.c',
)
@ -14,14 +12,13 @@ endif
test_rbtree = shared_module('test_rbtree',
test_rbtree_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_rbtree
test_install_libs += test_rbtree
install_data(
test_install_data += files(
'test_rbtree.control',
'test_rbtree--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_regex_sources = files(
'test_regex.c',
)
@ -14,14 +12,13 @@ endif
test_regex = shared_module('test_regex',
test_regex_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_regex
test_install_libs += test_regex
install_data(
test_install_data += files(
'test_regex.control',
'test_regex--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_rls_hooks_sources = files(
'test_rls_hooks.c',
)
@ -14,9 +12,9 @@ endif
test_rls_hooks = shared_module('test_rls_hooks',
test_rls_hooks_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_rls_hooks
test_install_libs += test_rls_hooks
tests += {
'name': 'test_rls_hooks',

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_shm_mq_sources = files(
'setup.c',
'test.c',
@ -16,14 +14,13 @@ endif
test_shm_mq = shared_module('test_shm_mq',
test_shm_mq_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_shm_mq
test_install_libs += test_shm_mq
install_data(
test_install_data += files(
'test_shm_mq.control',
'test_shm_mq--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_slru_sources = files(
'test_slru.c',
)
@ -14,14 +12,13 @@ endif
test_slru = shared_module('test_slru',
test_slru_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_slru
test_install_libs += test_slru
install_data(
test_install_data += files(
'test_slru.control',
'test_slru--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -1,7 +1,5 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
# FIXME: prevent install during main install, but not during test :/
test_worker_spi_sources = files(
'worker_spi.c',
)
@ -14,14 +12,13 @@ endif
test_worker_spi = shared_module('worker_spi',
test_worker_spi_sources,
kwargs: pg_mod_args,
kwargs: pg_test_mod_args,
)
testprep_targets += test_worker_spi
test_install_libs += test_worker_spi
install_data(
test_install_data += files(
'worker_spi.control',
'worker_spi--1.0.sql',
kwargs: contrib_data_args,
)
tests += {

View File

@ -39,11 +39,9 @@ bin_targets += pg_regress
regress_module = shared_module('regress',
['regress.c'],
kwargs: pg_mod_args + {
'install': false,
},
kwargs: pg_test_mod_args,
)
testprep_targets += regress_module
test_install_libs += regress_module
# Get some extra C modules from contrib/spi but mark them as not to be
# installed.
@ -51,20 +49,16 @@ testprep_targets += regress_module
autoinc_regress = shared_module('autoinc',
['../../../contrib/spi/autoinc.c'],
kwargs: pg_mod_args + {
'install': false,
},
kwargs: pg_test_mod_args,
)
testprep_targets += autoinc_regress
test_install_libs += autoinc_regress
refint_regress = shared_module('refint',
['../../../contrib/spi/refint.c'],
c_args: refint_cflags,
kwargs: pg_mod_args + {
'install': false,
},
kwargs: pg_test_mod_args,
)
testprep_targets += refint_regress
test_install_libs += refint_regress
tests += {

View File

@ -0,0 +1,28 @@
#!/usr/bin/env python3
# Helper to install additional files into the temporary installation
# for tests, beyond those that are installed by meson/ninja install.
import argparse
import shutil
import os
parser = argparse.ArgumentParser()
parser.add_argument('--datadir', type=str)
parser.add_argument('--libdir', type=str)
parser.add_argument('--install-data', type=str, nargs='*')
parser.add_argument('--install-libs', type=str, nargs='*')
args = parser.parse_args()
def copy_files(src_list: list, dest: str):
os.makedirs(dest, exist_ok=True)
for src in src_list:
shutil.copy2(src, dest)
copy_files(args.install_data, args.datadir)
copy_files(args.install_libs, args.libdir)