diff options
-rw-r--r-- | .gitlab-ci.yml | 17 | ||||
-rw-r--r-- | glnx-fdio.h | 2 | ||||
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | meson_options.txt | 9 | ||||
-rw-r--r-- | tests/meson.build | 62 | ||||
-rw-r--r-- | tests/use-as-subproject/.gitignore | 5 | ||||
-rw-r--r-- | tests/use-as-subproject/README | 8 | ||||
-rw-r--r-- | tests/use-as-subproject/config.h | 6 | ||||
-rw-r--r-- | tests/use-as-subproject/dummy-config.h.in | 6 | ||||
-rw-r--r-- | tests/use-as-subproject/meson.build | 24 | ||||
-rw-r--r-- | tests/use-as-subproject/use-libglnx.c | 16 | ||||
-rw-r--r-- | tests/use-as-subproject/use-testlib.c | 17 |
12 files changed, 148 insertions, 26 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 29de882..d9e465a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,17 +7,24 @@ stages: - build before_script: - - dnf install -y gcc meson ninja-build "pkgconfig(gio-2.0)" "pkgconfig(gio-unix-2.0)" "pkgconfig(glib-2.0)" + - dnf install -y gcc git meson ninja-build "pkgconfig(gio-2.0)" "pkgconfig(gio-unix-2.0)" "pkgconfig(glib-2.0)" xz build: stage: build script: - meson _build . - - cd _build - - ninja - - meson test + - ninja -C _build + - meson test -C _build # Run it again! This previously did not work. - - meson test + - meson test -C _build + # Ensure that we can build as a subproject + - rm -fr _build/meson-dist + - meson dist -C _build + - mkdir -p tests/use-as-subproject/subprojects/libglnx + - tar --strip-components=1 -C tests/use-as-subproject/subprojects/libglnx -xf _build/meson-dist/*.tar.xz + - meson tests/use-as-subproject/_build tests/use-as-subproject + - ninja -C tests/use-as-subproject/_build + - meson test -C tests/use-as-subproject/_build artifacts: when: on_failure name: "libglnx-${CI_COMMIT_REF_NAME}-${CI_JOB_NAME}" diff --git a/glnx-fdio.h b/glnx-fdio.h index b6ba0ea..af53479 100644 --- a/glnx-fdio.h +++ b/glnx-fdio.h @@ -209,6 +209,7 @@ int glnx_renameat2_noreplace (int olddirfd, const char *oldpath, int glnx_renameat2_exchange (int olddirfd, const char *oldpath, int newdirfd, const char *newpath); +#ifdef _GNU_SOURCE /** * glnx_try_fallocate: * @fd: File descriptor @@ -240,6 +241,7 @@ glnx_try_fallocate (int fd, return TRUE; } +#endif /** * glnx_fstat: diff --git a/meson.build b/meson.build index 6714dc2..f3dc8a4 100644 --- a/meson.build +++ b/meson.build @@ -83,9 +83,11 @@ libglnx_sources = [ libglnx = static_library('glnx', libglnx_sources, dependencies : libglnx_deps, + gnu_symbol_visibility : 'hidden', include_directories : libglnx_inc, install : false) libglnx_dep = declare_dependency( + dependencies : libglnx_deps, include_directories : libglnx_inc, link_with : libglnx) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..1028017 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,9 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: LGPL-2.0-or-later + +option( + 'tests', + type : 'boolean', + description : 'build and run unit tests', + value : 'true', +) diff --git a/tests/meson.build b/tests/meson.build index 2ad8c44..2c38ab0 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -2,25 +2,45 @@ # Copyright 2019 Collabora Ltd. # SPDX-License-Identifier: LGPL-2.1-or-later -test_names = [ - 'errors', - 'fdio', - 'macros', - 'shutil', - 'xattrs', -] +libglnx_testlib = static_library( + 'glnx-testlib', + 'libglnx-testlib.c', + 'libglnx-testlib.h', + dependencies : [ + libglnx_dep, + libglnx_deps, + ], + install : false, +) +libglnx_testlib_dep = declare_dependency( + dependencies : [ + libglnx_dep, + libglnx_deps, + ], + include_directories : include_directories('.'), + link_with : libglnx_testlib, +) -foreach test_name : test_names - exe = executable(test_name, - [ - 'libglnx-testlib.c', - 'libglnx-testlib.h', - 'test-libglnx-' + test_name + '.c', - ], - dependencies: [ - libglnx_dep, - libglnx_deps, - ], - ) - test(test_name, exe) -endforeach +if get_option('tests') + test_names = [ + 'errors', + 'fdio', + 'macros', + 'shutil', + 'xattrs', + ] + + foreach test_name : test_names + exe = executable(test_name, + [ + 'test-libglnx-' + test_name + '.c', + ], + dependencies: [ + libglnx_dep, + libglnx_deps, + libglnx_testlib_dep, + ], + ) + test(test_name, exe) + endforeach +endif diff --git a/tests/use-as-subproject/.gitignore b/tests/use-as-subproject/.gitignore new file mode 100644 index 0000000..ec6149f --- /dev/null +++ b/tests/use-as-subproject/.gitignore @@ -0,0 +1,5 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: LGPL-2.0-or-later + +/_build/ +/subprojects/ diff --git a/tests/use-as-subproject/README b/tests/use-as-subproject/README new file mode 100644 index 0000000..cc43a09 --- /dev/null +++ b/tests/use-as-subproject/README @@ -0,0 +1,8 @@ +This is a simple example of a project that uses libglnx as a subproject. +The intention is that if this project can successfully build and use libglnx +as a subproject, then so could Flatpak. + +<!-- +Copyright 2022 Collabora Ltd. +SPDX-License-Identifier: LGPL-2.0-or-later +--> diff --git a/tests/use-as-subproject/config.h b/tests/use-as-subproject/config.h new file mode 100644 index 0000000..dffc647 --- /dev/null +++ b/tests/use-as-subproject/config.h @@ -0,0 +1,6 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#error Should not use superproject config.h to compile libglnx diff --git a/tests/use-as-subproject/dummy-config.h.in b/tests/use-as-subproject/dummy-config.h.in new file mode 100644 index 0000000..bffb52a --- /dev/null +++ b/tests/use-as-subproject/dummy-config.h.in @@ -0,0 +1,6 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#error Should not use superproject generated config.h to compile libglnx diff --git a/tests/use-as-subproject/meson.build b/tests/use-as-subproject/meson.build new file mode 100644 index 0000000..2d08160 --- /dev/null +++ b/tests/use-as-subproject/meson.build @@ -0,0 +1,24 @@ +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: LGPL-2.0-or-later + +project( + 'use-libglnx-as-subproject', + 'c', + version : '0', + meson_version : '>=0.49.0', +) + +configure_file( + copy : true, + input : 'dummy-config.h.in', + output : 'config.h', +) + +glib_dep = dependency('glib-2.0') + +libglnx = subproject('libglnx') +libglnx_dep = libglnx.get_variable('libglnx_dep') +libglnx_testlib_dep = libglnx.get_variable('libglnx_testlib_dep') + +executable('use-libglnx', 'use-libglnx.c', dependencies : [libglnx_dep, glib_dep]) +executable('use-testlib', 'use-testlib.c', dependencies : [libglnx_testlib_dep, glib_dep]) diff --git a/tests/use-as-subproject/use-libglnx.c b/tests/use-as-subproject/use-libglnx.c new file mode 100644 index 0000000..0e14db0 --- /dev/null +++ b/tests/use-as-subproject/use-libglnx.c @@ -0,0 +1,16 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#include <libglnx.h> + +int +main (void) +{ + GError *error = NULL; + + glnx_throw (&error, "whatever"); + g_clear_error (&error); + return 0; +} diff --git a/tests/use-as-subproject/use-testlib.c b/tests/use-as-subproject/use-testlib.c new file mode 100644 index 0000000..9a955b4 --- /dev/null +++ b/tests/use-as-subproject/use-testlib.c @@ -0,0 +1,17 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#include <libglnx.h> +#include <libglnx-testlib.h> + +int +main (void) +{ + _GLNX_TEST_DECLARE_ERROR (local_error, error); + + glnx_throw (error, "Whatever"); + g_clear_error (&local_error); + return 0; +} |