banshee r4775 - in trunk/banshee: . build src/Backends/Banshee.Unix src/Clients/Booter src/Clients/Booter/Booter src/Libraries/Hyena.Gui



Author: abock
Date: Tue Nov  4 21:03:34 2008
New Revision: 4775
URL: http://svn.gnome.org/viewvc/banshee?rev=4775&view=rev

Log:
2008-11-04  Aaron Bockover  <abock gnome org>

    * build/Makefile.am:
    * build/DllMapVerifier.cs:
    * build/dll-map-makefile-verifier:
    * build/build.rules.mk: Wrote a DllImport and config file map verifier
    tool that analyzes source code and the build to ensure that any DllImport
    reference in the code must have a map in the config file or an explicit
    ignore in the build; also ensures that if a config file exists, it is
    included in module_SCRIPTS so it gets installed in the system

    * src/Clients/Booter/Makefile.am:
    * src/Clients/Booter/Banshee.exe.config:
    * src/Clients/Booter/Booter/Entry.cs:
    * src/Backends/Banshee.Unix/Banshee.Unix.dll.config:
    * src/Backends/Banshee.Unix/Makefile.am:
    * src/Libraries/Hyena.Gui/Hyena.Gui.dll.config: Fixed up more DLL maps



Added:
   trunk/banshee/build/DllMapVerifier.cs
   trunk/banshee/build/dll-map-makefile-verifier   (contents, props changed)
   trunk/banshee/src/Backends/Banshee.Unix/Banshee.Unix.dll.config
   trunk/banshee/src/Clients/Booter/Banshee.exe.config
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/build/Makefile.am
   trunk/banshee/build/build.rules.mk
   trunk/banshee/src/Backends/Banshee.Unix/Makefile.am
   trunk/banshee/src/Clients/Booter/Booter/Entry.cs
   trunk/banshee/src/Clients/Booter/Makefile.am
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.dll.config

