Use mesonintrospect to set library path
authorThibault Saunier <thibault.saunier@osg.samsung.com>
Sat, 19 Nov 2016 21:01:44 +0000 (18:01 -0300)
committerThibault Saunier <tsaunier@gnome.org>
Tue, 13 Dec 2016 15:58:31 +0000 (12:58 -0300)
this way the uninstalled target can be used before the libraries are built

https://bugzilla.gnome.org/show_bug.cgi?id=775281

common.py
gst-uninstalled.py
setup

index 40f420e..8c8b55d 100644 (file)
--- a/common.py
+++ b/common.py
@@ -1,7 +1,12 @@
 import argparse
+import os
 import shutil
 import subprocess
 
+
+ROOTDIR = os.path.abspath(os.path.dirname(__file__))
+
+
 class Colors:
     HEADER = '\033[95m'
     OKBLUE = '\033[94m'
@@ -47,3 +52,13 @@ def accept_command(commands):
             return command
 
     return None
+
+def get_meson():
+    meson = os.path.join(ROOTDIR, 'meson', 'meson.py')
+    if os.path.exists(meson):
+        mesonconf = os.path.join(ROOTDIR, 'meson', 'mesonconf.py')
+        mesonintrospect = os.path.join(ROOTDIR, 'meson', 'mesonintrospect.py')
+        return meson, mesonconf, mesonintrospect
+
+    return accept_command(["meson.py", "meson"]), accept_command(["mesonconf.py", "mesonconf"]), \
+        accept_command(["mesonintrospect.py", "mesonintrospect"])
index 14778f7..890ab51 100755 (executable)
@@ -1,13 +1,16 @@
 #!/usr/bin/env python3
 
 import argparse
+import json
 import os
+import platform
 import re
 import site
 import shutil
 import subprocess
 import tempfile
 
+from common import get_meson
 
 SCRIPTDIR = os.path.abspath(os.path.dirname(__file__))
 
@@ -59,7 +62,7 @@ def get_subprocess_env(options):
     env["GST_REGISTRY"] = os.path.normpath(options.builddir + "/registry.dat")
 
     filename = "meson.build"
-    sharedlib_reg = re.compile(r'\.so$|\.dylib$|\.dll$')
+    sharedlib_reg = re.compile(r'\.so|\.dylib|\.dll')
     typelib_reg = re.compile(r'.*\.typelib$')
 
     if os.name is 'nt':
@@ -69,23 +72,24 @@ def get_subprocess_env(options):
     else:
         lib_path_envvar = 'LD_LIBRARY_PATH'
 
-    for root, dirnames, filenames in os.walk(os.path.join(options.builddir,
-                                                          'subprojects')):
-        has_typelib = False
-        has_shared = False
-        for filename in filenames:
-            if typelib_reg.search(filename) and not has_typelib:
-                has_typelib = True
-                prepend_env_var(env, "GI_TYPELIB_PATH",
-                                os.path.join(options.builddir, root))
-                if has_shared:
-                    break
-            elif sharedlib_reg.search(filename) and not has_shared:
-                has_shared = True
-                prepend_env_var(env, lib_path_envvar,
-                                os.path.join(options.builddir, root))
-                if has_typelib:
-                    break
+    meson, mesonconf, mesonintrospect = get_meson()
+    targets_s = subprocess.check_output([mesonintrospect, options.builddir, '--targets'])
+    targets = json.loads(targets_s.decode())
+    for target in targets:
+        filename = target['filename']
+        root = os.path.dirname(filename)
+        if typelib_reg.search(filename):
+            prepend_env_var(env, "GI_TYPELIB_PATH",
+                            os.path.join(options.builddir, root))
+        elif sharedlib_reg.search(filename):
+            if target.get('type') != "shared library":
+                continue
+
+            if "lib/gstreamer-1.0" in os.path.normpath(target.get('install_filename')):
+                continue
+
+            prepend_env_var(env, lib_path_envvar,
+                            os.path.join(options.builddir, root))
 
     return env
 
diff --git a/setup b/setup
index 3f76857..489878e 100755 (executable)
--- a/setup
+++ b/setup
@@ -8,6 +8,7 @@ import shutil
 import subprocess
 
 from common import git
+from common import get_meson
 from common import Colors
 from common import accept_command
 
@@ -17,22 +18,13 @@ PROJECTNAME = "GStreamer build"
 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
 
 
-def get_meson():
-    meson = os.path.join(ROOTDIR, 'meson', 'meson.py')
-    if os.path.exists(meson):
-        mesonconf = os.path.join(ROOTDIR, 'meson', 'mesonconf.py')
-        return meson, mesonconf
-
-    return accept_command(["meson.py", "meson"]), accept_command(["mesonconf.py", "mesonconf"])
-
-
 def get_configs():
      return ['--werror']
 
 
 def configure_meson(args, options):
     """Configures meson and generate the Makefile."""
-    meson, mesonconf = get_meson()
+    meson, mesonconf, mesonintrospect = get_meson()
     if not meson:
         print("Install mesonbuild to build %s: http://mesonbuild.com/\n"
               "You can simply install it with:\n"