Skip to content

Commit

Permalink
meson: test extensions build by pkg-conf
Browse files Browse the repository at this point in the history
  • Loading branch information
nbyavuz committed Jun 7, 2023
1 parent d1491d3 commit 75044fd
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 4 deletions.
26 changes: 22 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ task:
TEST_JOBS: 3

CCACHE_DIR: /tmp/ccache_dir
INSTALL_DIR: /tmp/meson-install
CPPFLAGS: -DRELCACHE_FORCE_RELEASE -DCOPY_PARSE_PLAN_TREES -DWRITE_READ_PARSE_PLAN_TREES -DRAW_EXPRESSION_COVERAGE_TEST
CFLAGS: -Og -ggdb

Expand Down Expand Up @@ -187,6 +188,7 @@ task:
build
EOF
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
install_script: su postgres -c 'ninja -C build install'
upload_caches: ccache

test_world_script: |
Expand All @@ -201,13 +203,13 @@ task:
set -e
ulimit -c unlimited
meson test $MTEST_ARGS --quiet --suite setup
export LD_LIBRARY_PATH="$(pwd)/build/tmp_install/usr/local/pgsql/lib/:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="${INSTALL_DIR}/lib/:$LD_LIBRARY_PATH"
mkdir -p build/testrun
build/tmp_install/usr/local/pgsql/bin/initdb -N build/runningcheck --no-instructions -A trust
${INSTALL_DIR}/bin/initdb -N build/runningcheck --no-instructions -A trust
echo "include '$(pwd)/src/tools/ci/pg_ci_base.conf'" >> build/runningcheck/postgresql.conf
build/tmp_install/usr/local/pgsql/bin/pg_ctl -c -o '-c fsync=off' -D build/runningcheck -l build/testrun/runningcheck.log start
${INSTALL_DIR}/bin/pg_ctl -c -o '-c fsync=off' -D build/runningcheck -l build/testrun/runningcheck.log start
meson test $MTEST_ARGS --num-processes ${TEST_JOBS} --setup running
build/tmp_install/usr/local/pgsql/bin/pg_ctl -D build/runningcheck stop
${INSTALL_DIR}/bin/pg_ctl -D build/runningcheck stop
EOF
on_failure:
Expand All @@ -231,6 +233,7 @@ task:

CIRRUS_WORKING_DIR: /home/postgres/postgres
CCACHE_DIR: /tmp/ccache_dir
INSTALL_DIR: /tmp/meson-install

PATH: /usr/sbin:$PATH

Expand Down Expand Up @@ -288,13 +291,15 @@ task:
su postgres <<-EOF
meson setup \
--buildtype debug \
--prefix=${INSTALL_DIR} \
-Dcassert=true -Dssl=openssl ${UUID} \
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
${INCLUDE_DIRS} \
build
EOF
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
install_script: su postgres -c 'ninja -C build install'
upload_caches: ccache

test_world_script: |
Expand Down Expand Up @@ -355,6 +360,7 @@ task:
TEST_JOBS: 8 # experimentally derived to be a decent choice

CCACHE_DIR: /tmp/ccache_dir
INSTALL_DIR: /tmp/meson-install
DEBUGINFOD_URLS: "https://debuginfod.debian.net"

# Enable a reasonable set of sanitizers. Use the linux task for that, as
Expand Down Expand Up @@ -462,6 +468,7 @@ task:
su postgres <<-EOF
meson setup \
--buildtype=debug \
--prefix=${INSTALL_DIR} \
-Dcassert=true \
${LINUX_MESON_FEATURES} \
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
Expand All @@ -475,6 +482,7 @@ task:
export CC='ccache gcc -m32'
meson setup \
--buildtype=debug \
--prefix=${INSTALL_DIR}-32 \
-Dcassert=true \
${LINUX_MESON_FEATURES} \
-Dllvm=disabled \
Expand All @@ -486,6 +494,7 @@ task:
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
build_32_script: su postgres -c 'ninja -C build-32 -j${BUILD_JOBS}'
install_script: su postgres -c 'ninja -C build install'

upload_caches: ccache

Expand All @@ -497,6 +506,8 @@ task:
# so that we don't upload 64bit logs if 32bit fails
rm -rf build/
install_32_script: su postgres -c 'ninja -C build-32 install'

# There's currently no coverage of icu with LANG=C in the buildfarm. We
# can easily provide some here by running one of the sets of tests that
# way. Newer versions of python insist on changing the LC_CTYPE away
Expand All @@ -521,6 +532,7 @@ task:
TEST_JOBS: 8 # experimentally derived to be a decent choice

CCACHE_DIR: /tmp/ccache_dir
INSTALL_DIR: /tmp/meson-install
DEBUGINFOD_URLS: ${DEBUGINFO}

TCL_DIR: /usr/lib64/
Expand Down Expand Up @@ -572,12 +584,14 @@ task:
su postgres <<-EOF
meson setup \
--buildtype debug \
--prefix=${INSTALL_DIR} \
-Dcassert=true -Dssl=openssl -Duuid=e2fs ${LLVM} \
-DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
build
EOF
build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
install_script: su postgres -c 'ninja -C build install'
upload_caches: ccache

test_world_script: |
Expand All @@ -603,6 +617,7 @@ task:

CIRRUS_WORKING_DIR: ${HOME}/pgsql/
CCACHE_DIR: ${HOME}/ccache
INSTALL_DIR: /tmp/meson-install
HOMEBREW_CACHE: ${HOME}/homebrew-cache
PERL5LIB: ${HOME}/perl5/lib/perl5