Added: trunk/banshee/build/DllMapVerifier.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/build/DllMapVerifier.cs	Tue Nov  4 21:03:34 2008
@@ -0,0 +1,210 @@
+using System;
+using System.IO;
+using System.Xml;
+using System.Text;
+using System.Collections.Generic;
+
+public static class DllMapVerifier
+{
+    private struct DllImportRef
+    {
+        public DllImportRef (string name, int line, int column)
+        {
+            Name = name;
+            Line = line;
+            Column = column;
+        }
+
+        public string Name;
+        public int Line;
+        public int Column;
+    }
+
+    private static Dictionary<string, List<DllImportRef>> dll_imports 
+        = new Dictionary<string, List<DllImportRef>> ();
+    private static List<string> ignore_dlls = new List<string> ();
+    private static List<string> config_dlls = null;
+    
+    public static int Main (string [] args)
+    {
+        LoadConfigDlls (args[0]);
+        foreach (string file in args) {
+            LoadDllImports (file);
+        }
+
+        return VerifyDllImports (args[0]) ? 0 : 1;
+    }
+
+    private static bool VerifyDllImports (string configFile)
+    {
+        int total_unmapped_count = 0;
+
+        foreach (KeyValuePair<string, List<DllImportRef>> dll_import in dll_imports) {
+            int file_unmapped_count = 0;
+            foreach (DllImportRef dll_import_ref in dll_import.Value) {
+                if (config_dlls != null && config_dlls.Contains (dll_import_ref.Name)) {
+                    continue;
+                }
+
+                if (file_unmapped_count++ == 0) {
+                    Console.Error.WriteLine ("Unmapped DLLs in file: {0}", dll_import.Key);
+                }
+
+                Console.Error.WriteLine ("  + {0} : {1},{2}", dll_import_ref.Name, 
+                    dll_import_ref.Line, dll_import_ref.Column);
+            }
+
+            total_unmapped_count += file_unmapped_count;
+        }
+        
+        if (total_unmapped_count > 0 && config_dlls == null) {
+            Console.Error.WriteLine ("No config file for DLL mapping was found ({0})", configFile);
+        }
+
+        return total_unmapped_count == 0;
+    }
+    
+    private static void LoadDllImports (string csFile)
+    {
+        if (csFile.StartsWith ("-i")) {
+            ignore_dlls.Add (csFile.Substring (2));
+            return;
+        }
+
+        if (Path.GetExtension (csFile) == ".cs" && File.Exists (csFile)) {
+            List<DllImportRef> dll_import_refs = null;
+
+            foreach (DllImportRef dll_import in ParseFileForDllImports (csFile)) {
+                if (ignore_dlls.Contains (dll_import.Name)) {
+                    continue;
+                }
+            
+                if (dll_import_refs == null) {
+                    dll_import_refs = new List<DllImportRef> ();
+                }
+
+                dll_import_refs.Add (dll_import);
+            }
+
+            if (dll_import_refs != null) {
+                dll_imports.Add (csFile, dll_import_refs);
+            }
+        }
+    }
+
+    private static void LoadConfigDlls (string configFile)
+    {
+        try {
+            XmlTextReader config = new XmlTextReader (configFile);
+            config_dlls = new List<string> ();
+            while (config.Read ()) {
+                if (config.NodeType == XmlNodeType.Element && 
+                    config.Name == "dllmap") {
+                    string dll = config.GetAttribute ("dll");
+                    if (!config_dlls.Contains (dll)) {
+                        config_dlls.Add (dll);
+                    }
+                }
+            }
+        } catch {
+        }
+    }
+    
+#region DllImport parser
+
+    private static StreamReader reader;
+    private static int reader_line;
+    private static int reader_col;
+    
+    private static IEnumerable<DllImportRef> ParseFileForDllImports (string file)
+    {
+        reader_line = 1;
+        reader_col = 1;
+
+        using (reader = new StreamReader (file)) {
+            char c;
+            bool in_paren = false;
+            bool in_attr = false;
+            bool in_dll_attr = false;
+            bool in_string = false;
+            int dll_line = 1, dll_col = 1;
+            
+            while ((c = (char)reader.Peek ()) != Char.MaxValue) {
+                switch (c) {
+                    case ' ':
+                    case '\t': Read (); break;
+                    case '[': 
+                        in_attr = true;
+                        dll_line = reader_line;
+                        dll_col = reader_col;
+                        Read ();
+                        break;
+                    case '(': Read (); in_paren = true; break;
+                    case '"':
+                        Read ();
+                        if (in_dll_attr && in_paren && !in_string) {
+                            in_string = true;
+                        }
+                        break;
+                    default:
+                        if (!in_dll_attr && in_attr && ReadDllAttribute ()) {
+                            in_dll_attr = true;
+                        } else if (in_dll_attr && in_string) {
+                            yield return new DllImportRef (ReadDllString (), dll_line, dll_col);
+                            in_string = false;
+                            in_dll_attr = false;
+                            in_attr = false;
+                            in_paren = false;
+                        } else {
+                            Read ();
+                        }
+                        break;
+                }
+            }
+        }
+    }
+
+    private static bool ReadDllAttribute () 
+    {
+        return
+            Read () == 'D' && 
+            Read () == 'l' &&
+            Read () == 'l' &&
+            Read () == 'I' &&
+            Read () == 'm' &&
+            Read () == 'p' &&
+            Read () == 'o' &&
+            Read () == 'r' &&
+            Read () == 't';
+    }
+
+    private static string ReadDllString ()
+    {
+        StringBuilder builder = new StringBuilder (32);
+        while (true) {
+            char c = Read ();
+            if (Char.IsLetterOrDigit (c) || c == '.' || c == '-' || c == '_') {
+                builder.Append (c);
+            } else {
+                break;
+            }
+        }
+        return builder.ToString ();
+    }
+    
+    private static char Read ()
+    {
+        char c = (char)reader.Read ();
+        if (c == '\n') {
+            reader_line++;
+            reader_col = 1;
+        } else {
+            reader_col++;
+        }
+        return c;
+    }
+    
+#endregion
+
+}
+

Modified: trunk/banshee/build/Makefile.am
==============================================================================
--- trunk/banshee/build/Makefile.am	(original)
+++ trunk/banshee/build/Makefile.am	Tue Nov  4 21:03:34 2008
@@ -2,28 +2,36 @@
 
 GCONF_SCHEMA_EXTRACTOR_ASSEMBLY = gconf-schema-extractor.exe
 TRANSLATOR_EXTRACTOR_ASSEMBLY = translator-extractor.exe
