[meld/deprecation-cleanup: 33/48] Add scaffolding for GResource build + load support



commit df786b9bfeb9970b5c8e553d35fadf6dca24ab1a
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Dec 2 07:34:26 2018 +1000

    Add scaffolding for GResource build + load support
    
    Predictably, distutils makes this harder than you'd like. However, it's
    not that bad and it makes a bunch of resource handling code much, much
    nicer.

 bin/meld                          |  6 ++++++
 meld/build_helpers.py             | 30 ++++++++++++++++++++++++++++--
 meld/conf.py                      |  4 ++++
 meld/resources/meld.gresource.xml |  5 +++++
 4 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/bin/meld b/bin/meld
index 1199c9de..1c4aea00 100755
--- a/bin/meld
+++ b/bin/meld
@@ -222,11 +222,17 @@ def check_requirements():
 
 
 def setup_resources():
+    from gi.repository import Gio
     from gi.repository import GLib
     from gi.repository import Gtk
     from gi.repository import Gdk
     from gi.repository import GtkSource
 
+    if not uninstalled:
+        resource_file = os.path.join(meld.conf.DATADIR, "meld.gresource")
+        resources = Gio.resource_load(resource_file)
+        Gio.resources_register(resources)
+
     icon_dir = os.path.join(meld.conf.DATADIR, "icons")
     Gtk.IconTheme.get_default().append_search_path(icon_dir)
 
diff --git a/meld/build_helpers.py b/meld/build_helpers.py
index 9c2078e4..5977b3cd 100644
--- a/meld/build_helpers.py
+++ b/meld/build_helpers.py
@@ -78,6 +78,11 @@ class build_data(distutils.cmd.Command):
         ('share/meld', ['data/gschemas.compiled']),
     ]
 
+    # FIXME: This is way too much hard coding, but I really hope
+    # it also doesn't last that long.
+    resource_source = "meld/resources/meld.gresource.xml"
+    resource_target = "org.gnome.meld.gresource"
+
     def initialize_options(self):
         pass
 
@@ -85,10 +90,31 @@ class build_data(distutils.cmd.Command):
         pass
 
     def get_data_files(self):
+        data_files = []
+
+        build_path = os.path.join('build', 'data')
+        if not os.path.exists(build_path):
+            os.makedirs(build_path)
+
+        info("compiling gresources")
+        resource_dir = os.path.dirname(self.resource_source)
+        target = os.path.join(build_path, self.resource_target)
+        self.spawn([
+            "glib-compile-resources",
+            "--target={}".format(target),
+            "--sourcedir={}".format(resource_dir),
+            self.resource_source,
+        ])
+
+        data_files.append(('share/meld', [target]))
+
         if os.name == 'nt':
-            return self.frozen_gschemas
+            gschemas = self.frozen_gschemas
         else:
-            return self.gschemas
+            gschemas = self.gschemas
+        data_files.extend(gschemas)
+
+        return data_files
 
     def run(self):
         data_files = self.distribution.data_files
diff --git a/meld/conf.py b/meld/conf.py
index 504c3c6e..74fd646f 100644
--- a/meld/conf.py
+++ b/meld/conf.py
@@ -7,6 +7,7 @@ __package__ = "meld"
 __version__ = "3.19.2"
 
 APPLICATION_ID = "org.gnome.meld"
+RESOURCE_BASE = '/org/gnome/meld'
 
 # START; these paths are clobbered on install by meld.build_helpers
 DATADIR = Path(sys.prefix) / "share" / "meld"
@@ -46,6 +47,9 @@ def uninstalled():
     LOCALEDIR = melddir / "build" / "mo"
     DATADIR_IS_UNINSTALLED = True
 
+    resource_path = melddir / "meld" / "resources"
+    os.environ['G_RESOURCE_OVERLAYS'] = f'{RESOURCE_BASE}={resource_path}'
+
 
 def ui_file(filename):
     return os.path.join(DATADIR, "ui", filename)
diff --git a/meld/resources/meld.gresource.xml b/meld/resources/meld.gresource.xml
new file mode 100644
index 00000000..073851d2
--- /dev/null
+++ b/meld/resources/meld.gresource.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/meld">
+  </gresource>
+</gresources>


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