Skip to content

Commit b69e5d8

Browse files
committed
meson: test extensions build by pkg-conf
1 parent f7826df commit b69e5d8

File tree

3 files changed

+167
-5
lines changed

3 files changed

+167
-5
lines changed

.cirrus.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ task:
138138
TEST_JOBS: 3
139139

140140
CCACHE_DIR: /tmp/ccache_dir
141+
INSTALL_DIR: /tmp/meson-install
141142
CPPFLAGS: -DRELCACHE_FORCE_RELEASE -DCOPY_PARSE_PLAN_TREES -DWRITE_READ_PARSE_PLAN_TREES -DRAW_EXPRESSION_COVERAGE_TEST
142143
CFLAGS: -Og -ggdb
143144

@@ -181,12 +182,14 @@ task:
181182
su postgres <<-EOF
182183
meson setup \
183184
--buildtype=debug \
185+
--prefix=${INSTALL_DIR} \
184186
-Dcassert=true -Dssl=openssl -Duuid=bsd -Dtcl_version=tcl86 -Ddtrace=auto \
185187
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
186188
-Dextra_lib_dirs=/usr/local/lib -Dextra_include_dirs=/usr/local/include/ \
187189
build
188190
EOF
189191
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
192+
install_script: su postgres -c 'ninja -C build install'
190193
upload_caches: ccache
191194

192195
test_world_script: |
@@ -201,13 +204,13 @@ task:
201204
set -e
202205
ulimit -c unlimited
203206
meson test $MTEST_ARGS --quiet --suite setup
204-
export LD_LIBRARY_PATH="$(pwd)/build/tmp_install/usr/local/pgsql/lib/:$LD_LIBRARY_PATH"
207+
export LD_LIBRARY_PATH="${INSTALL_DIR}/lib/:$LD_LIBRARY_PATH"
205208
mkdir -p build/testrun
206-
build/tmp_install/usr/local/pgsql/bin/initdb -N build/runningcheck --no-instructions -A trust
209+
${INSTALL_DIR}/bin/initdb -N build/runningcheck --no-instructions -A trust
207210
echo "include '$(pwd)/src/tools/ci/pg_ci_base.conf'" >> build/runningcheck/postgresql.conf
208-
build/tmp_install/usr/local/pgsql/bin/pg_ctl -c -o '-c fsync=off' -D build/runningcheck -l build/testrun/runningcheck.log start
211+
${INSTALL_DIR}/bin/pg_ctl -c -o '-c fsync=off' -D build/runningcheck -l build/testrun/runningcheck.log start
209212
meson test $MTEST_ARGS --num-processes ${TEST_JOBS} --setup running
210-
build/tmp_install/usr/local/pgsql/bin/pg_ctl -D build/runningcheck stop
213+
${INSTALL_DIR}/bin/pg_ctl -D build/runningcheck stop
211214
EOF
212215
213216
on_failure:
@@ -225,6 +228,7 @@ task:
225228

226229
CIRRUS_WORKING_DIR: /home/postgres/postgres
227230
CCACHE_DIR: /tmp/ccache_dir
231+
INSTALL_DIR: /tmp/meson-install
228232

229233
PATH: /usr/sbin:$PATH
230234

@@ -282,13 +286,15 @@ task:
282286
su postgres <<-EOF
283287
meson setup \
284288
--buildtype debug \
289+
--prefix=${INSTALL_DIR} \
285290
-Dcassert=true -Dssl=openssl ${UUID} \
286291
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
287292
${INCLUDE_DIRS} \
288293
build
289294
EOF
290295
291296
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
297+
install_script: su postgres -c 'ninja -C build install'
292298
upload_caches: ccache
293299

294300
test_world_script: |
@@ -350,6 +356,7 @@ task:
350356
TEST_JOBS: 8 # experimentally derived to be a decent choice
351357

352358
CCACHE_DIR: /tmp/ccache_dir
359+
INSTALL_DIR: /tmp/meson-install
353360
DEBUGINFOD_URLS: "https://debuginfod.debian.net"
354361

355362
# Enable a reasonable set of sanitizers. Use the linux task for that, as
@@ -449,6 +456,7 @@ task:
449456
su postgres <<-EOF
450457
meson setup \
451458
--buildtype=debug \
459+
--prefix=${INSTALL_DIR} \
452460
-Dcassert=true \
453461
${LINUX_MESON_FEATURES} \
454462
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
@@ -462,6 +470,7 @@ task:
462470
export CC='ccache gcc -m32'
463471
meson setup \
464472
--buildtype=debug \
473+
--prefix=${INSTALL_DIR}-32 \
465474
-Dcassert=true \
466475
${LINUX_MESON_FEATURES} \
467476
-Dllvm=disabled \
@@ -473,6 +482,7 @@ task:
473482
474483
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
475484
build_32_script: su postgres -c 'ninja -C build-32 -j${BUILD_JOBS}'
485+
install_script: su postgres -c 'ninja -C build install'
476486

