[glib: 1/2] CI: Test static build on installed glib



commit 7fa6e9e8378df1010ca664ed50fad6825ead5575
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Wed Sep 26 10:56:10 2018 -0400

    CI: Test static build on installed glib

 .gitlab-ci.yml                    | 17 ++++++++++++-
 gio/tests/meson.build             | 12 +++++++++
 gio/tests/static-link.py          | 51 +++++++++++++++++++++++++++++++++++++++
 gio/tests/static-link/app.c       |  8 ++++++
 gio/tests/static-link/meson.build |  8 ++++++
 5 files changed, 95 insertions(+), 1 deletion(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 936c97669..5738014a3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -21,12 +21,27 @@ fedora-x86_64:
   variables:
     CFLAGS: "-coverage -ftest-coverage -fprofile-arcs"
   script:
-    - meson ${MESON_COMMON_OPTIONS} --werror -Dsystemtap=true -Ddtrace=true -Dfam=true _build
+    - meson ${MESON_COMMON_OPTIONS}
+            --werror
+            --default-library=both
+            --prefix=$HOME/glib-installed
+            --libdir=lib
+            -Dsystemtap=true
+            -Ddtrace=true
+            -Dfam=true
+            -Dinstalled_tests=true
+            _build
     - ninja -C _build
     - mkdir -p _coverage
     - lcov --config-file .gitlab-ci/lcovrc --directory _build --capture --initial --output-file 
"_coverage/${CI_JOB_NAME}-baseline.lcov"
     - meson test -C _build --timeout-multiplier ${MESON_TEST_TIMEOUT_MULTIPLIER}
     - lcov --config-file .gitlab-ci/lcovrc --directory _build --capture --output-file 
"_coverage/${CI_JOB_NAME}.lcov"
+    # FIXME: We should run all installed tests, but do only this one for now
+    # because it cannot run uninstalled. Reconfigure with dtrace disabled
+    # because it breaks static link.
+    - meson configure -Ddtrace=false _build
+    - ninja -C _build install
+    - GLIB_TEST_COMPILATION=1 $HOME/glib-installed/libexec/installed-tests/glib/static-link.py 
$HOME/glib-installed/lib/pkgconfig
   artifacts:
     name: "glib-${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}"
     when: always
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index 4110c88b2..65ddcdad8 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -376,6 +376,18 @@ if installed_tests_enabled
   install_subdir('desktop-files', install_dir : installed_tests_execdir)
   install_subdir('thumbnails', install_dir : installed_tests_execdir)
   install_subdir('cert-tests', install_dir : installed_tests_execdir)
+
+  cdata = configuration_data()
+  cdata.set('installed_tests_dir', installed_tests_execdir)
+  cdata.set('program', 'static-link.py ' + glib_pkgconfigreldir)
+  configure_file(
+    input: installed_tests_template,
+    output: 'static-link.test',
+    install_dir: installed_tests_metadir,
+    configuration: cdata
+  )
+  install_subdir('static-link', install_dir : installed_tests_execdir)
+  install_data('static-link.py', install_dir : installed_tests_execdir)
 endif
 
 if not meson.is_cross_build() or meson.has_exe_wrapper()
diff --git a/gio/tests/static-link.py b/gio/tests/static-link.py
new file mode 100755
index 000000000..0af9b1af9
--- /dev/null
+++ b/gio/tests/static-link.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2018 Collabora Inc.
+#
+# 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.1 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, see <http://www.gnu.org/licenses/>.
+#
+# Author: Xavier Claessens <xavier claessens collabora com>
+
+import os
+import sys
+import tempfile
+import subprocess
+
+if not 'GLIB_TEST_COMPILATION' in os.environ:
+  print('''Test disabled because GLIB_TEST_COMPILATION is not set in the env.
+If you wish to run this test, set GLIB_TEST_COMPILATION=1 in the env,
+and make sure you have glib build dependencies installed, including
+meson.''')
+  sys.exit(0)
+
+if len(sys.argv) != 2:
+  print('Usage: {} <gio-2.0.pc dir>'.format(os.path.basename(sys.argv[0])))
+  sys.exit(1)
+
+test_dir = os.path.dirname(sys.argv[0])
+
+with tempfile.TemporaryDirectory() as builddir:
+  env = os.environ.copy()
+  env['PKG_CONFIG_PATH'] = sys.argv[1]
+  sourcedir = os.path.join(test_dir, 'static-link')
+
+  # Ensure we can static link and run a test app
+  subprocess.check_call(['meson', sourcedir, builddir], env=env)
+  subprocess.check_call(['ninja', '-C', builddir, 'test'], env=env)
+  # FIXME: This probably only works on Linux
+  out = subprocess.check_output(['ldd', os.path.join(builddir, 'test-static-link')], env=env).decode()
+  if 'libgio' in out:
+    print('test-static-link is dynamically linked on libgio')
+    exit(1)
diff --git a/gio/tests/static-link/app.c b/gio/tests/static-link/app.c
new file mode 100644
index 000000000..94baf6057
--- /dev/null
+++ b/gio/tests/static-link/app.c
@@ -0,0 +1,8 @@
+#include <gio/gio.h>
+
+int main(int argc, char *argv[])
+{
+  GApplication *app = g_application_new (NULL, 0);
+  g_object_unref (app);
+  return 0;
+}
diff --git a/gio/tests/static-link/meson.build b/gio/tests/static-link/meson.build
new file mode 100644
index 000000000..c0b638fe6
--- /dev/null
+++ b/gio/tests/static-link/meson.build
@@ -0,0 +1,8 @@
+project('test-static-link', 'c')
+
+# This is a dummy project that static links against installed gio.
+# See gio/tests/static-link.py.
+app = executable('test-static-link', 'app.c',
+  dependencies : dependency('gio-2.0', static : true)
+)
+test('test-static-link', app)


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