[gimp] macos: support for homebrew build



commit 271435534f22b6b49804e3bdcc91dafe012dbf19
Author: Lukas Oberhuber <lukaso gmail com>
Date:   Wed Jul 27 16:31:52 2022 +0100

    macos: support for homebrew build
    
    Supports running gimp in homebrew builds which have more complex
    structures of where things are placed.

 app/main.c            | 31 ++++++++++++++++++++++---------
 libgimpbase/gimpenv.c | 25 +++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 9 deletions(-)
---
diff --git a/app/main.c b/app/main.c
index 2a0c41e23c..e25edd14af 100644
--- a/app/main.c
+++ b/app/main.c
@@ -334,12 +334,13 @@ gimp_macos_setenv (const char * progname)
        */
       static gboolean            show_playground   = TRUE;
 
-      gchar *path;
-      gchar *tmp;
-      gchar *app_dir;
-      gchar *res_dir;
-      size_t path_len;
-      struct stat sb;
+      gchar   *path;
+      gchar   *tmp;
+      gchar   *app_dir;
+      gchar   *res_dir;
+      size_t   path_len;
+      struct   stat sb;
+      gboolean need_pythonhome = TRUE;
 
       app_dir = g_path_get_dirname (resolved_path);
       tmp = g_strdup_printf ("%s/../Resources", app_dir);
@@ -371,6 +372,15 @@ gimp_macos_setenv (const char * progname)
             }
         }
 
+      /* Detect we were built in homebrew for MacOS */
+      tmp = g_strdup_printf ("%s/Frameworks/Python.framework", res_dir);
+      if (tmp && !stat (tmp, &sb) && S_ISDIR (sb.st_mode))
+        {
+          g_print ("GIMP was built with homebrew\n");
+          need_pythonhome = FALSE;
+        }
+      g_free (tmp);
+
       path_len = strlen (g_getenv ("PATH") ? g_getenv ("PATH") : "") + strlen (app_dir) + 2;
       path = g_try_malloc (path_len);
       if (path == NULL)
@@ -400,9 +410,12 @@ gimp_macos_setenv (const char * progname)
       tmp = g_strdup_printf ("%s/etc/fonts", res_dir);
       g_setenv ("FONTCONFIG_PATH", tmp, TRUE);
       g_free (tmp);
-      tmp = g_strdup_printf ("%s", res_dir);
-      g_setenv ("PYTHONHOME", tmp, TRUE);
-      g_free (tmp);
+      if (need_pythonhome)
+        {
+          tmp = g_strdup_printf ("%s", res_dir);
+          g_setenv ("PYTHONHOME", tmp, TRUE);
+          g_free (tmp);
+        }
       tmp = g_strdup_printf ("%s/lib/python3.9", res_dir);
       g_setenv ("PYTHONPATH", tmp, TRUE);
       g_free (tmp);
diff --git a/libgimpbase/gimpenv.c b/libgimpbase/gimpenv.c
index 00e16bf7b9..9183f3f63e 100644
--- a/libgimpbase/gimpenv.c
+++ b/libgimpbase/gimpenv.c
@@ -441,6 +441,31 @@ gimp_installation_directory (void)
         g_free (tmp2);
         g_free (tmp3);
       }
+    else if (strstr (basepath, "/Cellar/"))
+      {
+        /*  we are running from a Python.framework bundle built in homebrew
+         *  during the build phase
+         */
+
+        gchar *fulldir = g_strdup (basepath);
+        gchar *lastdir = g_path_get_basename (fulldir);
+        gchar *tmp_fulldir;
+
+        while (strcmp (lastdir, "Cellar"))
+          {
+            tmp_fulldir = g_path_get_dirname (fulldir);
+
+            g_free (lastdir);
+            g_free (fulldir);
+
+            fulldir = tmp_fulldir;
+            lastdir = g_path_get_basename (fulldir);
+          }
+        toplevel = g_path_get_dirname (fulldir);
+
+        g_free (fulldir);
+        g_free (lastdir);
+      }
     else
       {
         /*  if none of the above match, we assume that we are really in a bundle  */


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