+DLL_MAP_VERIFIER_ASSEMBLY = dll-map-verifier.exe
+
+ALL_TARGETS = $(TRANSLATOR_EXTRACT_ASSEMBLY) $(DLL_MAP_VERIFIER_ASSEMBLY)
 
 if GCONF_SCHEMAS_INSTALL
 bansheedir = $(pkglibdir)
 banshee_SCRIPTS = $(GCONF_SCHEMA_EXTRACTOR_ASSEMBLY)
-
-all: $(GCONF_SCHEMA_EXTRACTOR_ASSEMBLY) $(TRANSLATOR_EXTRACTOR_ASSEMBLY)
-
+ALL_TARGETS += $(GCONF_SCHEMA_EXTRACTOR_ASSEMBLY)
 $(GCONF_SCHEMA_EXTRACTOR_ASSEMBLY): GConfSchemaExtractor.cs
 	$(MCS) -out:$@ $<
 endif
 
+all: $(ALL_TARGETS)
+
 $(TRANSLATOR_EXTRACTOR_ASSEMBLY): TranslatorExtractor.cs
 	if [ "x$(top_srcdir)" = "x$(top_builddir)" ]; then \
 		$(MCS) -out:$@ $< && LC_ALL=en_US.utf8 $(MONO) $@ $(top_builddir)/po > \
 			$(top_srcdir)/src/Core/Banshee.Core/Resources/translators.xml; \
 	fi;
 
+$(DLL_MAP_VERIFIER_ASSEMBLY): DllMapVerifier.cs
+	$(MCS) -out:$@ $<
+
 EXTRA_DIST = \
 	icon-theme-installer \
 	private-icon-theme-installer \
 	GConfSchemaExtractor.cs \
 	TranslatorExtractor.cs \
+	DllMapVerifier.cs \
+	dll-map-makefile-verifier \
 	gconf-schema-rules
 
 CLEANFILES = *.exe *.mdb

Modified: trunk/banshee/build/build.rules.mk
==============================================================================
--- trunk/banshee/build/build.rules.mk	(original)
+++ trunk/banshee/build/build.rules.mk	Tue Nov  4 21:03:34 2008
@@ -58,9 +58,11 @@
 	test "x$$colors" = "xyes" && \
 		echo -e "\033[1mCompiling $(notdir $@)...\033[0m" || \
 		echo "Compiling $(notdir $@)...";
+	@$(top_srcdir)/build/dll-map-makefile-verifier $(srcdir)/Makefile.am $(srcdir)/$(notdir $  config)
+	@$(MONO) $(top_builddir)/build/dll-map-verifier.exe $(srcdir)/$(notdir $  config) -iwinmm -ilibbanshee -ilibbnpx11 -ilibc -ilibc.so.6 -iintl -ilibmtp.dll $(SOURCES_BUILD)
 	@$(BUILD) $(GMCS_FLAGS) -nowarn:0078 -target:$(TARGET) -out:$@ $$warn -define:HAVE_GTK_2_10 -define:NET_2_0 $(BUILD_DEFINES) $(ENABLE_TESTS_FLAG) $(FILTERED_LINK) $(RESOURCES_BUILD) $(SOURCES_BUILD) 
-	@if [ -e $(notdir $  config) ]; then \
-		cp $(notdir $  config) $(top_builddir)/bin; \
+	@if [ -e $(srcdir)/$(notdir $  config) ]; then \
+		cp $(srcdir)/$(notdir $  config) $(top_builddir)/bin; \
 	fi;
 	@if [ ! -z "$(EXTRA_BUNDLE)" ]; then \
 		cp $(EXTRA_BUNDLE) $(top_builddir)/bin; \

Added: trunk/banshee/build/dll-map-makefile-verifier
==============================================================================
--- (empty file)
+++ trunk/banshee/build/dll-map-makefile-verifier	Tue Nov  4 21:03:34 2008
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+if [ -f $2 ]; then
+	# Lame, but better than nothing
+	grep $(basename $2) $1 | grep module_SCRIPTS &>/dev/null || {
+		echo "Assembly has corresponding .config file, but it was not found in module_SCRIPTS in Makefile.am" 2>&1
+		exit 1
+	}
+fi
+

