changeset 15355:43aa6a7e60bd

mx exportlibs: include libs only if there's a real dependency from a project
author Bernhard Urban <bernhard.urban@jku.at>
date Thu, 24 Apr 2014 11:50:40 +0200
parents 4ab89f0ff10c
children 9e7f87dc6395
files mxtool/mx.py
diffstat 1 files changed, 28 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mxtool/mx.py	Wed Apr 23 22:46:38 2014 +0200
+++ b/mxtool/mx.py	Thu Apr 24 11:50:40 2014 +0200
@@ -4365,9 +4365,34 @@
             else:
                 logv('[already added ' + path + ']')
 
-        for lib in _libs.itervalues():
-            if len(lib.urls) != 0 or args.include_system_libs:
-                add(lib.get_path(resolve=True), lib.path)
+        libsToExport = set()
+        def isValidLibrary(dep):
+            if dep in _libs.iterkeys():
+                lib = _libs[dep]
+                if len(lib.urls) != 0 or args.include_system_libs:
+                    return lib
+            return None
+
+        # iterate over all project dependencies and find used libraries
+        for p in _projects.itervalues():
+            for dep in p.deps:
+                r = isValidLibrary(dep)
+                if r:
+                    libsToExport.add(r)
+
+        # a library can have other libraries as dependency
+        size = 0
+        while size != len(libsToExport):
+            for lib in libsToExport.copy():
+                for dep in lib.deps:
+                    r = isValidLibrary(dep)
+                    if r:
+                        libsToExport.add(r)
+            size = len(libsToExport)
+
+        for lib in libsToExport:
+            add(lib.get_path(resolve=True), lib.path)
+
         if args.extras:
             for e in args.extras:
                 if os.path.isdir(e):