[gtk-mac-bundler] Make pango modules related code optional to fix build with pango 1.38



commit 5a348d5a9405c958ee0e85fb0af58a8dc0dd999c
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Wed Feb 24 18:40:44 2016 +0100

    Make pango modules related code optional to fix build with pango 1.38
    
    pango 1.38 no longer builds separate modules and has removed the
    "pango_module_version" pkg-config var. This makes the pango
    bundle code optional depending on the presence of the modules and
    adds an error message to help users update their bundle xml file
    in case a newer pango is present.

 bundler/bundler.py        |    6 ++++++
 bundler/main.py           |    6 ++++--
 bundler/utils.py          |   26 ++++++++++++++++++++++++++
 examples/gtk-demo.bundle  |    2 ++
 examples/gtk3-demo.bundle |    2 ++
 examples/gtk3-launcher.sh |    2 ++
 6 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/bundler/bundler.py b/bundler/bundler.py
index ebbe870..65b8cc0 100644
--- a/bundler/bundler.py
+++ b/bundler/bundler.py
@@ -68,6 +68,12 @@ class Bundler:
         self.copy_path(path)
 
     def create_pango_setup(self):
+        if utils.has_pkgconfig_module("pango") and \
+                not utils.has_pkgconfig_variable("pango", "pango_module_version"):
+            # Newer pango (>= 1.38) no longer has modules, skip this
+            # step in that case.
+            return
+
         # Create a temporary pangorc file just for creating the
         # modules file with the right modules.
         module_version = utils.evaluate_pkgconfig_variables("${pkg:pango:pango_module_version}")
diff --git a/bundler/main.py b/bundler/main.py
index 6afc2b0..b9b2fc5 100644
--- a/bundler/main.py
+++ b/bundler/main.py
@@ -14,5 +14,7 @@ def main(argv):
 
     project = Project(argv[0])
     bundler = Bundler(project)
-
-    bundler.run()
+    try:
+        bundler.run()
+    except Exception as err:
+        print("Bundler encountered an error %s" % str(err))
diff --git a/bundler/utils.py b/bundler/utils.py
index 304aedf..76c83d1 100644
--- a/bundler/utils.py
+++ b/bundler/utils.py
@@ -15,6 +15,21 @@ def evaluate_environment_variables(string):
 
     return string
 
+def has_pkgconfig_module(module):
+    """Returns True if the pkg-config module exists"""
+    f = os.popen("pkg-config --exists " + module)
+    f.read().strip()
+    return f.close() is None
+
+def has_pkgconfig_variable(module, key):
+    """Returns True if the pkg-config variable exists for the given
+    module
+    """
+    f = os.popen("pkg-config --variable=" + key + " " + module)
+    status = bool(f.read().strip())
+    f.close()
+    return status
+
 def evaluate_pkgconfig_variables(string):
     p = re.compile("\${pkg:(.*?):(.*?)}")
     m = p.search(string)
@@ -24,6 +39,17 @@ def evaluate_pkgconfig_variables(string):
         f = os.popen("pkg-config --variable=" + key + " " + module)
         value = f.read().strip()
         if not value:
+            # pango 1.38 removed modules, try to give a helpful
+            # message in case something tries to reference the no
+            # longer existing variable (most likely from old bundle
+            # xml files) when using a newer pango build.
+            if module == "pango" and key == "pango_module_version":
+                if has_pkgconfig_module("pango"):
+                    raise Exception(
+                        "'%s' got removed in '%s' "
+                        "1.38. Remove any reference to pango "
+                        "modules in your bundle xml." % (
+                            key, module))
             raise Exception("pkg-config variable '%s %s' is undefined" % (key, module))
         string = p.sub(value, string, 1)
         m = p.search(string)
diff --git a/examples/gtk-demo.bundle b/examples/gtk-demo.bundle
index 4b32d6b..422126e 100644
--- a/examples/gtk-demo.bundle
+++ b/examples/gtk-demo.bundle
@@ -79,9 +79,11 @@
     ${prefix}/lib/gdk-pixbuf-2.0/${pkg:${gtk}:gtk_binary_version}/loaders/*.so
   </binary>
 
+<!-- No longer needed for pango >= 1.38
    <binary>
     ${prefix}/lib/pango/${pkg:pango:pango_module_version}/modules/
   </binary>
+-->
 
   <data>
     ${prefix}/etc/pango/
diff --git a/examples/gtk3-demo.bundle b/examples/gtk3-demo.bundle
index 13e372a..ec0eb4c 100644
--- a/examples/gtk3-demo.bundle
+++ b/examples/gtk3-demo.bundle
@@ -69,9 +69,11 @@
     ${prefix}/lib/gdk-pixbuf-2.0/${pkg:gdk-pixbuf-2.0:gdk_pixbuf_binary_version}/loaders/*.so
   </binary>
 
+<!-- No longer needed for pango >= 1.38
   <binary>
     ${prefix}/lib/pango/${pkg:pango:pango_module_version}/modules/
   </binary>
+-->
 
   <!-- Translation filenames, one for each program or library that you
        want to copy in to the bundle. The "dest" attribute is
diff --git a/examples/gtk3-launcher.sh b/examples/gtk3-launcher.sh
index de9bb10..9137ccb 100755
--- a/examples/gtk3-launcher.sh
+++ b/examples/gtk3-launcher.sh
@@ -29,9 +29,11 @@ export GTK_DATA_PREFIX="$bundle_res"
 export GTK_EXE_PREFIX="$bundle_res"
 export GTK_PATH="$bundle_res"
 
+# PANGO_* is no longer needed for pango >= 1.38
 export PANGO_RC_FILE="$bundle_etc/pango/pangorc"
 export PANGO_SYSCONFDIR="$bundle_etc"
 export PANGO_LIBDIR="$bundle_lib"
+
 export GDK_PIXBUF_MODULE_FILE="$bundle_lib/gdk-pixbuf-2.0/2.10.0/loaders.cache"
 if [ `uname -r | cut -d . -f 1` -ge 10 ]; then
     export GTK_IM_MODULE_FILE="$bundle_etc/gtk-3.0/gtk.immodules"


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