Skip to content

Commit ae9a6e1

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

File tree

3 files changed

+166
-4
lines changed

3 files changed

+166
-4
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 -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:
@@ -231,6 +234,7 @@ task:
231234

232235
CIRRUS_WORKING_DIR: /home/postgres/postgres
233236
CCACHE_DIR: /tmp/ccache_dir
237+
INSTALL_DIR: /tmp/meson-install
234238

235239
PATH: /usr/sbin:$PATH
236240

@@ -288,13 +292,15 @@ task:
288292
su postgres <<-EOF
289293
meson setup \
290294
--buildtype debug \
295+
--prefix=${INSTALL_DIR} \
291296
-Dcassert=true -Dssl=openssl ${UUID} \
292297
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
293298
${INCLUDE_DIRS} \
294299
build
295300
EOF
296301
297302
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
303+
install_script: su postgres -c 'ninja -C build install'
298304
upload_caches: ccache
299305

300306
test_world_script: |
@@ -355,6 +361,7 @@ task:
355361
TEST_JOBS: 8 # experimentally derived to be a decent choice
356362

357363
CCACHE_DIR: /tmp/ccache_dir
364+
INSTALL_DIR: /tmp/meson-install
358365
DEBUGINFOD_URLS: "https://debuginfod.debian.net"
359366

360367
# Enable a reasonable set of sanitizers. Use the linux task for that, as
@@ -462,6 +469,7 @@ task:
462469
su postgres <<-EOF
463470
meson setup \
464471
--buildtype=debug \
472+
--prefix=${INSTALL_DIR} \
465473
-Dcassert=true \
466474
${LINUX_MESON_FEATURES} \
467475
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
@@ -475,6 +483,7 @@ task:
475483
export CC='ccache gcc -m32'
476484
meson setup \
477485
--buildtype=debug \
486+
--prefix=${INSTALL_DIR}-32 \
478487
-Dcassert=true \
479488
${LINUX_MESON_FEATURES} \
480489
-Dllvm=disabled \
@@ -486,6 +495,7 @@ task:
486495
487496
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
488497
build_32_script: su postgres -c 'ninja -C build-32 -j${BUILD_JOBS}'
498+
install_script: su postgres -c 'ninja -C build install'
489499

490500
upload_caches: ccache
491501

@@ -497,6 +507,8 @@ task:
497507
# so that we don't upload 64bit logs if 32bit fails
498508
rm -rf build/
499509
510+
install_32_script: su postgres -c 'ninja -C build-32 install'
511+
500512
# There's currently no coverage of icu with LANG=C in the buildfarm. We
501513
# can easily provide some here by running one of the sets of tests that
502514
# way. Newer versions of python insist on changing the LC_CTYPE away
@@ -521,6 +533,7 @@ task:
521533
TEST_JOBS: 8 # experimentally derived to be a decent choice
522534

523535
CCACHE_DIR: /tmp/ccache_dir
536+
INSTALL_DIR: /tmp/meson-install
524537
DEBUGINFOD_URLS: ${DEBUGINFO}
525538

526539
TCL_DIR: /usr/lib64/
@@ -572,12 +585,14 @@ task:
572585
su postgres <<-EOF
573586
meson setup \
574587
--buildtype debug \
588+
--prefix=${INSTALL_DIR} \
575589
-Dcassert=true -Dssl=openssl -Duuid=e2fs ${LLVM} \
576590
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
577591
build
578592
EOF
579593
580594
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
595+
install_script: su postgres -c 'ninja -C build install'
581596
upload_caches: ccache
582597

583598
test_world_script: |
@@ -603,6 +618,7 @@ task:
603618

604619
CIRRUS_WORKING_DIR: ${HOME}/pgsql/
605620
CCACHE_DIR: ${HOME}/ccache
621+
INSTALL_DIR: /tmp/meson-install
606622
HOMEBREW_CACHE: ${HOME}/homebrew-cache
607623
PERL5LIB: ${HOME}/perl5/lib/perl5
608624

@@ -675,6 +691,8 @@ task:
675691
676692
meson setup \
677693
--buildtype=debug \
694+
--prefix=${INSTALL_DIR} \
695+
-Dpkg_config_path=$PKG_CONFIG_PATH \
678696
-Dextra_include_dirs=${brewpath}/include \
679697
-Dextra_lib_dirs=${brewpath}/lib \
680698
-Dcassert=true \
@@ -684,6 +702,7 @@ task:
684702
build
685703
686704
build_script: ninja -C build -j${BUILD_JOBS}
705+
install_script: ninja -C build install
687706
upload_caches: ccache
688707

689708
test_world_script: |

meson.build

Lines changed: 20 additions & 0 deletions
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

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)