[banshee] [solitary] ldd, otool support; confinement root



commit ac557018adb792aa8b23ddcd29aed01c2058420a
Author: Aaron Bockover <abockover novell com>
Date:   Tue Dec 29 19:24:57 2009 -0500

    [solitary] ldd, otool support; confinement root
    
    Process all native libraries with either ldd or otool -L
    to gather a full list of native dependencies.
    
    Support a confinement root - if set, any files located
    outside of the root will be ignored.

 build/bundle/mkbundle.osx                  |    1 +
 build/bundle/solitary/AssemblyItem.cs      |    2 +-
 build/bundle/solitary/Entry.cs             |    8 +++-
 build/bundle/solitary/Item.cs              |   10 +++++
 build/bundle/solitary/NativeLibraryItem.cs |   60 ++++++++++++++++++++++++++-
 build/bundle/solitary/Solitary.cs          |    1 +
 6 files changed, 77 insertions(+), 5 deletions(-)
---
diff --git a/build/bundle/mkbundle.osx b/build/bundle/mkbundle.osx
index 48f9e81..64d3a72 100755
--- a/build/bundle/mkbundle.osx
+++ b/build/bundle/mkbundle.osx
@@ -15,6 +15,7 @@ cd solitary
 make
 mono --debug Solitary.exe \
 	--mono-prefix=$BUILD_PREFIX \
+	--root=$BUILD_PREFIX \
 	$BANSHEE_PATH \
 	$BUILD_PREFIX/lib/gstreamer-0.10
 
diff --git a/build/bundle/solitary/AssemblyItem.cs b/build/bundle/solitary/AssemblyItem.cs
index 42d4ea9..373a61d 100644
--- a/build/bundle/solitary/AssemblyItem.cs
+++ b/build/bundle/solitary/AssemblyItem.cs
@@ -43,7 +43,7 @@ public class AssemblyItem : Item
             File = new FileInfo (Assembly.Location);
         }
 
-        if (Confinement.Items.Exists (item => item.File.FullName == File.FullName)) {
+        if (!IsValidConfinementItem (this)) {
             yield break;
         }
 
diff --git a/build/bundle/solitary/Entry.cs b/build/bundle/solitary/Entry.cs
index 07bc359..b700547 100644
--- a/build/bundle/solitary/Entry.cs
+++ b/build/bundle/solitary/Entry.cs
@@ -41,6 +41,7 @@ public static class Entry
 
         var p = new OptionSet () {
             { "p|mono-prefix=", "set the mono prefix (e.g. to find etc/mono/config)", v => solitary.MonoPrefix = v },
+            { "r|root=", "set the confinement root - any files outside of the root will be ignored", v => solitary.ConfinementRoot = v },
             { "b|blacklist=", "blacklist file to exclude native libraries from the summary", v => blacklist_file = v },
             { "h|help", "show this message and exit", v => show_help = v != null }
         };
@@ -70,7 +71,12 @@ public static class Entry
                 foreach (var collect_item in item.Load ()) {
                     solitary.Items.Add (collect_item);
                     total_size += collect_item.File.Length;
-                    Console.WriteLine ("{0}\t{1}", collect_item.File.Length, collect_item.File.FullName);
+
+                    if (solitary.ConfinementRoot != null) {
+                        Console.WriteLine (collect_item.File.FullName.Substring (solitary.ConfinementRoot.Length + 1));
+                    } else {
+                        Console.WriteLine (collect_item.File.FullName);
+                    }
                 }
             }
         }
diff --git a/build/bundle/solitary/Item.cs b/build/bundle/solitary/Item.cs
index 98efcde..5d69c46 100644
--- a/build/bundle/solitary/Item.cs
+++ b/build/bundle/solitary/Item.cs
@@ -52,6 +52,16 @@ public abstract class Item
         }
     }
 
+    public bool IsValidConfinementItem (Item item)
+    {
+        if (Confinement.ConfinementRoot != null &&
+            !item.File.FullName.StartsWith (Confinement.ConfinementRoot)) {
+            return false;
+        }
+
+        return !Confinement.Items.Exists (c => c.File.FullName == item.File.FullName);
+    }
+
     public static Item Resolve (Solitary confinement, FileInfo file)
     {
         if (file.Name.StartsWith (".")) {
diff --git a/build/bundle/solitary/NativeLibraryItem.cs b/build/bundle/solitary/NativeLibraryItem.cs
index 6b18bec..ab576ad 100644
--- a/build/bundle/solitary/NativeLibraryItem.cs
+++ b/build/bundle/solitary/NativeLibraryItem.cs
@@ -24,19 +24,73 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-
 using System;
+using System.IO;
+using System.Diagnostics;
 using System.Collections.Generic;
 
 public class NativeLibraryItem : Item
 {
     public override IEnumerable<Item> Load ()
     {
-        if (Confinement.Items.Exists (item => item.File.FullName == File.FullName)) {
+        if (!IsValidConfinementItem (this)) {
+            yield break;
+        }
+
+        foreach (var item in LddFile ()) {
+            yield return item;
+        }
+    }
+
+    private Process CreateProcess (string cmd, string args)
+    {
+        return Process.Start (new ProcessStartInfo (cmd, args) {
+            RedirectStandardOutput = true,
+            RedirectStandardError = true,
+            UseShellExecute = false
+        });
+    }
+
+    private IEnumerable<Item> LddFile ()
+    {
+        Process proc = null;
+
+        try {
+            proc = CreateProcess ("ldd", File.FullName);
+        } catch {
+            proc = CreateProcess ("otool", "-L " + File.FullName);
+        }
+
+        proc.WaitForExit ();
+        if (proc.ExitCode != 0) {
             yield break;
         }
 
         yield return this;
-        // FIXME: 'ldd' on this to walk native dependencies
+
+        string line;
+        while ((line = proc.StandardOutput.ReadLine ()) != null) {
+            line = line.Trim ();
+
+            int addr = line.IndexOf ('(');
+            if (addr < 0) {
+                continue;
+            }
+
+            line = line.Substring (0, addr);
+            int map = line.IndexOf (" => ");
+            if (map > 0) {
+                line = line.Substring (map + 4);
+            }
+
+            var item = new NativeLibraryItem () {
+                File = new FileInfo (line.Trim ()),
+                Confinement = Confinement
+            };
+
+            foreach (var child_item in item.Load ()) {
+                yield return child_item;
+            }
+        }
     }
 }
diff --git a/build/bundle/solitary/Solitary.cs b/build/bundle/solitary/Solitary.cs
index e36463d..83e737e 100644
--- a/build/bundle/solitary/Solitary.cs
+++ b/build/bundle/solitary/Solitary.cs
@@ -34,6 +34,7 @@ public class Solitary
     public List<Item> Items { get; private set; }
     public List<string> SearchPaths { get; private set; }
     public string MonoPrefix { get; set; }
+    public string ConfinementRoot { get; set; }
 
     private class BlacklistComparer : IEqualityComparer<string>
     {



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