Merge branch 'wip/smcv/subproject' into 'master'

Improve Meson subproject support

See merge request GNOME/libglnx!34
This commit is contained in:
Phaedrus Leeds
2022-05-10 17:34:21 +00:00
12 changed files with 148 additions and 26 deletions

View File

@@ -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}"

View File

@@ -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:

View File

@@ -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)

9
meson_options.txt Normal file
View File

@@ -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',
)

View File

@@ -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

5
tests/use-as-subproject/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
# Copyright 2022 Collabora Ltd.
# SPDX-License-Identifier: LGPL-2.0-or-later
/_build/
/subprojects/

View File

@@ -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
-->

View File

@@ -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

View File

@@ -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

View File

@@ -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])

View File

@@ -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;
}

View File

@@ -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;
}