Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6041e86

Browse files
nbyavuzCommitfest Bot
authored and
Commitfest Bot
committed
meson: Test building extensions by using postgresql-extension.pc
The 'test_meson_extensions' pyton wrapper is added to run these tests. It compiles and builds extensions at ${build}/testrun/meson_extensions/${extension_name} path. The tests for building amcheck, auth_delay and postgres_fdw extensions are added. These are also examples of how to build extensions by using postgresql-extension.pc. Author: Andres Freund <andres@anarazel.de> Author: Nazir Bilal Yavuz <byavuz81@gmail.com> Discussion: https://postgr.es/m/206b001d-1884-4081-bd02-bed5c92f02ba%40eisentraut.org
1 parent 1b14ed3 commit 6041e86

File tree

8 files changed

+205
-0
lines changed

8 files changed

+205
-0
lines changed

meson.build

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,6 +3042,7 @@ nls_targets = []
30423042
# Define the tests to distribute them to the correct test styles later
30433043
test_deps = []
30443044
tests = []
3045+
meson_extension_tests = []
30453046

30463047

30473048
# Default options for targets
@@ -3597,6 +3598,37 @@ sys.exit(sp.returncode)
35973598
suite: ['setup'])
35983599

35993600

3601+
# it seems freebsd doesn't use libdir for pkgconfig path
3602+
if host_system == 'freebsd'
3603+
pkgconf_installdir = dir_prefix / 'libdata' / 'pkgconfig'
3604+
else
3605+
pkgconf_installdir = dir_prefix / dir_lib / 'pkgconfig'
3606+
endif
3607+
test_pkg_conf_file = files('src/tools/ci/test_meson_extensions')
3608+
3609+
foreach test : meson_extension_tests
3610+
if test['kind'] not in ['pkg_config']
3611+
error('unknown kind @0@ of test in @1@'.format(test['kind'], test['sd']))
3612+
endif
3613+
3614+
test_group = 'meson_@0@_extensions'.format(test['kind'])
3615+
3616+
test(test_group / test['name'],
3617+
test_pkg_conf_file,
3618+
args: [
3619+
'--meson', meson_bin.path(),
3620+
'--meson_args', meson_args,
3621+
'--test_dir', test['sd'],
3622+
'--test_out_dir', test_result_dir / 'meson_extensions' / test['name'],
3623+
'--builddir', meson.build_root(),
3624+
'--pkg_conf_path', get_option('pkg_config_path'),
3625+
'--',
3626+
cc.cmd_array(),
3627+
],
3628+
suite: test_group,
3629+
)
3630+
3631+
endforeach
36003632

36013633
###############################################################
36023634
# Test Generation