477487
upload_caches: ccache
478488

@@ -484,6 +494,8 @@ task:
484494
# so that we don't upload 64bit logs if 32bit fails
485495
rm -rf build/
486496
497+
install_32_script: su postgres -c 'ninja -C build-32 install'
498+
487499
# There's currently no coverage of icu with LANG=C in the buildfarm. We
488500
# can easily provide some here by running one of the sets of tests that
489501
# way. Newer versions of python insist on changing the LC_CTYPE away
@@ -508,6 +520,7 @@ task:
508520
TEST_JOBS: 8 # experimentally derived to be a decent choice
509521

510522
CCACHE_DIR: /tmp/ccache_dir
523+
INSTALL_DIR: /tmp/meson-install
511524
DEBUGINFOD_URLS: ${DEBUGINFO}
512525

513526
TCL_DIR: /usr/lib64/
@@ -559,12 +572,14 @@ task:
559572
su postgres <<-EOF
560573
meson setup \
561574
--buildtype debug \
575+
--prefix=${INSTALL_DIR} \
562576
-Dcassert=true -Dssl=openssl -Duuid=e2fs ${LLVM} \
563577
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
564578
build
565579
EOF
566580
567581
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
582+
install_script: su postgres -c 'ninja -C build install'
568583
upload_caches: ccache
569584

570585
test_world_script: |
@@ -590,6 +605,7 @@ task:
590605

591606
CIRRUS_WORKING_DIR: ${HOME}/pgsql/
592607
CCACHE_DIR: ${HOME}/ccache
608+
INSTALL_DIR: /tmp/meson-install
593609
HOMEBREW_CACHE: ${HOME}/homebrew-cache
594610
PERL5LIB: ${HOME}/perl5/lib/perl5
595611

@@ -662,6 +678,8 @@ task:
662678
663679
meson setup \
664680
--buildtype=debug \
681+
--prefix=${INSTALL_DIR} \
682+
-Dpkg_config_path=$PKG_CONFIG_PATH \
665683
-Dextra_include_dirs=${brewpath}/include \
666684
-Dextra_lib_dirs=${brewpath}/lib \
667685
-Dcassert=true \
@@ -671,6 +689,7 @@ task:
671689
build
672690
673691
build_script: ninja -C build -j${BUILD_JOBS}
692+
install_script: ninja -C build install
674693
upload_caches: ccache
675694

676695
test_world_script: |

meson.build

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,6 +2953,8 @@ foreach lib: test_install_libs
29532953
test_install_libs_fp += lib.full_path()
29542954
endforeach
29552955

