[file-roller/wip/jtojnar/api_docs: 9/10] introspection: Allow building without schemas installed and outside X server




commit b75fb19279852a6e82133f5de097a877eb5b4ce2
Author: Jan Tojnar <jtojnar gmail com>
Date:   Mon May 16 01:18:32 2022 +0200

    introspection: Allow building without schemas installed and outside X server
    
    Many classes bind GSettings in constructors so they need access to schemas.
    Unfortunately, it does not appear to be possible to pass `GSETTINGS_SCHEMA_DIR`
    environment variable to `g-ir-scanner` executed by `gnome.generate_gir`
    using any reasonable method so we need this chain of hacks.
    
    Similarly, some classes require DISPLAY environment variable,
    so we need it running under xvfb-run.

 build-aux/introspection-wrapper.sh.in |  4 ++++
 data/meson.build                      | 13 ++++++++++++-
 default.nix                           | 10 ++++++++++
 src/meson.build                       | 21 +++++++++++++++++++++
 4 files changed, 47 insertions(+), 1 deletion(-)
---
diff --git a/build-aux/introspection-wrapper.sh.in b/build-aux/introspection-wrapper.sh.in
new file mode 100755
index 00000000..79eaf2c6
--- /dev/null
+++ b/build-aux/introspection-wrapper.sh.in
@@ -0,0 +1,4 @@
+#!/bin/sh
+env "GSETTINGS_SCHEMA_DIR=@settings_schema_compiled_dir@" \
+  @xvfb_run@ -s '-screen 0 800x600x24' \
+    "$@"
diff --git a/data/meson.build b/data/meson.build
index 54adbd86..34bc0bb3 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,9 +1,20 @@
 po_dir = join_paths(meson.project_source_root(), 'po')
 
-install_data('org.gnome.FileRoller.gschema.xml',
+settings_schema_compiled_dir = meson.current_build_dir()
+
+settings_schema = 'org.gnome.FileRoller.gschema.xml'
+install_data(
+  settings_schema,
   install_dir : join_paths(datadir, 'glib-2.0', 'schemas')
 )
 
+# Required by gobject-introspection.
+compiled_schemas = gnome.compile_schemas(
+  depend_files: [
+    settings_schema,
+  ],
+)
+
 install_data('packages.match',
   install_dir : join_paths(datadir, meson.project_name())
 )
diff --git a/default.nix b/default.nix
index 340dff8a..322f6962 100644
--- a/default.nix
+++ b/default.nix
@@ -97,6 +97,8 @@ makeDerivation rec {
     ninja
     pkg-config
     wrapGAppsHook
+    # Building introspection requires DISPLAY environment variable.
+    xvfb-run
   ] ++ lib.optionals shell [
     niv
   ];
@@ -116,4 +118,12 @@ makeDerivation rec {
   ];
 
   inherit doCheck;
+
+  preBuild = ''
+    # Some introspected classes bind GSettings in constructors
+    # so Gio will try to check settings in the HOME directory.
+    # By default, Nix sandbox points $HOME to non-existent directory
+    # so we need to create it.
+    export HOME="$(mktemp -d)"
+  '';
 }
diff --git a/src/meson.build b/src/meson.build
index ac6e2b3e..16af55f9 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -146,11 +146,32 @@ fr_exe = executable('file-roller',
 )
 
 if build_introspection
+  xvfb_run = find_program('xvfb-run')
+
+  introspection_wrapper = configure_file(
+    input: meson.project_source_root() / 'build-aux/introspection-wrapper.sh.in',
+    output: 'introspection-wrapper.sh',
+    configuration: {
+      'settings_schema_compiled_dir': settings_schema_compiled_dir,
+      'xvfb_run': xvfb_run.path(),
+    },
+  )
+
+  # HACK: Cannot pass File object to extra_args of fr_gir so we need to convert it to string first.
+  introspection_wrapper_path = run_command('echo', introspection_wrapper).stdout().strip()
+
   fr_gir = gnome.generate_gir(
     fr_exe,
     sources: [
       source_files,
       fr_headers,
+      # HACK: We need to ensure that schemas are compiled and there is no depends kwarg.
+      compiled_schemas,
+    ],
+    extra_args: [
+      # Constructors bind to GSettings so we need to have access to schemas.
+      # HACK: Cannot set environment variables for running g-ir-scanner so abusing binary wrapper.
+      f'--use-binary-wrapper=@introspection_wrapper_path@',
     ],
     namespace: 'FileRoller',
     nsversion: '1.0',


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