[gtk-mac-bundler] Move copying of Girs and recreating typelibs to GirFile class.



commit c7a023906ebf003cba3f31abe9d4788439ac50a2
Author: John Ralls <jralls ceridwen us>
Date:   Sun Jan 1 13:33:09 2017 -0800

    Move copying of Girs and recreating typelibs to GirFile class.

 bundler/bundler.py |   46 +++++++++++++---------------------------------
 bundler/project.py |   27 +++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 33 deletions(-)
---
diff --git a/bundler/bundler.py b/bundler/bundler.py
index b118643..40c35fe 100644
--- a/bundler/bundler.py
+++ b/bundler/bundler.py
@@ -440,39 +440,19 @@ class Bundler:
             translation.copy_target(self.project)
 
     def install_gir(self):
-        gir_files = self.project.get_gir()
-        bundle_gir_dir = self.project.get_bundle_path('Contents', 'Resources',
-                                                      'share', 'gir-1.0')
-        bundle_typelib_dir = self.project.get_bundle_path('Contents', 'Resources',
-                                                          'lib', 'girepository-1.0')
-        old_lib_path = os.path.join(self.project.get_prefix(), 'lib')
-        os.makedirs(bundle_gir_dir)
-        os.makedirs(bundle_typelib_dir)
-        import subprocess
-
-        def transform_file(filename):
-            path, fname = os.path.split(filename)
-            name, ext = os.path.splitext(fname)
-
-            with open (filename, "r") as source:
-                lines = source.readlines()
-            newpath = os.path.join(bundle_gir_dir, fname)
-            typelib = os.path.join(bundle_typelib_dir, name + '.typelib')
-            with open (newpath, "w") as target:
-                for line in lines:
-                    target.write(re.sub(old_lib_path,
-                                        '@executable_path/../Resources/lib',
-                                        line))
-            subprocess.call(['g-ir-compiler', '--output=' + typelib, newpath])
-            self.binary_paths.append(typelib)
-
-        for gir in gir_files:
-            filename = self.project.evaluate_path(gir.source)
-            for globbed_source in glob.glob(filename):
-                try:
-                    transform_file(globbed_source)
-                except Exception as err:
-                    print('Error in transformation of %s: %s' % (globbed_source, err))
+        if not self.project.get_gir():
+            return
+        gir_dest = self.project.get_bundle_path('Contents', 'Resources',
+                                                'share', 'gir-1.0')
+        typelib_dest = self.project.get_bundle_path('Contents', 'Resources',
+                                                    'lib', 'girepository-1.0')
+        lib_path = os.path.join(self.project.get_prefix(), 'lib')
+        utils.makedirs(gir_dest)
+        utils.makedirs(typelib_dest)
+
+        for gir in self.project.get_gir():
+            self.binary_paths.extend(gir.copy_target(self.project, gir_dest,
+                                                     typelib_dest, lib_path))
 
     def run(self):
         # Remove the temp location forcefully.
diff --git a/bundler/project.py b/bundler/project.py
index 1711e65..9897fd9 100644
--- a/bundler/project.py
+++ b/bundler/project.py
@@ -270,6 +270,33 @@ class Translation(Path):
 class GirFile(Path):
     def __init__(self, sourcepath, destpath, recurse):
         super(GirFile, self).__init__(sourcepath, destpath, recurse)
+        self.bundle_path = '@executable_path/../Resources/lib'
+
+    def copy_target(self, project, gir_dest, typelib_dest, lib_path):
+        import subprocess
+
+        def transform_file(filename):
+            path, fname = os.path.split(filename)
+            name, ext = os.path.splitext(fname)
+
+            with open (filename, "r") as source:
+                lines = source.readlines()
+            gir_file = os.path.join(gir_dest, fname)
+            typelib = os.path.join(typelib_dest, name + '.typelib')
+            with open (gir_file, "w") as target:
+                for line in lines:
+                    target.write(re.sub(lib_path, self.bundle_path, line))
+            subprocess.call(['g-ir-compiler', '--output=' + typelib, gir_file])
+            return typelib
+
+        filename = project.evaluate_path(self.source)
+        typelib_paths = []
+        for globbed_source in glob.glob(filename):
+            try:
+                typelib_paths.append(transform_file(globbed_source))
+            except Exception as err:
+                print('Error in transformation of %s: %s' % (globbed_source, err))
+        return typelib_paths
 
 class Data(Path):
     pass


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