From afe64deb46d0d6f7f117ad82bf35e0c2cc7b97d5 Mon Sep 17 00:00:00 2001 From: Charles Day Date: Mon, 13 Jul 2009 20:39:44 +0000 Subject: [PATCH] Patch by John Ralls. Permits binreloc to work from inside a MacOSX application bundle. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18207 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Makefile.am | 2 ++ src/engine/binreloc.c | 66 ++++++++++++++++++++++++++++++++++++++++-- src/engine/binreloc.h | 4 +++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index c91374a467..64cf7c1caa 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -10,6 +10,7 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/gnc-module \ -I${top_srcdir}/src/libqof/qof \ ${GLIB_CFLAGS} \ + ${IGE_MAC_CFLAGS} \ ${GUILE_INCS} libgncmod_engine_la_SOURCES = \ @@ -116,6 +117,7 @@ libgncmod_engine_la_LIBADD = \ ${REGEX_LIBS} \ ${GLIB_LIBS} \ ${BINRELOC_LIBS} \ + ${IGE_MAC_LIBS} \ ${top_builddir}/lib/libc/libc-missing.la gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash diff --git a/src/engine/binreloc.c b/src/engine/binreloc.c index bf5c035521..ad19558686 100644 --- a/src/engine/binreloc.c +++ b/src/engine/binreloc.c @@ -18,6 +18,9 @@ #include #include #include +#ifdef MAC_INTEGRATION +#include +#endif #endif /* ENABLE_BINRELOC */ #include #include @@ -27,7 +30,9 @@ #include G_BEGIN_DECLS - +#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION +static IgeMacBundle *bundle = NULL; +#endif /** @internal * Find the canonical filename of the executable. Returns the filename @@ -60,6 +65,26 @@ _br_find_exe (GbrInitError *error) (char*)NULL); g_free (prefix); return result; +#elif MAC_INTEGRATION + gchar *prefix = NULL, *result = NULL; + g_type_init(); + bundle = ige_mac_bundle_new(); + if (!bundle) { + *error = GBR_INIT_ERROR_MAC_NOT_BUNDLE; + return NULL; + } + if (!ige_mac_bundle_get_is_app_bundle (bundle)) { + g_object_unref(bundle); + bundle = NULL; + *error = GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE; + return NULL; + } + ige_mac_bundle_setup_environment(bundle); + prefix = g_strdup(ige_mac_bundle_get_path(bundle)); + result = g_build_filename(prefix, "Contents/MacOS", + "gnucash-bin", NULL); + g_free(prefix); + return result; #else char *path, *path2, *line, *result; size_t buf_size; @@ -201,7 +226,7 @@ _br_find_exe_for_symbol (const void *symbol, GbrInitError *error) *error = GBR_INIT_ERROR_DISABLED; return (char *) NULL; #else -#ifdef G_OS_WIN32 +#if defined G_OS_WIN32 g_warning ("_br_find_exe_for_symbol not implemented on win32."); if (error) *error = GBR_INIT_ERROR_DISABLED; @@ -390,6 +415,12 @@ set_gerror (GError **error, GbrInitError errcode) case GBR_INIT_ERROR_INVALID_MAPS: error_message = "The file format of /proc/self/maps is invalid."; break; + case GBR_INIT_ERROR_MAC_NOT_BUNDLE: + error_message = "Binreloc did not find a bundle"; + break; + case GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE: + error_message = "Binreloc found that the bundle is not an app bundle"; + break; case GBR_INIT_ERROR_DISABLED: error_message = "Binary relocation support is disabled."; break; @@ -473,6 +504,21 @@ gbr_find_prefix (const gchar *default_prefix) { gchar *dir1, *dir2; +#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION + gchar *prefix = NULL, *result = NULL; + if (bundle == NULL) { + /* BinReloc not initialized. */ + if (default_prefix != NULL) + return g_strdup (default_prefix); + else + return NULL; + } + prefix = g_strdup(ige_mac_bundle_get_path(bundle)); + result = g_build_filename(prefix, "Contents/Resources", NULL); + g_free(prefix); + return result; +#else + if (exe == NULL) { /* BinReloc not initialized. */ if (default_prefix != NULL) @@ -480,11 +526,11 @@ gbr_find_prefix (const gchar *default_prefix) else return NULL; } - dir1 = g_path_get_dirname (exe); dir2 = g_path_get_dirname (dir1); g_free (dir1); return dir2; +#endif //ENABLE_BINRELOC && MAC_INTEGRATION } @@ -505,6 +551,19 @@ gchar * gbr_find_bin_dir (const gchar *default_bin_dir) { gchar *prefix, *dir; +#if defined ENABLE_BINRELOC && defined MAC_INTEGRATION + if (bundle == NULL) { + /* BinReloc not initialized. */ + if (default_bin_dir != NULL) + return g_strdup (default_bin_dir); + else + return NULL; + } + prefix = g_strdup(ige_mac_bundle_get_path(bundle)); + dir = g_build_filename(prefix, "Contents/MacOS", NULL); + g_free(prefix); + return dir; +#else prefix = gbr_find_prefix (NULL); if (prefix == NULL) { @@ -518,6 +577,7 @@ gbr_find_bin_dir (const gchar *default_bin_dir) dir = g_build_filename (prefix, "bin", NULL); g_free (prefix); return dir; +#endif //ENABLE_BINRELOC && MAC_INTEGRATION } diff --git a/src/engine/binreloc.h b/src/engine/binreloc.h index 443e8503a5..7cfe95fb38 100644 --- a/src/engine/binreloc.h +++ b/src/engine/binreloc.h @@ -28,6 +28,10 @@ typedef enum { GBR_INIT_ERROR_READ_MAPS, /** The file format of /proc/self/maps is invalid; kernel bug? */ GBR_INIT_ERROR_INVALID_MAPS, + /** BinReloc determined that gnucash is not running from a bundle */ + GBR_INIT_ERROR_MAC_NOT_BUNDLE, + /** Binreloc determined that the bundle is not an app bundle */ + GBR_INIT_ERROR_MAC_NOT_APP_BUNDLE, /** BinReloc is disabled (the ENABLE_BINRELOC macro is not defined). */ GBR_INIT_ERROR_DISABLED } GbrInitError;