Added: trunk/banshee/src/Backends/Banshee.Unix/Banshee.Unix.dll.config
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Backends/Banshee.Unix/Banshee.Unix.dll.config	Tue Nov  4 21:03:34 2008
@@ -0,0 +1,4 @@
+<configuration>
+  <dllmap dll="libglib-2.0-0.dll" target="libglib-2.0.so.0" os="linux"/>
+  <dllmap dll="libglib-2.0-0.dll" target="libglib-2.0.dylib" os="osx"/>
+</configuration>
\ No newline at end of file

Modified: trunk/banshee/src/Backends/Banshee.Unix/Makefile.am
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Unix/Makefile.am	(original)
+++ trunk/banshee/src/Backends/Banshee.Unix/Makefile.am	Tue Nov  4 21:03:34 2008
@@ -13,3 +13,6 @@
 
 include $(top_srcdir)/build/build.mk
 
+EXTRA_DIST += Banshee.Unix.dll.config
+module_SCRIPTS += Banshee.Unix.dll.config
+

Added: trunk/banshee/src/Clients/Booter/Banshee.exe.config
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Clients/Booter/Banshee.exe.config	Tue Nov  4 21:03:34 2008
@@ -0,0 +1,4 @@
+<configuration>
+  <dllmap dll="libgdk-win32-2.0-0.dll" target="libgdk-x11-2.0.so.0" os="linux"/>
+  <dllmap dll="libgdk-win32-2.0-0.dll" target="libgdk-quartz-2.0.dylib" os="osx"/>
+</configuration>

Modified: trunk/banshee/src/Clients/Booter/Booter/Entry.cs
==============================================================================
--- trunk/banshee/src/Clients/Booter/Booter/Entry.cs	(original)
+++ trunk/banshee/src/Clients/Booter/Booter/Entry.cs	Tue Nov  4 21:03:34 2008
@@ -107,10 +107,10 @@
                 Assembly.GetEntryAssembly ().Location), String.Format ("{0}.exe", clientName)));
         }
         
-        [DllImport ("libgdk-x11-2.0.so.0")]
+        [DllImport ("libgdk-win32-2.0-0.dll")]
         private static extern bool gdk_init_check (IntPtr argc, IntPtr argv);
         
-        [DllImport ("libgdk-x11-2.0.so.0")]
+        [DllImport ("libgdk-win32-2.0-0.dll")]
         private static extern void gdk_notify_startup_complete ();
         
         private static void NotifyStartupComplete ()

Modified: trunk/banshee/src/Clients/Booter/Makefile.am
==============================================================================
--- trunk/banshee/src/Clients/Booter/Makefile.am	(original)
+++ trunk/banshee/src/Clients/Booter/Makefile.am	Tue Nov  4 21:03:34 2008
@@ -3,7 +3,8 @@
 LINK = $(REF_BOOTER)
 SOURCES = Booter/Entry.cs
 
-bin_SCRIPTS = banshee-1
-
 include $(top_srcdir)/build/build.mk
 
+bin_SCRIPTS = banshee-1
+EXTRA_DIST += Banshee.exe.config
+module_SCRIPTS += Banshee.exe.config

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.dll.config
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.dll.config	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.dll.config	Tue Nov  4 21:03:34 2008
@@ -5,6 +5,7 @@
   <dllmap dll="libgobject-2.0-0.dll" target="libgobject-2.0.so.0" os="linux"/>
   <dllmap dll="libgdk_pixbuf-2.0-0.dll" target="libgdk_pixbuf-2.0.so.0" os="linux"/>
   <dllmap dll="libpangocairo-1.0-0.dll" target="libpangocairo-1.0.so.0" os="linux"/>
+  <dllmap dll="libcairo-2.dll" target="libcairo.so.2" os="linux"/>
 
   <dllmap dll="libgtk-win32-2.0-0.dll" target="libgtk-quartz-2.0.dylib" os="osx"/>
   <dllmap dll="libgdk-win32-2.0-0.dll" target="libgdk-quartz-2.0.dylib" os="osx"/>
@@ -12,4 +13,5 @@
   <dllmap dll="libgobject-2.0-0.dll" target="libgobject-2.0.dylib" os="osx"/>
   <dllmap dll="libgdk_pixbuf-2.0-0.dll" target="libgdk_pixbuf-2.0.dylib" os="osx"/>
   <dllmap dll="libpangocairo-1.0-0.dll" target="libpangocairo-1.0.dylib" os="osx"/>
+  <dllmap dll="libcairo-2.dll" target="libcairo.2.dylib" os="linux"/>
 </configuration>



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