src/test/modules/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ subdir('test_ginpostinglist')
2626
subdir('test_integerset')
2727
subdir('test_json_parser')
2828
subdir('test_lfind')
29+
subdir('test_meson_extensions')
2930
subdir('test_misc')
3031
subdir('test_oat_hooks')
3132
subdir('test_parser')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright (c) 2022-2025, PostgreSQL Global Development Group
2+
3+
subdir('test_pkg_config_extensions')
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2022-2025, PostgreSQL Global Development Group
2+
3+
project('amcheck', 'c')
4+
5+
amcheck_path = '../../../../../../contrib/amcheck/'
6+
7+
amcheck_sources = files(
8+
amcheck_path / 'verify_heapam.c',
9+
amcheck_path / 'verify_nbtree.c',
10+
)
11+
12+
pg_ext = dependency('postgresql-extension-warnings')
13+
14+
amcheck = shared_module('amcheck',
15+
amcheck_sources,
16+
dependencies: pg_ext,
17+
install_dir: pg_ext.get_variable(pkgconfig: 'dir_mod'),
18+
)
19+
20+
install_data(
21+
amcheck_path / 'amcheck.control',
22+
amcheck_path / 'amcheck--1.0.sql',
23+
amcheck_path / 'amcheck--1.0--1.1.sql',
24+
amcheck_path / 'amcheck--1.1--1.2.sql',
25+
amcheck_path / 'amcheck--1.2--1.3.sql',
26+
amcheck_path / 'amcheck--1.3--1.4.sql',
27+
install_dir: pg_ext.get_variable(pkgconfig: 'dir_data'),
28+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2022-2025, PostgreSQL Global Development Group
2+
3+
project('auth_delay', 'c')
4+
5+
auth_delay_path = '../../../../../../contrib/auth_delay/'
6+
7+
auth_delay_sources = files(
8+
auth_delay_path / 'auth_delay.c',
9+
)
10+
11+
pg_ext = dependency('postgresql-extension-warnings')
12+
13+
auth_delay = shared_module('auth_delay',
14+
auth_delay_sources,
15+
dependencies: pg_ext,
16+
install_dir: pg_ext.get_variable(pkgconfig: 'dir_mod'),
17+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2022-2025, PostgreSQL Global Development Group
2+
3+
# pkgconfig is not available on Windows, so skip it.
4+
if host_machine.system() == 'windows'
5+
subdir_done()
6+
endif
7+
8+
meson_extension_tests += {
9+
'name': 'amcheck',
10+
'kind': 'pkg_config',
11+
'sd': meson.current_source_dir() / 'amcheck',
12+
}
13+
14+
meson_extension_tests += {
15+
'name': 'auth_delay',
16+
'kind': 'pkg_config',
17+
'sd': meson.current_source_dir() / 'auth_delay',
18+
}
19+
20+
meson_extension_tests += {
21+
'name': 'postgres_fdw',
22+
'kind': 'pkg_config',
23+
'sd': meson.current_source_dir() / 'postgres_fdw',
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2022-2025, PostgreSQL Global Development Group
2+
3+
project('auth_delay', 'c')
4+
5+
postgres_fdw_path = '../../../../../../contrib/postgres_fdw/'
6+
7+
postgres_fdw_sources = files(
8+
postgres_fdw_path / 'connection.c',
9+
postgres_fdw_path / 'deparse.c',
10+
postgres_fdw_path / 'option.c',
11+
postgres_fdw_path / 'postgres_fdw.c',
12+
postgres_fdw_path / 'shippable.c',
13+
)
14+
15+
pg_ext = dependency('postgresql-extension-warnings')
16+
libpq = dependency('libpq')
17+
18+
postgres_fdw = shared_module('postgres_fdw',
19+
postgres_fdw_sources,
20+
dependencies: [pg_ext, libpq],
21+
install_dir: pg_ext.get_variable(pkgconfig: 'dir_mod'),
22+
)
23+
24+
install_data(
25+
postgres_fdw_path / 'postgres_fdw.control',
26+
postgres_fdw_path / 'postgres_fdw--1.0.sql',
27+
postgres_fdw_path / 'postgres_fdw--1.0--1.1.sql',
28+
postgres_fdw_path / 'postgres_fdw--1.1--1.2.sql',
29+
install_dir: pg_ext.get_variable(pkgconfig: 'dir_data'),
30+
)

src/tools/ci/test_meson_extensions

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import os
5+
import shutil
6+
import subprocess
7+
8+
parser = argparse.ArgumentParser()
9+
10+
parser.add_argument('--meson', help='path to meson binary',
11+
type=str, required=True)
12+
parser.add_argument('--meson_args', help='args of meson binary',
13+
type=str, nargs='*', required=False)
14+
parser.add_argument('--test_dir', help='test source directory',
15+
type=str, required=True)
16+
parser.add_argument('--test_out_dir', help='test output directory',
17+
type=str, required=True)
18+
parser.add_argument('--builddir', help='meson build directory',
19+
type=str, required=True)
20+
parser.add_argument('--pkg_conf_path',
21+
help='PKG_CONF_PATH from surrounding meson build',
22+
type=str, nargs='?', const='', required=False)
23+
parser.add_argument('c_args', help='c_args from surrounding meson build',
24+
nargs='*')
25+
26+
args = parser.parse_args()
27+
28+
meson_bin = args.meson
29+
meson_args = ' '.join(args.meson_args)
30+
test_source_dir = args.test_dir
31+
test_out_dir = args.test_out_dir
32+
build_dir = args.builddir
33+
pkg_conf_path = args.pkg_conf_path
34+
c_args = ' '.join(args.c_args)
35+
36+
exit_code = 0
37+
38+
def remove_duplicates(duplicate_str):
39+
words = duplicate_str.split()
40+
return ' '.join(sorted(set(words), key=words.index))
41+
42+
43+
def run_tests(pkg_conf_path_local, message):
44+
print('\n{}\n{}\n'.format('#' * 60, message), flush=True)
45+
46+
env = {**os.environ, }
47+
env['PKG_CONFIG_PATH'] = '{}:{}:{}'.format(
48+
pkg_conf_path_local, pkg_conf_path, env.get('PKG_CONFIG_PATH', ''),
49+
).strip(': ')
50+
env['CC'] = '{} {}'.format(
51+
c_args, env.get('CC', ''),
52+
)
53+
env['CC'] = remove_duplicates(env['CC'])
54+
55+
# Clear the build directory beforehand.
56+
if os.path.exists(test_out_dir):
57+
shutil.rmtree(test_out_dir)
58+
59+
if meson_args:
60+
meson_setup_command = [meson_bin, meson_args, 'setup', test_out_dir]
61+
else:
62+
meson_setup_command = [meson_bin, 'setup', test_out_dir]
63+
64+
meson_compile_command = ['meson', 'compile', '-C', test_out_dir, '-v']
65+
66+
subprocess.run(meson_setup_command, env=env, cwd=test_source_dir, check=True)
67+
subprocess.run(meson_compile_command, cwd=test_source_dir, check=True)
68+
69+
run_tests(os.path.join(build_dir, 'meson-uninstalled'),
70+
message='Testing postgresql-extension-warnings-uninstalled')

0 commit comments

Comments
 (0)