[libglnx/wip/smcv/subproject: 4/4] tests: Verify libglnx can work as a subproject




commit 856ee533ba3dbabddf36688544327de34684fb78
Author: Simon McVittie <smcv collabora com>
Date:   Thu Apr 21 18:33:34 2022 +0100

    tests: Verify libglnx can work as a subproject
    
    What isn't tested usually doesn't work, and the only way to use libglnx
    is as a subproject, so test it like that.
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 .gitlab-ci.yml                            | 17 ++++++++++++-----
 tests/use-as-subproject/.gitignore        |  5 +++++
 tests/use-as-subproject/README            |  8 ++++++++
 tests/use-as-subproject/config.h          |  6 ++++++
 tests/use-as-subproject/dummy-config.h.in |  6 ++++++
 tests/use-as-subproject/meson.build       | 24 ++++++++++++++++++++++++
 tests/use-as-subproject/use-libglnx.c     | 16 ++++++++++++++++
 tests/use-as-subproject/use-testlib.c     | 16 ++++++++++++++++
 8 files changed, 93 insertions(+), 5 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 29de882..f266da3 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)"
 
 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 -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/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..9df4b09
--- /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(
+  output : 'config.h',
+  input : 'dummy-config.h.in',
+  configuration : configuration_data(),
+)
+
+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..2cc5408
--- /dev/null
+++ b/tests/use-as-subproject/use-testlib.c
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2022 Collabora Ltd.
+ * SPDX-License-Identifier: LGPL-2.0-or-later
+ */
+
+#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;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]