From ab232217c9cd1f9f36aa85519a88153af9bde101 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sat, 27 Aug 2022 09:52:03 -0700 Subject: [PATCH 01/12] meson: Add postgresql-extension.pc for building extension libraries This should work with several other buildsystems. TODO: Docs and example --- src/backend/meson.build | 106 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/src/backend/meson.build b/src/backend/meson.build index ccfc382fcfd15..ec479867e5e70 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -195,6 +195,112 @@ pg_test_mod_args = pg_mod_args + { +############################################################### +# Define a .pc file that can be used to build server extensions +############################################################### + +pg_ext_vars = [] +pg_ext_vars_inst = [] +pg_ext_vars_uninst = [] + +pg_ext_cflags = pg_mod_c_args + cppflags +pg_ext_libs = [backend_mod_deps, thread_dep, ldflags, ldflags_mod] +pg_ext_subdirs = [''] + +# Compute directories to add include directories to the .pc files for. +# This is a bit more complicated due to port/win32 etc. +i = 0 +foreach incdir : postgres_inc_d + if fs.is_absolute(incdir) + # an absolute path from -Dextra_include_dirs + pg_ext_cflags += '-I@0@'.format(incdir) + continue + elif incdir.startswith('src/include') + subincdir = dir_include_pkg_rel / 'server' / incdir.split('src/include/').get(1, '') + else + subincdir = '' + endif + pg_ext_subdirs += subincdir + + # Add directories in source / build dir containing headers to cflags for the + # -uninstalled.pc. Older versions of pkg-config complain if a referenced + # variable is not defined, so we emit an empty one for the installed .pc + # file. + pg_ext_vars += [ + 'build_inc@0@=""'.format(i), + 'src_inc@0@=""'.format(i), + ] + pg_ext_vars_uninst += [ + 'build_inc@0@=-I${prefix}/@1@'.format(i, incdir), + 'src_inc@0@=-I${srcdir}/@1@'.format(i, incdir), + ] + pg_ext_cflags += [ + '${build_inc@0@}'.format(i), + '${src_inc@0@}'.format(i) + ] + + i += 1 +endforeach + + +# Extension modules should likely also use -fwrapv etc. But it it's a bit odd +# to expose it to a .pc file? +pg_ext_cflags += cflags + +# Directories for extensions to install into +# XXX: more needed +pg_ext_vars += 'pkglibdir=${prefix}/@0@'.format(dir_lib_pkg) +pg_ext_vars += 'dir_mod=${pkglibdir}' +pg_ext_vars += 'dir_data=${prefix}/@0@'.format(dir_data_extension) +# referenced on some platforms, via mod_link_with_dir +pg_ext_vars += 'bindir=${prefix}/@0@'.format(dir_bin) + +# XXX: Define variables making it easy to define tests, too + +# Some platforms need linker flags to link with binary, they are the same +# between building with meson and .pc file, except that we have have to +# reference a variable to make it work for both normal and -uninstalled .pc +# files. +if mod_link_args_fmt.length() != 0 + assert(link_with_inst != '') + assert(link_with_uninst != '') + + pg_ext_vars_inst += 'mod_link_with=@0@'.format(link_with_inst) + pg_ext_vars_uninst += 'mod_link_with=@0@'.format(link_with_uninst) + + foreach el : mod_link_args_fmt + pg_ext_libs += el.format('${mod_link_with}') + endforeach +endif + +# main .pc to build extensions +pkgconfig.generate( + name: 'postgresql-extension', + description: 'PostgreSQL Extension Support', + url: pg_url, + + subdirs: pg_ext_subdirs, + libraries: pg_ext_libs, + extra_cflags: pg_ext_cflags, + + variables: pg_ext_vars + pg_ext_vars_inst, + uninstalled_variables: pg_ext_vars + pg_ext_vars_uninst, +) + +# a .pc depending on the above, but with all our warnings enabled +pkgconfig.generate( + name: 'postgresql-extension-warnings', + description: 'PostgreSQL Extension Support - Compiler Warnings', + requires: 'postgresql-extension', + url: pg_url, + extra_cflags: cflags_warn, + + variables: pg_ext_vars + pg_ext_vars_inst, + uninstalled_variables: pg_ext_vars + pg_ext_vars_uninst, +) + + + # Shared modules that, on some system, link against the server binary. Only # enter these after we defined the server build. From 6e2c89d6c6477663e42e132223d7565733de1bfe Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 26 Sep 2022 17:24:47 -0700 Subject: [PATCH 02/12] meson: Add support for relative rpaths, fixing tests on MacOS w/ SIP --- meson.build | 68 ++++++++++---- .../relativize_shared_library_references | 88 +++++++++++++++++++ src/tools/relpath.py | 6 ++ 3 files changed, 145 insertions(+), 17 deletions(-) create mode 100755 src/tools/relativize_shared_library_references create mode 100755 src/tools/relpath.py diff --git a/meson.build b/meson.build index 16b2e866462a2..39641a1ad0e25 100644 --- a/meson.build +++ b/meson.build @@ -167,6 +167,7 @@ portname = host_system exesuffix = '' # overridden below where necessary dlsuffix = '.so' # overridden below where necessary +rpath_origin = '$ORIGIN' library_path_var = 'LD_LIBRARY_PATH' # Format of file to control exports from libraries, and how to pass them to @@ -222,6 +223,7 @@ elif host_system == 'cygwin' elif host_system == 'darwin' dlsuffix = '.dylib' library_path_var = 'DYLD_LIBRARY_PATH' + rpath_origin = '@loader_path' export_file_format = 'darwin' export_fmt = '-exported_symbols_list=@0@' @@ -260,8 +262,16 @@ elif host_system == 'netbsd' # LDFLAGS. ldflags += ['-Wl,-z,now', '-Wl,-z,relro'] + # netbsd patched their meson in a broken way: + # https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=56959 + # until there's a way out of that, disable rpath_origin + rpath_origin = '' + elif host_system == 'openbsd' - # you're ok + # openbsd's $ORIGIN doesn't use an absolute path to the binary, but argv[0] + # (i.e. absolute when invoked with an absolute name, but e.g. not absolute + # when invoked via PATH search). + rpath_origin = '' elif host_system == 'sunos' portname = 'solaris' @@ -273,6 +283,7 @@ elif host_system == 'windows' exesuffix = '.exe' dlsuffix = '.dll' library_path_var = '' + rpath_origin = '' export_file_format = 'win' export_file_suffix = 'def' @@ -2606,25 +2617,41 @@ bin_install_rpaths = [] lib_install_rpaths = [] mod_install_rpaths = [] - -# Don't add rpaths on darwin for now - as long as only absolute references to -# libraries are needed, absolute LC_ID_DYLIB ensures libraries can be found in -# their final destination. +# Add extra_lib_dirs to rpath. This ensures we find libraries we depend on. +# +# Not needed on darwin, even if we use relative rpaths for our own libraries, +# as the install_name of libraries in extra_lib_dirs will point to their +# location anyway. if host_system != 'darwin' + bin_install_rpaths += postgres_lib_d + lib_install_rpaths += postgres_lib_d + mod_install_rpaths += postgres_lib_d +endif + +# If the host can form relative rpaths, use that to make the installation +# properly relocatable +if rpath_origin != '' + # PG binaries might need to link to libpq, use relative path to reference + bin_to_lib = run_command(python, files('src/tools/relpath.py'), + dir_bin, dir_lib, check: true).stdout().strip() + bin_install_rpaths += rpath_origin / bin_to_lib + + # PG extensions might need to link to libpq, use relative path to reference + # (often just .) + mod_to_lib = run_command(python, files('src/tools/relpath.py'), + dir_lib_pkg, dir_lib, check: true).stdout().strip() + mod_install_rpaths += rpath_origin / mod_to_lib + + test_use_library_path_var = false +else + # Add absolute path to libdir to rpath. This ensures installed binaries / # libraries find our libraries (mainly libpq). bin_install_rpaths += dir_prefix / dir_lib lib_install_rpaths += dir_prefix / dir_lib mod_install_rpaths += dir_prefix / dir_lib - # Add extra_lib_dirs to rpath. This ensures we find libraries we depend on. - # - # Not needed on darwin even if we use relative rpaths for our own libraries, - # as the install_name of libraries in extra_lib_dirs will point to their - # location anyway. - bin_install_rpaths += postgres_lib_d - lib_install_rpaths += postgres_lib_d - mod_install_rpaths += postgres_lib_d + test_use_library_path_var = true endif @@ -2948,6 +2975,14 @@ above, or by running configure and then make maintainer-clean. endif +# To make MacOS installation work without a prior make install, even with SIP +# enabled, make rpaths relative after installation. This also makes the +# installation relocatable. +if host_system == 'darwin' + meson.add_install_script('src/tools/relativize_shared_library_references') +endif + + ############################################################### # Install targets @@ -3072,10 +3107,9 @@ test_env.set('REGRESS_SHLIB', regress_module.full_path()) # Export PG_TEST_EXTRA so it can be checked in individual tap tests. test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA')) -# Add the temporary installation to the library search path on platforms where -# that works (everything but windows, basically). On windows everything -# library-like gets installed into bindir, solving that issue. -if library_path_var != '' +# On platforms without $ORIGIN support we need to add the temporary +# installation to the library search path. +if test_use_library_path_var and library_path_var != '' test_env.prepend(library_path_var, test_install_location / get_option('libdir')) endif diff --git a/src/tools/relativize_shared_library_references b/src/tools/relativize_shared_library_references new file mode 100755 index 0000000000000..280bd48fd3227 --- /dev/null +++ b/src/tools/relativize_shared_library_references @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# -*-python-*- + +# This script updates a macos postgres installation to reference all internal +# shared libraries using rpaths, leaving absolute install_names in the +# libraries themselves intact. + +import os +import sys +import json +import subprocess +import shutil + + +def installed_path(destdir, path): + if destdir is not None: + return f'{destdir}{path}' + else: + return path + + +def collect_information(): + shared_libraries = [] + executables = [] + shared_modules = [] + + meson_info_p = os.path.join(build_root, 'meson-info') + targets = json.load( + open(os.path.join(meson_info_p, 'intro-targets.json'))) + installed = json.load( + open(os.path.join(meson_info_p, 'intro-installed.json'))) + + for target in targets: + if not target['installed']: + continue + + filenames = target['filename'] + + if target['type'] == 'shared library': + assert(len(filenames) == 1) + filename = filenames[0] + + shared_libraries.append(installed[filename]) + + if target['type'] == 'executable': + assert(len(filenames) == 1) + filename = filenames[0] + executables.append(installed[filename]) + + if target['type'] == 'shared module': + assert(len(filenames) == 1) + filename = filenames[0] + shared_modules.append(installed[filename]) + + return shared_libraries, executables, shared_modules + + +def patch_references(destdir, shared_libraries, executables, shared_modules): + install_name_tool = [shutil.which('install_name_tool')] + + for lib in shared_libraries: + libname = os.path.basename(lib) + libpath = installed_path(destdir, lib) + newref = f'@rpath/{libname}' + + for patch in shared_modules + executables: + patchpath = installed_path(destdir, patch) + + # print(f'in {patchpath} replace reference to {libpath} with {newref}') + if not os.path.exists(patchpath): + print(f"path {patchpath} doesn't exist", file=sys.stderr) + sys.exit(1) + + cmd = install_name_tool + ['-change', lib, newref, patchpath] + subprocess.check_call(cmd) + + +if __name__ == '__main__': + build_root = os.environ['MESON_BUILD_ROOT'] + destdir = os.environ.get('DESTDIR', None) + + print(f'making references to shared libraries relative, destdir is {destdir}', + file=sys.stderr) + + shared_libraries, executables, shared_modules = collect_information() + patch_references(destdir, shared_libraries, executables, shared_modules) + + sys.exit(0) diff --git a/src/tools/relpath.py b/src/tools/relpath.py new file mode 100755 index 0000000000000..87bcb496ab59c --- /dev/null +++ b/src/tools/relpath.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +import os +import sys + +print(os.path.relpath(sys.argv[2], start=sys.argv[1])) From a8bbae39d16f08d6f302a52e6ef658050a2a8695 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Fri, 10 Mar 2023 22:31:44 -0800 Subject: [PATCH 03/12] meson: add generated header stamps --- meson.build | 14 ++++++++------ src/backend/meson.build | 2 +- src/fe_utils/meson.build | 2 +- src/include/meson.build | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index 39641a1ad0e25..b35d9c94d6485 100644 --- a/meson.build +++ b/meson.build @@ -2706,6 +2706,8 @@ gen_export_kwargs = { 'install': false, } +# command to create stamp files on all OSs +stamp_cmd = [python, '-c', 'import sys; open(sys.argv[1], "w")', '@OUTPUT0@'] ### @@ -2809,14 +2811,14 @@ subdir('src/port') frontend_common_code = declare_dependency( compile_args: ['-DFRONTEND'], include_directories: [postgres_inc], - sources: generated_headers, + sources: generated_headers_stamp, dependencies: [os_deps, zlib, zstd], ) backend_common_code = declare_dependency( compile_args: ['-DBUILDING_DLL'], include_directories: [postgres_inc], - sources: generated_headers, + sources: generated_headers_stamp, dependencies: [os_deps, zlib, zstd], ) @@ -2831,7 +2833,7 @@ shlib_code = declare_dependency( frontend_stlib_code = declare_dependency( include_directories: [postgres_inc], link_with: [common_static, pgport_static], - sources: generated_headers, + sources: generated_headers_stamp, dependencies: [os_deps, libintl], ) @@ -2839,7 +2841,7 @@ frontend_stlib_code = declare_dependency( frontend_shlib_code = declare_dependency( include_directories: [postgres_inc], link_with: [common_shlib, pgport_shlib], - sources: generated_headers, + sources: generated_headers_stamp, dependencies: [shlib_code, os_deps, libintl], ) @@ -2861,7 +2863,7 @@ subdir('src/fe_utils') frontend_code = declare_dependency( include_directories: [postgres_inc], link_with: [fe_utils, common_static, pgport_static], - sources: generated_headers, + sources: generated_headers_stamp, dependencies: [os_deps, libintl], ) @@ -2889,7 +2891,7 @@ backend_code = declare_dependency( include_directories: [postgres_inc], link_args: ldflags_be, link_with: [], - sources: generated_headers + generated_backend_headers, + sources: [generated_backend_headers_stamp], dependencies: os_deps + backend_both_deps + backend_deps, ) diff --git a/src/backend/meson.build b/src/backend/meson.build index ec479867e5e70..e857a330fddcd 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -176,7 +176,7 @@ backend_mod_code = declare_dependency( compile_args: pg_mod_c_args, include_directories: postgres_inc, link_args: pg_mod_link_args, - sources: generated_headers + generated_backend_headers, + sources: [generated_backend_headers_stamp], dependencies: backend_mod_deps, ) diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index ea96e862adb23..406e31b5b4105 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -24,7 +24,7 @@ generated_sources += psqlscan fe_utils_sources += psqlscan fe_utils = static_library('libpgfeutils', - fe_utils_sources + generated_headers, + fe_utils_sources, c_pch: pch_postgres_fe_h, include_directories: [postgres_inc, libpq_inc], c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], diff --git a/src/include/meson.build b/src/include/meson.build index 33c0a5562c60a..66d0c2072fa6d 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -186,3 +186,17 @@ install_subdir('catalog', # autoconf generates the file there, ensure we get a conflict generated_sources_ac += {'src/include': ['stamp-h', 'stamp-ext-h']} + + +generated_headers_stamp = custom_target('generated-headers-stamp.h', + output: 'generated-headers-stamp.h', + input: [generated_headers], + command: stamp_cmd, +) + +generated_backend_headers_stamp = custom_target('generated-backend-headers-stamp.h', + output: 'generated-backend-headers-stamp.h', + input: [generated_backend_headers], + depends: generated_headers_stamp, + command: stamp_cmd, +) From 30917aa3e48597356e2e0ade27e6e009a086a484 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Fri, 10 Mar 2023 22:32:02 -0800 Subject: [PATCH 04/12] meson: cpluspluscheck prereq --- src/makefiles/meson.build | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/makefiles/meson.build b/src/makefiles/meson.build index 13045cbd6e494..0030d75c67fd0 100644 --- a/src/makefiles/meson.build +++ b/src/makefiles/meson.build @@ -117,6 +117,10 @@ pgxs_kv = { 'FLEXFLAGS': ' '.join(flex_flags), 'LIBS': var_libs, + + # Needed for headerscheck/cpluspluscheck + 'perl_includespec': perl_dep.found() ? ' '.join(perl_ccflags) : '', + 'python_includespec': python3_dep.found() ? '-I@0@'.format(python3_inst.get_variable('INCLUDEPY')) : '', } if llvm.found() @@ -180,8 +184,8 @@ pgxs_empty = [ 'LIBOBJS', 'PG_CRC32C_OBJS', 'TAS', 'DTRACEFLAGS', # only server has dtrace probes - 'perl_archlibexp', 'perl_embed_ccflags', 'perl_embed_ldflags', 'perl_includespec', 'perl_privlibexp', - 'python_additional_libs', 'python_includespec', 'python_libdir', 'python_libspec', 'python_majorversion', 'python_version', + 'perl_archlibexp', 'perl_embed_ccflags', 'perl_embed_ldflags', 'perl_privlibexp', + 'python_additional_libs', 'python_libdir', 'python_libspec', 'python_majorversion', 'python_version', # possible that some of these are referenced explicitly in pgxs makefiles? # For now not worth it. From ae53f21d06b4dadf8e6b90df84000fad9a769eaf Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sat, 3 Jun 2023 08:56:44 -0700 Subject: [PATCH 05/12] meson: ci: wip: move compilerwarnings task to meson --- .cirrus.yml | 96 +++++++++++++------------- src/tools/ci/linux-mingw-w64-64bit.txt | 13 ++++ 2 files changed, 61 insertions(+), 48 deletions(-) create mode 100644 src/tools/ci/linux-mingw-w64-64bit.txt diff --git a/.cirrus.yml b/.cirrus.yml index 113f4545244cc..3db0c2458d38e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -700,6 +700,10 @@ task: ccache_cache: folder: $CCACHE_DIR + ccache_stats_start_script: + ccache -s + ccache -z + setup_additional_packages_script: | #apt-get update #DEBIAN_FRONTEND=noninteractive apt-get -y install ... @@ -708,8 +712,6 @@ task: # Test that code can be built with gcc/clang without warnings ### - setup_script: echo "COPT=-Werror" > src/Makefile.custom - # Trace probes have a history of getting accidentally broken. Use the # different compilers to build with different combinations of dtrace on/off # and cassert on/off. @@ -717,58 +719,57 @@ task: # gcc, cassert off, dtrace on always: gcc_warning_script: | - time ./configure \ - --cache gcc.cache \ - --enable-dtrace \ - ${LINUX_CONFIGURE_FEATURES} \ - CC="ccache gcc" CXX="ccache g++" CLANG="ccache clang" - make -s -j${BUILD_JOBS} clean - time make -s -j${BUILD_JOBS} world-bin + mkdir build-gcc && cd build-gcc + CC="ccache gcc" CXX="ccache g++" \ + meson setup \ + -Dwerror=true \ + -Dcassert=false \ + -Ddtrace=enabled \ + ${LINUX_MESON_FEATURES} \ + .. + time ninja -j${BUILD_JOBS} # gcc, cassert on, dtrace off always: gcc_a_warning_script: | - time ./configure \ - --cache gcc.cache \ - --enable-cassert \ - ${LINUX_CONFIGURE_FEATURES} \ - CC="ccache gcc" CXX="ccache g++" CLANG="ccache clang" - make -s -j${BUILD_JOBS} clean - time make -s -j${BUILD_JOBS} world-bin + cd build-gcc + meson configure \ + -Dcassert=true \ + -Ddtrace=disabled + time ninja -j${BUILD_JOBS} # clang, cassert off, dtrace off always: clang_warning_script: | - time ./configure \ - --cache clang.cache \ - ${LINUX_CONFIGURE_FEATURES} \ - CC="ccache clang" CXX="ccache clang++" CLANG="ccache clang" - make -s -j${BUILD_JOBS} clean - time make -s -j${BUILD_JOBS} world-bin + mkdir build-clang && cd build-clang + CC="ccache clang" CXX="ccache clang++" \ + meson setup \ + -Dwerror=true \ + -Dcassert=false \ + -Ddtrace=disabled \ + ${LINUX_MESON_FEATURES} \ + .. + time ninja -j${BUILD_JOBS} # clang, cassert on, dtrace on always: clang_a_warning_script: | - time ./configure \ - --cache clang.cache \ - --enable-cassert \ - --enable-dtrace \ - ${LINUX_CONFIGURE_FEATURES} \ - CC="ccache clang" CXX="ccache clang++" CLANG="ccache clang" - make -s -j${BUILD_JOBS} clean - time make -s -j${BUILD_JOBS} world-bin + cd build-clang + meson configure \ + -Dcassert=true \ + -Ddtrace=enabled + time ninja -j${BUILD_JOBS} # cross-compile to windows always: mingw_cross_warning_script: | - time ./configure \ - --host=x86_64-w64-mingw32 \ - --enable-cassert \ - --without-icu \ - CC="ccache x86_64-w64-mingw32-gcc" \ - CXX="ccache x86_64-w64-mingw32-g++" - make -s -j${BUILD_JOBS} clean - time make -s -j${BUILD_JOBS} world-bin + mkdir build-w64 && cd build-w64 + meson setup \ + --cross-file=../src/tools/ci/linux-mingw-w64-64bit.txt \ + -Dwerror=true \ + -Dcassert=true \ + .. + time ninja -j${BUILD_JOBS} ### # Verify docs can be built @@ -776,13 +777,8 @@ task: # XXX: Only do this if there have been changes in doc/ since last build always: docs_build_script: | - time ./configure \ - --cache gcc.cache \ - CC="ccache gcc" \ - CXX="ccache g++" \ - CLANG="ccache clang" - make -s -j${BUILD_JOBS} clean - time make -s -j${BUILD_JOBS} -C doc + cd build-gcc + time ninja docs ### # Verify headerscheck / cpluspluscheck succeed @@ -795,15 +791,19 @@ task: ### always: headers_headerscheck_script: | - time ./configure \ + mkdir build-ac && cd build-ac + time ../configure \ ${LINUX_CONFIGURE_FEATURES} \ --without-icu \ --quiet \ - CC="gcc" CXX"=g++" CLANG="clang" - make -s -j${BUILD_JOBS} clean + CC="gcc" CXX="g++" CLANG="clang" + make -s -j${BUILD_JOBS} world-bin time make -s headerscheck EXTRAFLAGS='-fmax-errors=10' headers_cpluspluscheck_script: | + cd build-ac time make -s cpluspluscheck EXTRAFLAGS='-fmax-errors=10' always: + ccache_stats_end_script: + ccache -s upload_caches: ccache diff --git a/src/tools/ci/linux-mingw-w64-64bit.txt b/src/tools/ci/linux-mingw-w64-64bit.txt new file mode 100644 index 0000000000000..9d43b6dcfbc3b --- /dev/null +++ b/src/tools/ci/linux-mingw-w64-64bit.txt @@ -0,0 +1,13 @@ +[binaries] +c = ['ccache', '/usr/bin/x86_64-w64-mingw32-gcc'] +cpp = ['ccache', '/usr/bin/x86_64-w64-mingw32-g++'] +ar = '/usr/bin/x86_64-w64-mingw32-ar' +strip = '/usr/bin/x86_64-w64-mingw32-strip' +pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config' +windres = '/usr/bin/x86_64-w64-mingw32-windres' + +[host_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' From 940eae776fe0c38358b9ebd11ba5fa2580c7f459 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 26 Sep 2022 13:08:56 -0700 Subject: [PATCH 06/12] meson: wip: headerchecks cpluspluschecks --- src/include/meson.build | 4 ++-- src/include/utils/pg_locale.h | 2 ++ src/meson.build | 17 +++++++++++++++++ src/tools/pginclude/cpluspluscheck | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/include/meson.build b/src/include/meson.build index 66d0c2072fa6d..7dc802b6cc2d4 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -44,9 +44,9 @@ config_paths_data.set_quoted('MANDIR', dir_prefix / dir_man) var_cc = ' '.join(cc.cmd_array()) var_cpp = ' '.join(cc.cmd_array() + ['-E']) -var_cflags = ' '.join(cflags + cflags_warn + get_option('c_args')) +var_cflags = ' '.join(cflags + cflags_warn + get_option('c_args') + ['-Wall']) if llvm.found() - var_cxxflags = ' '.join(cxxflags + cxxflags_warn + get_option('cpp_args')) + var_cxxflags = ' '.join(cxxflags + cxxflags_warn + get_option('cpp_args') + ['-Wall']) else var_cxxflags = '' endif diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index e2a72435427cf..77c122ff1e581 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -16,6 +16,8 @@ #include #endif #ifdef USE_ICU +/* the cplusplus portion doesn't parse inside extern "C" { } */ +#define U_SHOW_CPLUSPLUS_API 0 #include #endif diff --git a/src/meson.build b/src/meson.build index bceeca70f90d2..820fd02ffa187 100644 --- a/src/meson.build +++ b/src/meson.build @@ -51,3 +51,20 @@ install_data( install_data( 'makefiles/pgxs.mk', install_dir: dir_pgxs / 'src' / 'makefiles') + + +generated_sources_stamp = custom_target('generated-sources-stamp.h', + output: 'generated-sources-stamp.h', + input: [generated_sources, generated_headers_stamp, generated_backend_headers_stamp], + command: stamp_cmd, +) + +run_target('headerscheck', + command: [files('tools/pginclude/headerscheck'), '@SOURCE_ROOT@', '@BUILD_ROOT@'], + depends: [generated_sources_stamp, generated_headers_stamp, generated_backend_headers_stamp], +) + +run_target('cpluspluscheck', + command: [files('tools/pginclude/cpluspluscheck'), '@SOURCE_ROOT@', '@BUILD_ROOT@'], + depends: [generated_sources_stamp, generated_headers_stamp, generated_backend_headers_stamp], +) diff --git a/src/tools/pginclude/cpluspluscheck b/src/tools/pginclude/cpluspluscheck index 4e09c4686b30b..87adde15ad473 100755 --- a/src/tools/pginclude/cpluspluscheck +++ b/src/tools/pginclude/cpluspluscheck @@ -198,7 +198,7 @@ do src/pl/plperl/*) EXTRAINCLUDES="$perl_includespec" ;; src/pl/plpython/*) - EXTRAINCLUDES="$python_includespec" ;; + EXTRAINCLUDES="$python_includespec"; ;; src/interfaces/ecpg/*) EXTRAINCLUDES="-I $builddir/src/interfaces/ecpg/include -I $srcdir/src/interfaces/ecpg/include" ;; src/backend/parser/*) From abb04b79aeb5ca121b2b772cb0804deeee7b65b2 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 24 Aug 2022 19:58:45 -0700 Subject: [PATCH 07/12] meson: Add LLVM bitcode emission This needs a bit more love before being ready... --- contrib/citext/meson.build | 5 +++ meson.build | 11 +++++++ src/backend/jit/llvm/bitcode/meson.build | 40 ++++++++++++++++++++++++ src/backend/jit/llvm/meson.build | 29 ++++++++++------- src/backend/meson.build | 8 +++++ src/tools/irlink | 25 +++++++++++++++ 6 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 src/backend/jit/llvm/bitcode/meson.build create mode 100644 src/tools/irlink diff --git a/contrib/citext/meson.build b/contrib/citext/meson.build index b9bc2437344ea..fe11601a7505d 100644 --- a/contrib/citext/meson.build +++ b/contrib/citext/meson.build @@ -40,3 +40,8 @@ tests += { ], }, } + +bitcode_modules += { + 'target': citext, + 'srcfiles': citext_sources, +} diff --git a/meson.build b/meson.build index b35d9c94d6485..8aa44d2350c44 100644 --- a/meson.build +++ b/meson.build @@ -769,6 +769,8 @@ if not llvmopt.disabled() ccache = find_program('ccache', native: true, required: false) clang = find_program(llvm_binpath / 'clang', required: true) + llvm_lto = find_program(llvm_binpath / 'llvm-lto', required: true) + irlink = find_program('src/tools/irlink', native: true) endif else llvm = not_found_dep @@ -2609,6 +2611,10 @@ nls_targets = [] test_deps = [] tests = [] +# List of object files + source files to generated LLVM IR for inlining. +# Each element is a hash of {'target': target, 'srcfiles': ...}. +bitcode_modules = [] + # Default options for targets @@ -2917,6 +2923,11 @@ subdir('src/interfaces/ecpg/test') subdir('doc/src/sgml') +# generate bitcode for JIT inlining after giving contrib modules etc a chance +# to add themselves to bitcode_modules[] +subdir('src/backend/jit/llvm/bitcode', if_found: llvm) + + generated_sources_ac += {'': ['GNUmakefile']} # After processing src/test, add test_install_libs to the testprep_targets diff --git a/src/backend/jit/llvm/bitcode/meson.build b/src/backend/jit/llvm/bitcode/meson.build new file mode 100644 index 0000000000000..ba45da37313f6 --- /dev/null +++ b/src/backend/jit/llvm/bitcode/meson.build @@ -0,0 +1,40 @@ +# Copyright (c) 2022-2023, PostgreSQL Global Development Group +# +# emit LLVM bitcode for JIT inlining + +assert(llvm.found()) + +foreach bitcode_module : bitcode_modules + bitcode_targets = [] + bitcode_obj = bitcode_module['target'] + if 'name' not in bitcode_module + bitcode_name = bitcode_obj.name() + else + bitcode_name = bitcode_module['name'] + endif + + foreach srcfile : bitcode_module['srcfiles'] + srcfilename = '@0@'.format(srcfile) + targetname = '@0@_@1@_@2@.bc'.format( + bitcode_name, + fs.parent(srcfilename).underscorify(), fs.name(srcfilename)) + bitcode_targets += custom_target( + targetname, + input: [srcfile, bitcode_obj.extract_objects(srcfile)], + output: targetname, + command: [llvm_irgen_command, bitcode_cflags], + install: true, + install_dir: dir_bitcode, + ) + endforeach + + index_name = '@0@.index.bc'.format(bitcode_name) + bitcode_index = custom_target('@0@'.format(bitcode_name), + output: index_name, + input: bitcode_targets, + command: [irlink, '--lto', llvm_lto, '--outdir', '@OUTDIR@', '--index', index_name, '@INPUT@'], + install: true, + install_dir: dir_bitcode, + ) + backend_targets += bitcode_index +endforeach diff --git a/src/backend/jit/llvm/meson.build b/src/backend/jit/llvm/meson.build index a6524c06fe3ef..225da839e0019 100644 --- a/src/backend/jit/llvm/meson.build +++ b/src/backend/jit/llvm/meson.build @@ -41,21 +41,20 @@ backend_targets += llvmjit # Define a few bits and pieces used here and elsewhere to generate bitcode -llvm_irgen_args = [ - '-c', '-o', '@OUTPUT@', '@INPUT@', +llvm_irgen_command = [] +if ccache.found() + llvm_irgen_command += ccache +endif + +llvm_irgen_command += [ + clang, + '-c', '-o', '@OUTPUT0@', '@INPUT0@', '-flto=thin', '-emit-llvm', - '-MD', '-MQ', '@OUTPUT@', '-MF', '@DEPFILE@', '-O2', '-Wno-ignored-attributes', '-Wno-empty-body', ] - -if ccache.found() - llvm_irgen_command = ccache - llvm_irgen_args = [clang.path()] + llvm_irgen_args -else - llvm_irgen_command = clang -endif +llvm_irgen_dep_args = ['-MD', '-MQ', '@OUTPUT0@', '-MF', '@DEPFILE@'] # XXX: Need to determine proper version of the function cflags for clang @@ -74,7 +73,7 @@ bitcode_cflags += '-I@SOURCE_ROOT@/src/include' # Note this is intentionally not installed to bitcodedir, as it's not for # inlining llvmjit_types = custom_target('llvmjit_types.bc', - command: [llvm_irgen_command] + llvm_irgen_args + bitcode_cflags, + command: llvm_irgen_command + llvm_irgen_dep_args + bitcode_cflags, input: 'llvmjit_types.c', output: 'llvmjit_types.bc', depends: [postgres], @@ -83,3 +82,11 @@ llvmjit_types = custom_target('llvmjit_types.bc', depfile: '@BASENAME@.c.bc.d', ) backend_targets += llvmjit_types + +# Figure out -I's needed to build all postgres code, including all its +# dependencies +pkg_config = find_program(['pkg-config', 'pkgconf'], required: true) +r = run_command(pkg_config, + ['--cflags-only-I', meson.build_root() / 'meson-uninstalled/postgresql-extension-uninstalled.pc'], + check: true) +bitcode_cflags += r.stdout().split() diff --git a/src/backend/meson.build b/src/backend/meson.build index e857a330fddcd..0c3f9cbb09565 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -147,6 +147,14 @@ postgres = executable('postgres', backend_targets += postgres + +bitcode_modules += { + 'name': 'postgres', + 'target': postgres_lib, + 'srcfiles': backend_sources, +} + + pg_mod_c_args = cflags_mod pg_mod_cpp_args = cxxflags_mod pg_mod_link_args = ldflags_sl + ldflags_mod diff --git a/src/tools/irlink b/src/tools/irlink new file mode 100644 index 0000000000000..c7802097ac93e --- /dev/null +++ b/src/tools/irlink @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import os +import shutil +import subprocess +import sys +import argparse + +parser = argparse.ArgumentParser( + description='generate PostgreSQL JIT IR module') + +parser.add_argument('--index', type=str, required=True) +parser.add_argument('--lto', type=str, required=True) +parser.add_argument('--outdir', type=str, required=True) +parser.add_argument('INPUT', type=str, nargs='+') + +args = parser.parse_args() + +file_names = [os.path.basename(f) for f in args.INPUT] +command = [args.lto, + '-thinlto', '-thinlto-action=thinlink', + '-o', args.index] + file_names +res = subprocess.run(command, cwd=args.outdir) + +exit(res.returncode) From 86175a684d11254890539dd7aad4ac51e1596284 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Fri, 7 Apr 2023 14:00:10 -0700 Subject: [PATCH 08/12] meson: ci: dontmerge: Add additional CI coverage This is part of the series to be able to test meson on more platforms than normally part of CI. Author: Andres Freund Author: Nazir Bilal Yavuz Author: Justin Pryzby --- .cirrus.yml | 361 +++++++++++++++++- src/tools/ci/docker/linux_centos7 | 57 +++ src/tools/ci/docker/linux_centos8 | 54 +++ src/tools/ci/docker/linux_fedora_rawhide | 49 +++ src/tools/ci/docker/linux_opensuse_tumbleweed | 56 +++ 5 files changed, 560 insertions(+), 17 deletions(-) create mode 100644 src/tools/ci/docker/linux_centos7 create mode 100644 src/tools/ci/docker/linux_centos8 create mode 100644 src/tools/ci/docker/linux_fedora_rawhide create mode 100644 src/tools/ci/docker/linux_opensuse_tumbleweed diff --git a/.cirrus.yml b/.cirrus.yml index 3db0c2458d38e..8487b36b45d41 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -221,6 +221,92 @@ task: cores_script: src/tools/ci/cores_backtrace.sh freebsd /tmp/cores +task: + depends_on: SanityCheck + + env: + CPUS: 2 + BUILD_JOBS: 3 + TEST_JOBS: 3 + + CIRRUS_WORKING_DIR: /home/postgres/postgres + CCACHE_DIR: /tmp/ccache_dir + + PATH: /usr/sbin:$PATH + + # Postgres interprets LANG as a 'en_US.UTF-8' but it is 'C', then + # Postgres tries to set 'LC_COLLATE' to 'en_US.UTF-8' but it is not + # changeable. Initdb fails because of that. So, LANG is forced to be 'C'. + LANG: "C" + LC_ALL: "C" + + matrix: + - name: NetBSD - 9 - Meson + only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*netbsd.*' + env: + IMAGE_NAME: pg-ci-netbsd-postgres-9-3 + PLATFORM: netbsd + INCLUDE_DIRS: -Dextra_lib_dirs=/usr/pkg/lib -Dextra_include_dirs=/usr/pkg/include + + - name: OpenBSD - 7 - Meson + only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*openbsd.*' + env: + IMAGE_NAME: pg-ci-openbsd-postgres-7-2 + PLATFORM: openbsd + INCLUDE_DIRS: -Dextra_include_dirs=/usr/local/include -Dextra_lib_dirs=/usr/local/lib + UUID: -Duuid=e2fs + + compute_engine_instance: + image_project: $IMAGE_PROJECT + image: family/${IMAGE_NAME} + platform: ${PLATFORM} + cpu: $CPUS + memory: 4G + disk: 25 + + sysinfo_script: | + locale + id + uname -a + ulimit -a -H && ulimit -a -S + export + + ccache_cache: + folder: $CCACHE_DIR + + create_user_script: | + useradd postgres + chown -R postgres:users /home/postgres + mkdir -p ${CCACHE_DIR} + chown -R postgres:users ${CCACHE_DIR} + + # -Duuid=bsd is not set since 'bsd' uuid option + # is not working on netBSD & openBSD. See + # https://www.postgresql.org/message-id/17358-89806e7420797025@postgresql.org + # And other uuid options are not available on netBSD + configure_script: | + su postgres <<-EOF + meson setup \ + --buildtype debug \ + -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}' + upload_caches: ccache + + test_world_script: | + su postgres <<-EOF + ulimit -c unlimited + meson test $MTEST_ARGS --num-processes ${TEST_JOBS} + EOF + + on_failure: + <<: *on_failure_meson + + # configure feature flags, shared between the task running the linux tests and # the CompilerWarnings task LINUX_CONFIGURE_FEATURES: &LINUX_CONFIGURE_FEATURES >- @@ -246,6 +332,22 @@ LINUX_MESON_FEATURES: &LINUX_MESON_FEATURES >- -Duuid=e2fs +# configure preparation scripts, shared between tasks running the linux tests +linux_preparation_scripts_template: &linux_preparation_scripts_template + sysinfo_script: | + id + uname -a + cat /proc/cmdline + ulimit -a -H && ulimit -a -S + export + create_user_script: | + useradd -m -U postgres + chown -R postgres:postgres . + mkdir -p ${CCACHE_DIR} + chown -R postgres:postgres ${CCACHE_DIR} + su postgres -c "ulimit -l -H && ulimit -l -S" + + task: env: CPUS: 4 @@ -296,19 +398,9 @@ task: ccache_cache: folder: ${CCACHE_DIR} - sysinfo_script: | - id - uname -a - cat /proc/cmdline - ulimit -a -H && ulimit -a -S - export - create_user_script: | - useradd -m postgres - chown -R postgres:postgres . - mkdir -p ${CCACHE_DIR} - chown -R postgres:postgres ${CCACHE_DIR} + set_limits_script: | echo '* - memlock 134217728' > /etc/security/limits.d/postgres.conf - su postgres -c "ulimit -l -H && ulimit -l -S" + <<: *linux_preparation_scripts_template setup_core_files_script: | mkdir -m 770 /tmp/cores chown root:postgres /tmp/cores @@ -354,7 +446,13 @@ task: on_failure: <<: *on_failure_ac - - name: Linux - Debian Bullseye - Meson + - matrix: + - name: Linux - Debian Bullseye - Meson + - name: Linux - Debian Sid - Meson + trigger_type: manual + + compute_engine_instance: + image: family/pg-ci-sid env: CCACHE_MAXSIZE: "400M" # tests two different builds @@ -381,7 +479,7 @@ task: ${LINUX_MESON_FEATURES} \ -Dllvm=disabled \ --pkg-config-path /usr/lib/i386-linux-gnu/pkgconfig/ \ - -DPERL=perl5.32-i386-linux-gnu \ + -DPERL=$(echo /usr/bin/perl*i386-linux-gnu) \ -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \ build-32 EOF @@ -416,6 +514,82 @@ task: cores_script: src/tools/ci/cores_backtrace.sh linux /tmp/cores +task: + env: + CPUS: 4 + BUILD_JOBS: 4 + TEST_JOBS: 8 # experimentally derived to be a decent choice + + CCACHE_DIR: /tmp/ccache_dir + DEBUGINFOD_URLS: ${DEBUGINFO} + + TCL_DIR: /usr/lib64/ + UUID: e2fs + + CFLAGS: "-Og -ggdb" + CXXFLAGS: "-Og -ggdb" + + LINUX_CONFIGURE_FEATURES: *LINUX_CONFIGURE_FEATURES + + depends_on: SanityCheck + only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*linux.*' + + container: + dockerfile: ${DOCKERFILE_PATH} + cpu: $CPUS + memory: 4G + + ccache_cache: + folder: ${CCACHE_DIR} + + <<: *linux_preparation_scripts_template + + matrix: + - name: Linux - OpenSuse Tumbleweed (LLVM) - Meson + env: + DOCKERFILE_PATH: src/tools/ci/docker/linux_opensuse_tumbleweed + DEBUGINFO: "https://debuginfod.opensuse.org/" + LLVM: -Dllvm=enabled + + - trigger_type: manual + matrix: + - name: Linux - Fedora Rawhide - Meson + env: + DOCKERFILE_PATH: src/tools/ci/docker/linux_fedora_rawhide + DEBUGINFO: "https://debuginfod.fedoraproject.org/" + + - name: Linux - Centos 8 - Meson + env: + DOCKERFILE_PATH: src/tools/ci/docker/linux_centos8 + DEBUGINFO: "http://debuginfo.centos.org/" + + - name: Linux - Centos 7 - Meson + env: + DOCKERFILE_PATH: src/tools/ci/docker/linux_centos7 + DEBUGINFO: "http://debuginfo.centos.org/" + + configure_script: | + su postgres <<-EOF + meson setup \ + --buildtype debug \ + -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}' + upload_caches: ccache + + test_world_script: | + su postgres <<-EOF + ulimit -c unlimited + meson test $MTEST_ARGS --num-processes ${TEST_JOBS} + EOF + + on_failure: + <<: *on_failure_meson + + task: name: macOS - Ventura - Meson @@ -535,6 +709,20 @@ WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE # Avoids port conflicts between concurrent tap test runs PG_TEST_USE_UNIX_SOCKETS: 1 PG_REGRESS_SOCK_DIR: "c:/cirrus/" + # -m enables parallelism + # verbosity:minimal + Summary reduce verbosity, while keeping a summary of + # errors/warnings + # ForceNoAlign prevents msbuild from introducing line-breaks for long lines + # disable file tracker, we're never going to rebuild, and it slows down the + # build + MSBFLAGS: -m -verbosity:minimal "-consoleLoggerParameters:Summary;ForceNoAlign" /p:TrackFileAccess=false -nologo + + # If tests hang forever, cirrus eventually times out. In that case log + # output etc is not uploaded, making the problem hard to debug. Of course + # tests internally should have shorter timeouts, but that's proven to not + # be sufficient. 15min currently is fast enough to finish individual test + # "suites". + T_C: "\"C:/Program Files/Git/usr/bin/timeout.exe\" -v -k60s 15m" sysinfo_script: | chcp @@ -542,10 +730,12 @@ WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE powershell -Command get-psdrive -psprovider filesystem set + meson_downgrade_script: | + pip install git+https://github.com/eli-schwartz/meson@vs-find_program-path task: name: Windows - Server 2019, VS 2019 - Meson & ninja - << : *WINDOWS_ENVIRONMENT_BASE + <<: *WINDOWS_ENVIRONMENT_BASE env: TEST_JOBS: 8 # wild guess, data based value welcome @@ -578,10 +768,15 @@ task: echo 127.0.0.3 pg-loadbalancetest >> c:\Windows\System32\Drivers\etc\hosts type c:\Windows\System32\Drivers\etc\hosts + meson_install_wraps_script: | + mkdir subprojects + meson wrap install lz4 + meson wrap install zlib + # Use /DEBUG:FASTLINK to avoid high memory usage during linking configure_script: | vcvarsall x64 - meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build + meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build build_script: | vcvarsall x64 @@ -599,7 +794,53 @@ task: task: - << : *WINDOWS_ENVIRONMENT_BASE + <<: *WINDOWS_ENVIRONMENT_BASE + name: Windows - Server 2019, VS 2019 - Meson & msbuild + + env: + TEST_JOBS: 8 # wild guess, data based value welcome + CIRRUS_WINDOWS_ERROR_MODE: 0x8001 + + depends_on: SanityCheck + only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*' + + compute_engine_instance: + image_project: $IMAGE_PROJECT + image: family/pg-ci-windows-ci-vs-2019 + platform: windows + cpu: $CPUS + memory: 4G + + # 1.0.1 is borked with msbuild + meson_downgrade_script: | + pip install meson!=1.0.1 + + meson_install_wraps_script: | + mkdir subprojects + meson wrap install lz4 + meson wrap install zlib + + configure_script: | + vcvarsall x64 + meson setup --buildtype debug --backend vs -Dcassert=true -Db_pch=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build + + build_script: | + vcvarsall x64 + msbuild %MSBFLAGS% build\postgresql.sln + + check_world_script: | + vcvarsall x64 + meson test %MTEST_ARGS% --num-processes %TEST_JOBS% + + on_failure: + <<: *on_failure_meson + crashlog_artifacts: + path: "crashlog-*.txt" + type: text/plain + + +task: + <<: *WINDOWS_ENVIRONMENT_BASE name: Windows - Server 2019, MinGW64 - Meson # due to resource constraints we don't run this task by default for now @@ -657,6 +898,92 @@ task: on_failure: <<: *on_failure_meson + + +task: + <<: *WINDOWS_ENVIRONMENT_BASE + name: Windows - Server 2019, VS 2019 - Homegrown + + depends_on: SanityCheck + only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*' + + env: + # Our windows infrastructure doesn't have test concurrency above the level + # of a single vcregress test target. Due to that, it's useful to run prove + # with multiple jobs. For the other tasks it isn't, because two sources + # (make and prove) of concurrency can overload machines. + # + # The concrete choice of 10 is based on a small bit of experimentation and + # likely can be improved upon further. + PROVE_FLAGS: -j10 --timer + + # Avoid re-installing over and over + NO_TEMP_INSTALL: 1 + + # startcreate_script starts a postgres instance that we don't want to get + # killed at the end of that script (it's stopped in stop_script). Can't + # trivially use background_scripts because a) need pg_ctl's dropping of + # permissions b) need to wait for startup to have finished, and we don't + # currently have a tool for that... + CIRRUS_ESCAPING_PROCESSES: 1 + + compute_engine_instance: + image_project: $IMAGE_PROJECT + image: family/pg-ci-windows-ci-vs-2019 + platform: windows + cpu: $CPUS + memory: 4G + + configure_script: + # copy errors out when using forward slashes + - copy src\tools\ci\windows_build_config.pl src\tools\msvc\config.pl + - vcvarsall x64 + - perl src/tools/msvc/mkvcbuild.pl + build_script: + - vcvarsall x64 + - msbuild %MSBFLAGS% pgsql.sln + tempinstall_script: + # Installation on windows currently only completely works from src/tools/msvc + - cd src/tools/msvc && perl install.pl %CIRRUS_WORKING_DIR%/tmp_install + + test_regress_parallel_script: | + %T_C% perl src/tools/msvc/vcregress.pl check parallel + startcreate_script: | + rem paths to binaries need backslashes + tmp_install\bin\pg_ctl.exe initdb -D tmp_check/db -l tmp_check/initdb.log --options=--no-sync + echo include '%TEMP_CONFIG%' >> tmp_check/db/postgresql.conf + tmp_install\bin\pg_ctl.exe start -D tmp_check/db -l tmp_check/postmaster.log + + test_pl_script: | + %T_C% perl src/tools/msvc/vcregress.pl plcheck + test_isolation_script: | + %T_C% perl src/tools/msvc/vcregress.pl isolationcheck + test_modules_script: | + %T_C% perl src/tools/msvc/vcregress.pl modulescheck + test_contrib_script: | + %T_C% perl src/tools/msvc/vcregress.pl contribcheck + stop_script: | + tmp_install\bin\pg_ctl.exe stop -D tmp_check/db -l tmp_check/postmaster.log + test_ssl_script: | + set with_ssl=openssl + %T_C% perl src/tools/msvc/vcregress.pl taptest ./src/test/ssl/ + test_subscription_script: | + %T_C% perl src/tools/msvc/vcregress.pl taptest ./src/test/subscription/ + test_authentication_script: | + %T_C% perl src/tools/msvc/vcregress.pl taptest ./src/test/authentication/ + test_recovery_script: | + %T_C% perl src/tools/msvc/vcregress.pl recoverycheck + test_bin_script: | + %T_C% perl src/tools/msvc/vcregress.pl bincheck + test_ecpg_script: | + rem tries to build additional stuff + vcvarsall x64 + rem References ecpg_regression.proj in the current dir + cd src/tools/msvc + %T_C% perl vcregress.pl ecpgcheck + + on_failure: + <<: *on_failure_ac crashlog_artifacts: path: "crashlog-*.txt" type: text/plain diff --git a/src/tools/ci/docker/linux_centos7 b/src/tools/ci/docker/linux_centos7 new file mode 100644 index 0000000000000..3742890d96177 --- /dev/null +++ b/src/tools/ci/docker/linux_centos7 @@ -0,0 +1,57 @@ +FROM centos:centos7 +# Enable powertools, EPEL and devtoolset repository +RUN \ + yum -y install dnf-plugins-core \ + epel-release \ + centos-release-scl-rh && \ + \ + yum -y update && \ + yum -y install \ + \ + git \ + perl \ + perl-ExtUtils-Embed \ + perl-IPC-Run \ + perl-Test-Harness \ + perl-Test-Simple \ + \ + bison \ + ccache \ + clang \ + devtoolset-7-make \ + flex \ + gcc \ + gettext \ + \ + krb5-devel \ + libicu-devel \ + libuuid-devel \ + libxml2-devel \ + libxslt-devel \ + libzstd-devel \ + lz4-devel \ + openldap-devel \ + openssl-devel \ + pam-devel \ + python3-devel \ + readline-devel \ + systemd-devel \ + tcl-devel \ + \ + krb5-server \ + krb5-server-ldap \ + krb5-workstation \ + lz4 \ + openldap-clients \ + openldap-servers \ + openssl \ + zstd \ + \ + && \ + pip3 install meson && \ + pip3 install ninja && \ + yum clean all + +# Make version is 3.82 but required is > 4, adding devtoolset-7-make to the PATH +ENV PATH="/opt/rh/devtoolset-7/root/usr/bin/:${PATH}" +ENV LANG=en_US.UTF-8 diff --git a/src/tools/ci/docker/linux_centos8 b/src/tools/ci/docker/linux_centos8 new file mode 100644 index 0000000000000..58f95847ef176 --- /dev/null +++ b/src/tools/ci/docker/linux_centos8 @@ -0,0 +1,54 @@ +FROM quay.io/centos/centos:stream8 +# Enable powertools and EPEL repository +RUN \ + dnf -y install dnf-plugins-core && \ + dnf config-manager --set-enabled powertools && \ + dnf -y install epel-release && \ + dnf -y update && \ + dnf -y install \ + \ + git \ + meson \ + perl \ + perl-IPC-Run \ + \ + bison \ + ccache \ + clang \ + diffutils \ + flex \ + gcc \ + gettext \ + \ + krb5-devel \ + libicu-devel \ + libuuid-devel \ + libxml2-devel \ + libxslt-devel \ + libzstd-devel \ + llvm-devel \ + lz4-devel \ + openldap-devel \ + openssl-devel \ + pam-devel \ + python3-devel \ + readline-devel \ + systemd-devel \ + tcl-devel \ + \ + krb5-server \ + krb5-server-ldap \ + krb5-workstation \ + lz4 \ + openldap-clients \ + openldap-servers \ + openssl \ + zstd \ + \ + glibc-langpack-en \ + \ + && \ + pip3 install ninja && \ + yum clean all + +ENV LANG=en_US.UTF-8 diff --git a/src/tools/ci/docker/linux_fedora_rawhide b/src/tools/ci/docker/linux_fedora_rawhide new file mode 100644 index 0000000000000..c95027cd6a779 --- /dev/null +++ b/src/tools/ci/docker/linux_fedora_rawhide @@ -0,0 +1,49 @@ +FROM fedora:rawhide +RUN \ + dnf -y update && \ + dnf -y install \ + git \ + meson \ + perl \ + perl-IPC-Run \ + \ + bison \ + ccache \ + clang \ + flex \ + gcc \ + gettext \ + ninja-build \ + \ + krb5-devel \ + libicu-devel \ + libuuid-devel \ + libxml2-devel \ + libxslt-devel \ + libzstd-devel \ + llvm-devel \ + lz4-devel \ + openldap-devel \ + openssl-devel \ + pam-devel \ + python3-devel \ + readline-devel \ + systemd-devel \ + tcl-devel \ + \ + krb5-server \ + krb5-server-ldap \ + krb5-workstation \ + lz4 \ + openldap-clients \ + openldap-servers \ + openssl \ + zstd \ + \ + langpacks-en \ + glibc-langpack-en \ + \ + && \ + yum clean all + +ENV LANG=en_US.UTF-8 diff --git a/src/tools/ci/docker/linux_opensuse_tumbleweed b/src/tools/ci/docker/linux_opensuse_tumbleweed new file mode 100644 index 0000000000000..07364ee85ff00 --- /dev/null +++ b/src/tools/ci/docker/linux_opensuse_tumbleweed @@ -0,0 +1,56 @@ +FROM opensuse/tumbleweed +RUN \ + zypper -n clean -a && \ + zypper -n ref && \ + zypper -n dup && \ + zypper -n update && \ + zypper -n install \ + diffutils \ + git \ + icu \ + make \ + meson \ + perl-IPC-Run \ + shadow \ + systemd-devel \ + util-linux \ + \ + bison \ + ccache \ + clang \ + flex \ + gcc \ + gcc-c++ \ + gettext-runtime \ + ninja \ + \ + krb5-devel \ + libicu-devel \ + libldapcpp-devel \ + liblz4-devel \ + libopenssl-devel \ + libselinux-devel \ + libuuid-devel \ + libxml2-devel \ + libxslt-devel \ + libzstd-devel \ + llvm-devel \ + pam-devel \ + python38-devel \ + readline-devel \ + tcl-devel \ + \ + openldap2 \ + openldap2-client \ + \ + krb5-client \ + krb5-plugin-kdb-ldap \ + krb5-server \ + lz4 \ + zstd \ + \ + && \ + zypper -n clean -a + +# Fixing ICU errors caused by locale being set to 'POSIX' +ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 From 785629d131849a556ebe77facd87d332c033f376 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sat, 11 Mar 2023 14:03:23 -0800 Subject: [PATCH 09/12] fixup! meson: ci: wip: move compilerwarnings task to meson --- .cirrus.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 8487b36b45d41..59df789b0a183 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -730,9 +730,6 @@ WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE powershell -Command get-psdrive -psprovider filesystem set - meson_downgrade_script: | - pip install git+https://github.com/eli-schwartz/meson@vs-find_program-path - task: name: Windows - Server 2019, VS 2019 - Meson & ninja <<: *WINDOWS_ENVIRONMENT_BASE From 67de4a3a346181a80f13e2ec2b1df084f6cc2d49 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 20 Mar 2023 17:36:27 -0700 Subject: [PATCH 10/12] ci: move headerscheck, cpluspluscheck to meson --- .cirrus.yml | 13 +++---------- src/meson.build | 15 ++++++--------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 59df789b0a183..8da695c4dd8b1 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1115,17 +1115,10 @@ task: ### always: headers_headerscheck_script: | - mkdir build-ac && cd build-ac - time ../configure \ - ${LINUX_CONFIGURE_FEATURES} \ - --without-icu \ - --quiet \ - CC="gcc" CXX="g++" CLANG="clang" - make -s -j${BUILD_JOBS} world-bin - time make -s headerscheck EXTRAFLAGS='-fmax-errors=10' + CC=gcc meson setup build-headerscheck -Dicu=disabled + ninja -C build-headerscheck headerscheck headers_cpluspluscheck_script: | - cd build-ac - time make -s cpluspluscheck EXTRAFLAGS='-fmax-errors=10' + ninja -C build-headerscheck cpluspluscheck always: ccache_stats_end_script: diff --git a/src/meson.build b/src/meson.build index 820fd02ffa187..c643ed672fe59 100644 --- a/src/meson.build +++ b/src/meson.build @@ -59,12 +59,9 @@ generated_sources_stamp = custom_target('generated-sources-stamp.h', command: stamp_cmd, ) -run_target('headerscheck', - command: [files('tools/pginclude/headerscheck'), '@SOURCE_ROOT@', '@BUILD_ROOT@'], - depends: [generated_sources_stamp, generated_headers_stamp, generated_backend_headers_stamp], -) - -run_target('cpluspluscheck', - command: [files('tools/pginclude/cpluspluscheck'), '@SOURCE_ROOT@', '@BUILD_ROOT@'], - depends: [generated_sources_stamp, generated_headers_stamp, generated_backend_headers_stamp], -) +foreach tgt : ['headerscheck', 'cpluspluscheck'] + run_target(tgt, + command: [files('tools/pginclude/@0@'.format(tgt)), meson.source_root(), meson.build_root()], + depends: [generated_sources_stamp, generated_headers_stamp, generated_backend_headers_stamp], + ) +endforeach From d1491d36a3cb6ca14ff55b5d1506ba35a1e7f35a Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sat, 3 Jun 2023 09:56:16 -0700 Subject: [PATCH 11/12] fixup! meson: ci: dontmerge: Add additional CI coverage --- src/tools/ci/docker/linux_opensuse_tumbleweed | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/ci/docker/linux_opensuse_tumbleweed b/src/tools/ci/docker/linux_opensuse_tumbleweed index 07364ee85ff00..a89e146c6882b 100644 --- a/src/tools/ci/docker/linux_opensuse_tumbleweed +++ b/src/tools/ci/docker/linux_opensuse_tumbleweed @@ -17,7 +17,7 @@ RUN \ \ bison \ ccache \ - clang \ + clang15 \ flex \ gcc \ gcc-c++ \ @@ -34,7 +34,7 @@ RUN \ libxml2-devel \ libxslt-devel \ libzstd-devel \ - llvm-devel \ + llvm15-devel \ pam-devel \ python38-devel \ readline-devel \ From ae9a6e1af74e4f55b430ed0186848bf0d148b406 Mon Sep 17 00:00:00 2001 From: Nazir Bilal Yavuz Date: Wed, 7 Jun 2023 11:43:23 +0300 Subject: [PATCH 12/12] meson: test extensions build by pkg-conf --- .cirrus.yml | 27 ++++++-- meson.build | 20 ++++++ src/tools/ci/test_pkg_conf | 123 +++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 src/tools/ci/test_pkg_conf diff --git a/.cirrus.yml b/.cirrus.yml index 8da695c4dd8b1..d1ec646a440a1 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -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 @@ -181,12 +182,14 @@ task: su postgres <<-EOF meson setup \ --buildtype=debug \ + --prefix=${INSTALL_DIR} \ -Dcassert=true -Duuid=bsd -Dtcl_version=tcl86 -Ddtrace=auto \ -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \ -Dextra_lib_dirs=/usr/local/lib -Dextra_include_dirs=/usr/local/include/ \ 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: | @@ -201,13 +204,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: @@ -231,6 +234,7 @@ task: CIRRUS_WORKING_DIR: /home/postgres/postgres CCACHE_DIR: /tmp/ccache_dir + INSTALL_DIR: /tmp/meson-install PATH: /usr/sbin:$PATH @@ -288,6 +292,7 @@ task: su postgres <<-EOF meson setup \ --buildtype debug \ + --prefix=${INSTALL_DIR} \ -Dcassert=true -Dssl=openssl ${UUID} \ -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \ ${INCLUDE_DIRS} \ @@ -295,6 +300,7 @@ task: 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: | @@ -355,6 +361,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 @@ -462,6 +469,7 @@ task: su postgres <<-EOF meson setup \ --buildtype=debug \ + --prefix=${INSTALL_DIR} \ -Dcassert=true \ ${LINUX_MESON_FEATURES} \ -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \ @@ -475,6 +483,7 @@ task: export CC='ccache gcc -m32' meson setup \ --buildtype=debug \ + --prefix=${INSTALL_DIR}-32 \ -Dcassert=true \ ${LINUX_MESON_FEATURES} \ -Dllvm=disabled \ @@ -486,6 +495,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 @@ -497,6 +507,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 @@ -521,6 +533,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/ @@ -572,12 +585,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: | @@ -603,6 +618,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 @@ -675,6 +691,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 \ @@ -684,6 +702,7 @@ task: build build_script: ninja -C build -j${BUILD_JOBS} + install_script: ninja -C build install upload_caches: ccache test_world_script: | diff --git a/meson.build b/meson.build index 8aa44d2350c44..bac3dec0ee6cb 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/src/tools/ci/test_pkg_conf b/src/tools/ci/test_pkg_conf new file mode 100644 index 0000000000000..fe7febaff0a6f --- /dev/null +++ b/src/tools/ci/test_pkg_conf @@ -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)