2956+
test_result_dir = meson.build_root() / 'testrun'
2957+
29562958
install_additional_files = files('src/test/install_additional_files')
29572959
test('install_additional_files',
29582960
python, args: [
@@ -2966,7 +2968,25 @@ test('install_additional_files',
29662968
is_parallel: false,
29672969
suite: ['setup'])
29682970

2969-
test_result_dir = meson.build_root() / 'testrun'
2971+
# it seems freebsd doesn't use libdir for pkgconfig path
2972+
if host_system == 'freebsd'
2973+
pkgconf_installdir = dir_prefix / 'libdata' / 'pkgconfig'
2974+
else
2975+
pkgconf_installdir = dir_prefix / dir_lib / 'pkgconfig'
2976+
endif
2977+
test_pkg_conf_file = files('src/tools/ci/test_pkg_conf')
2978+
test('pkg_conf_extensions',
2979+
test_pkg_conf_file,
2980+
args: [
2981+
'--meson', meson_bin.path(),
2982+
'--meson_args', meson_args,
2983+
'--rootdir', meson.source_root(),
2984+
'--pkgconf_installdir', pkgconf_installdir,
2985+
'--builddir', meson.build_root(),
2986+
'--pkg_conf_path', get_option('pkg_config_path'),
2987+
'--',
2988+
cc.cmd_array(),
2989+
],)
29702990

29712991

29722992
# XXX: pg_regress doesn't assign unique ports on windows. To avoid the

src/tools/ci/test_pkg_conf

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import ast
5+
import shutil
6+
import subprocess
7+
import os
8+
import sys
9+
10+
parser = argparse.ArgumentParser()
11+
12+
parser.add_argument('--rootdir', help='root directory',
13+
type=str, required=True)
14+
parser.add_argument('--pkgconf_installdir', help='pkgconf install directory',
15+
type=str, required=True)
16+
parser.add_argument('--builddir', help='build directory',
17+
type=str, required=True)
18+
parser.add_argument('--meson', help='path to meson binary',
19+
type=str, required=True)
20+
parser.add_argument('--meson_args', help='args of meson binary',
21+
type=str, nargs='*', required=False)
22+
parser.add_argument('--pkg_conf_path',
23+
help='PKG_CONF_PATH from surrounding meson build',
24+
type=str, nargs='?', const='', required=False)
25+
26+
parser.add_argument('c_args', help='c_args from surrounding meson build',
27+
nargs='*')
28+
29+
args = parser.parse_args()
30+
31+
rootdir = os.path.realpath(args.rootdir)
32+
builddir = os.path.realpath(args.builddir)
33+
pkgconf_installdir = os.path.realpath(args.pkgconf_installdir)
34+
adminpackdir = os.path.join(rootdir, 'contrib/adminpack/')
35+
workdir = os.path.join(builddir, 'contrib/adminpack_tmp')
36+
meson_args = ' '.join(args.meson_args)
37+
c_args = ' '.join(args.c_args)
38+
exit_code = 0
39+
40+
adminpack_meson_build_file = \
41+
'''
42+
project('adminpack', 'c')
43+
44+
pg_ext = dependency('postgresql-extension-warnings')
45+
46+
adminpack = shared_module('adminpack',
47+
['{}adminpack.c'],
48+
dependencies: pg_ext,
49+
name_prefix: '',
50+
install_dir: pg_ext.get_variable(pkgconfig: 'dir_mod')
51+
)
52+
53+
install_data(
54+
'{}adminpack.control',
55+
'{}adminpack--1.0.sql',
56+
'{}adminpack--1.0--1.1.sql',
57+
'{}adminpack--1.1--2.0.sql',
58+
'{}adminpack--2.0--2.1.sql',
59+
install_dir: pg_ext.get_variable(pkgconfig: 'dir_data')
60+
)
61+
'''.format(adminpackdir, adminpackdir, adminpackdir, adminpackdir,
62+
adminpackdir, adminpackdir)
63+
64+
# clear workdir
65+
if os.path.exists(workdir):
66+
shutil.rmtree(workdir)
67+
os.makedirs(workdir)
68+
69+
# overwrite meson.build file
70+
meson_file = os.path.join(workdir, 'meson.build')
71+
with open(meson_file, 'w') as f:
72+
f.write(adminpack_meson_build_file)
73+
74+
75+
def remove_duplicates(duplicate_str):
76+
words = duplicate_str.split()
77+
return ' '.join(sorted(set(words), key=words.index))
78+
79+
80+
# run tests
81+
def run_tests(pkg_conf_path, message=''):
82+
print('\n{}\n{}\n'.format('#' * 60, message), flush=True)
83+
84+
adminpack_builddir = os.path.join(workdir, 'build')
85+
86+
env = {**os.environ, }
87+
env['PKG_CONFIG_PATH'] = '{}:{}:{}'.format(
88+
pkg_conf_path, args.pkg_conf_path, env.get('PKG_CONFIG_PATH', ''),
89+
).strip(': ')
90+
env['CC'] = '{} {}'.format(
91+
c_args, env.get('CC', ''),
92+
)
93+
env['CC'] = remove_duplicates(env['CC'])
94+
95+
if os.path.exists(adminpack_builddir):
96+
shutil.rmtree(adminpack_builddir)
97+
98+
if meson_args:
99+
meson_setup_command = [args.meson, meson_args, 'setup', 'build']
100+
else:
101+
meson_setup_command = [args.meson, 'setup', 'build']
102+
103+
ninja_build_command = ['ninja', '-C', 'build', '-v']
104+
if subprocess.run(meson_setup_command, env=env,
105+
cwd=workdir).returncode != 0:
106+
return False
107+
if subprocess.run(ninja_build_command, cwd=workdir).returncode != 0:
108+
return False
109+
return True
110+
111+
112+
# test postgresql-extension-warnings
113+
if not run_tests(pkgconf_installdir,
114+
message='Testing postgresql-extension-warnings'):
115+
exit_code = exit_code + 1
116+
117+
118+
# test postgresql-extension-warnings-uninstalled
119+
if not run_tests(os.path.join(builddir, 'meson-uninstalled'),
120+
message='Testing postgresql-extension-warnings-uninstalled'):
121+
exit_code = exit_code + 1
122+
123+
sys.exit(exit_code)

0 commit comments

Comments
 (0)