summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2019-10-11 11:57:33 +0000
committerColin Walters <walters@verbum.org>2019-10-11 11:57:33 +0000
commit41ecc5441f573b9b06d8dd360313e78047c11c45 (patch)
tree51ccb545b85b5f6c366bac3fe46c306cb4dfa967
parent2eeb8a7512be6755307cb21ccde4384016c6771f (diff)
parent4fca08e26808824b1f2a9866968eb245ce1da603 (diff)
downloadlibglnx-41ecc5441f573b9b06d8dd360313e78047c11c45.tar.gz
Merge branch 'meson-older-compilers' into 'master'
Add Meson build system and Gitlab-CI See merge request GNOME/libglnx!8
-rw-r--r--.gitlab-ci.yml22
-rw-r--r--README.md26
-rw-r--r--meson.build84
-rw-r--r--tests/libglnx-testlib.c66
-rw-r--r--tests/libglnx-testlib.h14
-rw-r--r--tests/meson.build23
-rw-r--r--tests/test-libglnx-fdio.c1
7 files changed, 236 insertions, 0 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..36638d7
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,22 @@
+image: registry.fedoraproject.org/fedora:30
+
+stages:
+ - build
+
+before_script:
+ - dnf install -y gcc meson ninja-build "pkgconfig(gio-2.0)" "pkgconfig(gio-unix-2.0)" "pkgconfig(glib-2.0)"
+
+build:
+ stage: build
+ script:
+ - meson _build .
+ - cd _build
+ - ninja
+ - meson test
+ # Run it again! This previously did not work.
+ - meson test
+ artifacts:
+ when: on_failure
+ name: "libglnx-${CI_COMMIT_REF_NAME}-${CI_JOB_NAME}"
+ paths:
+ - "${CI_PROJECT_DIR}/_build/meson-logs"
diff --git a/README.md b/README.md
index 6589d29..3be38d7 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,32 @@ One could also compare this project to gnulib; the salient differences
there are that at least some of this module is eventually destined for
inclusion in GLib.
+Adding this to your project
+---------------------------
+
+## Meson
+
+First, set up a Git submodule:
+
+```
+git submodule add https://gitlab.gnome.org/GNOME/libglnx subprojects/libglnx
+```
+
+Or a Git [subtree](https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt):
+
+```
+git remote add libglnx https://gitlab.gnome.org/GNOME/libglnx.git
+git fetch libglnx
+git subtree add -P subprojects/libglnx libglnx/master
+```
+
+Then, in your top-level `meson.build`:
+
+```
+libglnx_dep = subproject('libglnx').get_variable('libglnx_dep')
+# now use libglnx_dep in your dependencies
+```
+
Porting from libgsystem
-----------------------
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..74ee36a
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,84 @@
+project('libglnx', 'c')
+
+add_project_arguments('-D_GNU_SOURCE', language: 'c')
+add_project_arguments('-std=gnu99', language: 'c')
+add_project_arguments('-Wno-unused-local-typedefs', language: 'c')
+
+cc = meson.get_compiler('c')
+
+
+check_functions = [
+ 'renameat2',
+ 'memfd_create',
+ 'copy_file_range',
+]
+conf = configuration_data()
+foreach check_function : check_functions
+ have_it = cc.compiles('''
+ #include <sys/types.h>
+ #include <unistd.h>
+ #include <stdio.h>
+ #include <sys/mount.h>
+ #include <fcntl.h>
+ #include <sched.h>
+ #include <linux/loop.h>
+ #include <linux/random.h>
+ #include <sys/mman.h>
+
+ int func (void) {
+ (void) ''' + check_function + ''';
+ }
+ ''',
+ args : '-D_GNU_SOURCE',
+ name : check_function + '() is declared',
+ )
+ conf.set10('HAVE_DECL_' + check_function.underscorify().to_upper(), have_it)
+endforeach
+config_h = configure_file(
+ output : 'config.h',
+ configuration : conf,
+)
+
+libglnx_deps = [
+ dependency('gio-2.0'),
+ dependency('gio-unix-2.0'),
+]
+libglnx_inc = include_directories('.')
+libglnx_sources = [
+ 'glnx-backport-autocleanups.h',
+ 'glnx-backport-autoptr.h',
+ 'glnx-backports.c',
+ 'glnx-backports.h',
+ 'glnx-console.c',
+ 'glnx-console.h',
+ 'glnx-dirfd.c',
+ 'glnx-dirfd.h',
+ 'glnx-errors.c',
+ 'glnx-errors.h',
+ 'glnx-fdio.c',
+ 'glnx-fdio.h',
+ 'glnx-local-alloc.c',
+ 'glnx-local-alloc.h',
+ 'glnx-lockfile.c',
+ 'glnx-lockfile.h',
+ 'glnx-macros.h',
+ 'glnx-missing.h',
+ 'glnx-missing-syscall.h',
+ 'glnx-shutil.c',
+ 'glnx-shutil.h',
+ 'glnx-xattrs.c',
+ 'glnx-xattrs.h',
+ 'libglnx.h',
+]
+
+libglnx = static_library('glnx',
+ libglnx_sources,
+ dependencies : libglnx_deps,
+ include_directories : libglnx_inc,
+ install : false)
+libglnx_dep = declare_dependency(
+ include_directories : libglnx_inc,
+ link_with : libglnx)
+
+subdir('tests')
+
diff --git a/tests/libglnx-testlib.c b/tests/libglnx-testlib.c
new file mode 100644
index 0000000..5687d80
--- /dev/null
+++ b/tests/libglnx-testlib.c
@@ -0,0 +1,66 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright 2019 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "libglnx-testlib.h"
+
+#include <errno.h>
+
+#include "libglnx.h"
+
+struct _GLnxTestAutoTempDir
+{
+ gchar *old_cwd;
+ int old_cwd_fd;
+ GLnxTmpDir temp_dir;
+};
+
+_GLnxTestAutoTempDir *
+_glnx_test_auto_temp_dir_enter (void)
+{
+ GError *error = NULL;
+ _GLnxTestAutoTempDir *ret = g_new0 (_GLnxTestAutoTempDir, 1);
+
+ glnx_mkdtemp ("glnx-test-XXXXXX", 0700, &ret->temp_dir, &error);
+ g_assert_no_error (error);
+
+ /* just for better diagnostics */
+ ret->old_cwd = g_get_current_dir ();
+
+ glnx_opendirat (-1, ".", TRUE, &ret->old_cwd_fd, &error);
+ g_assert_no_error (error);
+
+ if (fchdir (ret->temp_dir.fd) != 0)
+ g_error ("fchdir(<fd for \"%s\">): %s", ret->temp_dir.path, g_strerror (errno));
+
+ return ret;
+}
+
+void
+_glnx_test_auto_temp_dir_leave (_GLnxTestAutoTempDir *dir)
+{
+ GError *error = NULL;
+
+ if (fchdir (dir->old_cwd_fd) != 0)
+ g_error ("fchdir(<fd for \"%s\">): %s", dir->old_cwd, g_strerror (errno));
+
+ glnx_tmpdir_delete (&dir->temp_dir, NULL, &error);
+ g_assert_no_error (error);
+}
diff --git a/tests/libglnx-testlib.h b/tests/libglnx-testlib.h
index ee750e4..0d3a075 100644
--- a/tests/libglnx-testlib.h
+++ b/tests/libglnx-testlib.h
@@ -1,6 +1,7 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2017 Red Hat, Inc.
+ * Copyright 2019 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,10 @@
#pragma once
+#include <glib.h>
+
+#include "glnx-backport-autoptr.h"
+
typedef GError _GLnxTestAutoError;
static inline void
_glnx_test_auto_error_cleanup (_GLnxTestAutoError *autoerror)
@@ -32,3 +37,12 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(_GLnxTestAutoError, _glnx_test_auto_error_cleanup)
#define _GLNX_TEST_DECLARE_ERROR(local_error, error) \
g_autoptr(_GLnxTestAutoError) local_error = NULL; \
GError **error = &local_error
+
+typedef struct _GLnxTestAutoTempDir _GLnxTestAutoTempDir;
+
+_GLnxTestAutoTempDir *_glnx_test_auto_temp_dir_enter (void);
+void _glnx_test_auto_temp_dir_leave (_GLnxTestAutoTempDir *dir);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(_GLnxTestAutoTempDir, _glnx_test_auto_temp_dir_leave);
+
+#define _GLNX_TEST_SCOPED_TEMP_DIR \
+ g_autoptr(_GLnxTestAutoTempDir) temp_dir = _glnx_test_auto_temp_dir_enter ()
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..de141c5
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,23 @@
+
+test_names = [
+ 'errors',
+ 'fdio',
+ 'macros',
+ 'shutil',
+ 'xattrs',
+]
+
+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
diff --git a/tests/test-libglnx-fdio.c b/tests/test-libglnx-fdio.c
index 81636e5..84ebb14 100644
--- a/tests/test-libglnx-fdio.c
+++ b/tests/test-libglnx-fdio.c
@@ -237,6 +237,7 @@ test_filecopy (void)
int main (int argc, char **argv)
{
+ _GLNX_TEST_SCOPED_TEMP_DIR;
int ret;
g_test_init (&argc, &argv, NULL);