2010-01-10 Aaron Bockover <abockover@novell.com>
authorAaron Bockover <abockover@novell.com>
Mon, 11 Jan 2010 06:04:09 +0000 (06:04 -0000)
committerAaron Bockover <abockover@novell.com>
Mon, 11 Jan 2010 06:04:09 +0000 (06:04 -0000)
    * assembly.c (mono_set_rootdir): Support finding the mono paths on OS X
    at runtime in the same way as on Windows, which yields a relocatable
    Mono. Uses dyld's _NSGetExecutablePath and realpath to resolve the path
    of the running mono process.

    On TARGET_ARM, fallback () will always be executed.

svn path=/trunk/mono/; revision=149298

mono/metadata/ChangeLog
mono/metadata/assembly.c

index 73648899152ad9f2e0556f2de59ea5128becafff..445c4acedf45f88cda2e52850038b9ecad911894 100644 (file)
@@ -1,3 +1,12 @@
+2010-01-10  Aaron Bockover  <abockover@novell.com>
+
+       * assembly.c (mono_set_rootdir): Support finding the mono paths on OS X
+       at runtime in the same way as on Windows, which yields a relocatable
+       Mono. Uses dyld's _NSGetExecutablePath and realpath to resolve the path
+       of the running mono process.
+
+       On TARGET_ARM, fallback () will always be executed.
+
 2010-01-08  Rodrigo Kumpera  <rkumpera@novell.com>
 
        * icall.c (ves_icall_Type_GetInterfaceMapData): This function is generics variance aware.
index 65d769a9cf437408480946b6c0f9df22c28f648c..4e1cd840e4b74caa484e1387a708225cf1a7f14e 100644 (file)
 #include <sys/stat.h>
 #endif
 
+#ifdef PLATFORM_MACOSX
+#include <mach-o/dyld.h>
+#endif
+
 /* AssemblyVersionMap: an assembly name and the assembly version set on which it is based */
 typedef struct  {
        const char* assembly_name;
@@ -550,10 +554,35 @@ set_dirs (char *exe)
 void
 mono_set_rootdir (void)
 {
-#ifdef HOST_WIN32
+#if defined(HOST_WIN32) || (defined(PLATFORM_MACOSX) && !defined(TARGET_ARM))
        gchar *bindir, *installdir, *root, *name, *config;
 
+#ifdef HOST_WIN32
        name = mono_get_module_file_name ((HMODULE) &__ImageBase);
+#else
+       {
+               /* 
+                * _NSGetExecutablePath may return -1 to indicate buf is not large
+                *  enough, but we ignore that case to avoid having to do extra dynamic
+                *  allocation for the path and hope that 4096 is enough - this is 
+                *  ok in the Linux/Solaris case below at least...
+                */
+               
+               gchar buf[4096];
+               guint buf_size = sizeof (buf);
+               name = NULL;
+               if (_NSGetExecutablePath (buf, &buf_size) == 0) {
+                       name = realpath (buf, NULL);
+               }
+               if (name == NULL) {
+                       fallback ();
+                       return;
+               }
+       }
+#endif
+
        bindir = g_path_get_dirname (name);
        installdir = g_path_get_dirname (bindir);
        root = g_build_path (G_DIR_SEPARATOR_S, installdir, "lib", NULL);