Skip to content

Commit 75044fd

Browse files
committed
meson: test extensions build by pkg-conf
1 parent d1491d3 commit 75044fd

File tree

3 files changed

+165
-4
lines changed

3 files changed

+165
-4
lines changed

.cirrus.yml

+22-4
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

@@ -187,6 +188,7 @@ task:
187188
build
188189
EOF
189190
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
191+
install_script: su postgres -c 'ninja -C build install'
190192
upload_caches: ccache
191193

192194
test_world_script: |
@@ -201,13 +203,13 @@ task:
201203
set -e
202204
ulimit -c unlimited
203205
meson test $MTEST_ARGS --quiet --suite setup
204-
export LD_LIBRARY_PATH="$(pwd)/build/tmp_install/usr/local/pgsql/lib/:$LD_LIBRARY_PATH"
206+
export LD_LIBRARY_PATH="${INSTALL_DIR}/lib/:$LD_LIBRARY_PATH"
205207
mkdir -p build/testrun
206-
build/tmp_install/usr/local/pgsql/bin/initdb -N build/runningcheck --no-instructions -A trust
208+
${INSTALL_DIR}/bin/initdb -N build/runningcheck --no-instructions -A trust
207209
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
210+
${INSTALL_DIR}/bin/pg_ctl -c -o '-c fsync=off' -D build/runningcheck -l build/testrun/runningcheck.log start
209211
meson test $MTEST_ARGS --num-processes ${TEST_JOBS} --setup running
210-
build/tmp_install/usr/local/pgsql/bin/pg_ctl -D build/runningcheck stop
212+
${INSTALL_DIR}/bin/pg_ctl -D build/runningcheck stop
211213
EOF
212214
213215
on_failure:
@@ -231,6 +233,7 @@ task:
231233

232234
CIRRUS_WORKING_DIR: /home/postgres/postgres
233235
CCACHE_DIR: /tmp/ccache_dir
236+
INSTALL_DIR: /tmp/meson-install
234237

235238
PATH: /usr/sbin:$PATH
236239

@@ -288,13 +291,15 @@ task:
288291
su postgres <<-EOF
289292
meson setup \
290293
--buildtype debug \
294+
--prefix=${INSTALL_DIR} \
291295
-Dcassert=true -Dssl=openssl ${UUID} \
292296
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
293297
${INCLUDE_DIRS} \
294298
build
295299
EOF
296300
297301
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
302+
install_script: su postgres -c 'ninja -C build install'
298303
upload_caches: ccache
299304

300305
test_world_script: |
@@ -355,6 +360,7 @@ task:
355360
TEST_JOBS: 8 # experimentally derived to be a decent choice
356361

357362
CCACHE_DIR: /tmp/ccache_dir
363+
INSTALL_DIR: /tmp/meson-install
358364
DEBUGINFOD_URLS: "https://debuginfod.debian.net"
359365

360366
# Enable a reasonable set of sanitizers. Use the linux task for that, as
@@ -462,6 +468,7 @@ task:
462468
su postgres <<-EOF
463469
meson setup \
464470
--buildtype=debug \
471+
--prefix=${INSTALL_DIR} \
465472
-Dcassert=true \
466473
${LINUX_MESON_FEATURES} \
467474
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
@@ -475,6 +482,7 @@ task:
475482
export CC='ccache gcc -m32'
476483
meson setup \
477484
--buildtype=debug \
485+
--prefix=${INSTALL_DIR}-32 \
478486
-Dcassert=true \
479487
${LINUX_MESON_FEATURES} \
480488
-Dllvm=disabled \
@@ -486,6 +494,7 @@ task:
486494
487495
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
488496
build_32_script: su postgres -c 'ninja -C build-32 -j${BUILD_JOBS}'
497+
install_script: su postgres -c 'ninja -C build install'
489498

490499
upload_caches: ccache
491500

@@ -497,6 +506,8 @@ task:
497506
# so that we don't upload 64bit logs if 32bit fails
498507
rm -rf build/
499508
509+
install_32_script: su postgres -c 'ninja -C build-32 install'
510+
500511
# There's currently no coverage of icu with LANG=C in the buildfarm. We
501512
# can easily provide some here by running one of the sets of tests that
502513
# way. Newer versions of python insist on changing the LC_CTYPE away
@@ -521,6 +532,7 @@ task:
521532
TEST_JOBS: 8 # experimentally derived to be a decent choice
522533

523534
CCACHE_DIR: /tmp/ccache_dir
535+
INSTALL_DIR: /tmp/meson-install
524536
DEBUGINFOD_URLS: ${DEBUGINFO}
525537

526538
TCL_DIR: /usr/lib64/
@@ -572,12 +584,14 @@ task:
572584
su postgres <<-EOF
573585
meson setup \
574586
--buildtype debug \
587+
--prefix=${INSTALL_DIR} \
575588
-Dcassert=true -Dssl=openssl -Duuid=e2fs ${LLVM} \
576589
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
577590
build
578591
EOF
579592
580593
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
594+
install_script: su postgres -c 'ninja -C build install'
581595
upload_caches: ccache
582596

583597
test_world_script: |
@@ -603,6 +617,7 @@ task:
603617

604618
CIRRUS_WORKING_DIR: ${HOME}/pgsql/
605619
CCACHE_DIR: ${HOME}/ccache
620+
INSTALL_DIR: /tmp/meson-install
606621
HOMEBREW_CACHE: ${HOME}/homebrew-cache
607622
PERL5LIB: ${HOME}/perl5/lib/perl5
608623

@@ -675,6 +690,8 @@ task:
675690
676691
meson setup \
677692
--buildtype=debug \
693+
--prefix=${INSTALL_DIR} \
694+
-Dpkg_config_path=$PKG_CONFIG_PATH \
678695
-Dextra_include_dirs=${brewpath}/include \
679696
-Dextra_lib_dirs=${brewpath}/lib \
680697
-Dcassert=true \
@@ -684,6 +701,7 @@ task:
684701
build
685702
686703
build_script: ninja -C build -j${BUILD_JOBS}
704+
install_script: ninja -C build install
687705
upload_caches: ccache
688706

689707
test_world_script: |

meson.build

+20
Original file line numberDiff line numberDiff line change
@@ -3102,6 +3102,26 @@ test('install_test_files',
31023102

31033103
test_result_dir = meson.build_root() / 'testrun'
31043104

3105+
# it seems freebsd doesn't use libdir for pkgconfig path
3106+
if host_system == 'freebsd'
3107+
pkgconf_installdir = dir_prefix / 'libdata' / 'pkgconfig'
3108+
else
3109+
pkgconf_installdir = dir_prefix / dir_lib / 'pkgconfig'
3110+
endif
3111+
test_pkg_conf_file = files('src/tools/ci/test_pkg_conf')
3112+
test('pkg_conf_extensions',
3113+
test_pkg_conf_file,
3114+
args: [
3115+
'--meson', meson_bin.path(),
3116+
'--meson_args', meson_args,
3117+
'--rootdir', meson.source_root(),
3118+
'--pkgconf_installdir', pkgconf_installdir,
3119+
'--builddir', meson.build_root(),
3120+
'--pkg_conf_path', get_option('pkg_config_path'),
3121+
'--',
3122+
cc.cmd_array(),
3123+
],)
3124+
31053125

31063126
# XXX: pg_regress doesn't assign unique ports on windows. To avoid the
31073127
# inevitable conflicts from running tests in parallel, hackishly assign

src/tools/ci/test_pkg_conf

+123
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)