Expand Down Expand Up @@ -675,6 +690,8 @@ task:
meson setup \
--buildtype=debug \
--prefix=${INSTALL_DIR} \
-Dpkg_config_path=$PKG_CONFIG_PATH \
-Dextra_include_dirs=${brewpath}/include \
-Dextra_lib_dirs=${brewpath}/lib \
-Dcassert=true \
Expand All @@ -684,6 +701,7 @@ task:
build
build_script: ninja -C build -j${BUILD_JOBS}
install_script: ninja -C build install
upload_caches: ccache

test_world_script: |
Expand Down
20 changes: 20 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,26 @@ test('install_test_files',

test_result_dir = meson.build_root() / 'testrun'

# it seems freebsd doesn't use libdir for pkgconfig path
if host_system == 'freebsd'
pkgconf_installdir = dir_prefix / 'libdata' / 'pkgconfig'
else
pkgconf_installdir = dir_prefix / dir_lib / 'pkgconfig'
endif
test_pkg_conf_file = files('src/tools/ci/test_pkg_conf')
test('pkg_conf_extensions',
test_pkg_conf_file,
args: [
'--meson', meson_bin.path(),
'--meson_args', meson_args,
'--rootdir', meson.source_root(),
'--pkgconf_installdir', pkgconf_installdir,
'--builddir', meson.build_root(),
'--pkg_conf_path', get_option('pkg_config_path'),
'--',
cc.cmd_array(),
],)


# XXX: pg_regress doesn't assign unique ports on windows. To avoid the
# inevitable conflicts from running tests in parallel, hackishly assign
Expand Down
123 changes: 123 additions & 0 deletions src/tools/ci/test_pkg_conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python3

import argparse
import ast
import shutil
import subprocess
import os
import sys

parser = argparse.ArgumentParser()

parser.add_argument('--rootdir', help='root directory',
type=str, required=True)
parser.add_argument('--pkgconf_installdir', help='pkgconf install directory',
type=str, required=True)
parser.add_argument('--builddir', help='build directory',
type=str, required=True)
parser.add_argument('--meson', help='path to meson binary',
type=str, required=True)
parser.add_argument('--meson_args', help='args of meson binary',
type=str, nargs='*', required=False)
parser.add_argument('--pkg_conf_path',
help='PKG_CONF_PATH from surrounding meson build',
type=str, nargs='?', const='', required=False)

parser.add_argument('c_args', help='c_args from surrounding meson build',
nargs='*')

args = parser.parse_args()

rootdir = os.path.realpath(args.rootdir)
builddir = os.path.realpath(args.builddir)
pkgconf_installdir = os.path.realpath(args.pkgconf_installdir)
adminpackdir = os.path.join(rootdir, 'contrib/adminpack/')
workdir = os.path.join(builddir, 'contrib/adminpack_tmp')
meson_args = ' '.join(args.meson_args)
c_args = ' '.join(args.c_args)
exit_code = 0

adminpack_meson_build_file = \
'''
project('adminpack', 'c')
pg_ext = dependency('postgresql-extension-warnings')
adminpack = shared_module('adminpack',
['{}adminpack.c'],
dependencies: pg_ext,
name_prefix: '',
install_dir: pg_ext.get_variable(pkgconfig: 'dir_mod')
)
install_data(
'{}adminpack.control',
'{}adminpack--1.0.sql',
'{}adminpack--1.0--1.1.sql',
'{}adminpack--1.1--2.0.sql',
'{}adminpack--2.0--2.1.sql',
install_dir: pg_ext.get_variable(pkgconfig: 'dir_data')
)
'''.format(adminpackdir, adminpackdir, adminpackdir, adminpackdir,
adminpackdir, adminpackdir)

# clear workdir
if os.path.exists(workdir):
shutil.rmtree(workdir)
os.makedirs(workdir)

# overwrite meson.build file
meson_file = os.path.join(workdir, 'meson.build')
with open(meson_file, 'w') as f:
f.write(adminpack_meson_build_file)


def remove_duplicates(duplicate_str):
words = duplicate_str.split()
return ' '.join(sorted(set(words), key=words.index))


# run tests
def run_tests(pkg_conf_path, message=''):
print('\n{}\n{}\n'.format('#' * 60, message), flush=True)

adminpack_builddir = os.path.join(workdir, 'build')

env = {**os.environ, }
env['PKG_CONFIG_PATH'] = '{}:{}:{}'.format(
pkg_conf_path, args.pkg_conf_path, env.get('PKG_CONFIG_PATH', ''),
).strip(': ')
env['CC'] = '{} {}'.format(
c_args, env.get('CC', ''),
)
env['CC'] = remove_duplicates(env['CC'])

if os.path.exists(adminpack_builddir):
shutil.rmtree(adminpack_builddir)

if meson_args:
meson_setup_command = [args.meson, meson_args, 'setup', 'build']
else:
meson_setup_command = [args.meson, 'setup', 'build']

ninja_build_command = ['ninja', '-C', 'build', '-v']
if subprocess.run(meson_setup_command, env=env,
cwd=workdir).returncode != 0:
return False
if subprocess.run(ninja_build_command, cwd=workdir).returncode != 0:
return False
return True


# test postgresql-extension-warnings
if not run_tests(pkgconf_installdir,
message='Testing postgresql-extension-warnings'):
exit_code = exit_code + 1


# test postgresql-extension-warnings-uninstalled
if not run_tests(os.path.join(builddir, 'meson-uninstalled'),
message='Testing postgresql-extension-warnings-uninstalled'):
exit_code = exit_code + 1

sys.exit(exit_code)

0 comments on commit 75044fd

Please sign in to comment.