[gimp/gimp-2-10] app: on make check, search menu XML files in both buildir and srcdir



commit b6c50c016c5feddaa0c1248b167bf70b04db5c21
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jul 1 18:49:50 2018 +0200

    app: on make check, search menu XML files in both buildir and srcdir
    
    Turn GIMP_TESTING_MENUS_DIR into GIMP_TESTING_MENUS_PATH and look in
    all its dirs for the menu file.
    
    (cherry picked from commit 8516aedadeb1f8081caa9ff4e0bc223bd194838e)

 app/tests/gimp-app-test-utils.c     | 74 +++++++++++++++++++++++++++++++------
 app/tests/gimp-app-test-utils.h     |  8 +++-
 app/tests/gimp-test-session-utils.c |  2 +-
 app/tests/test-save-and-export.c    |  2 +-
 app/tests/test-single-window-mode.c |  2 +-
 app/tests/test-tools.c              |  2 +-
 app/tests/test-ui.c                 |  2 +-
 app/widgets/gimpuimanager.c         | 30 ++++++++++++---
 8 files changed, 97 insertions(+), 25 deletions(-)
---
diff --git a/app/tests/gimp-app-test-utils.c b/app/tests/gimp-app-test-utils.c
index a39927f802..ab68070276 100644
--- a/app/tests/gimp-app-test-utils.c
+++ b/app/tests/gimp-app-test-utils.c
@@ -50,9 +50,9 @@
 #endif /* G_OS_WIN32 */
 
 void
-gimp_test_utils_set_env_to_subpath (const gchar *root_env_var,
-                                    const gchar *subdir,
-                                    const gchar *target_env_var)
+gimp_test_utils_set_env_to_subdir (const gchar *root_env_var,
+                                   const gchar *subdir,
+                                   const gchar *target_env_var)
 {
   const gchar *root_dir   = NULL;
   gchar       *target_dir = NULL;
@@ -75,6 +75,55 @@ gimp_test_utils_set_env_to_subpath (const gchar *root_env_var,
   g_free (target_dir);
 }
 
+void
+gimp_test_utils_set_env_to_subpath (const gchar *root_env_var1,
+                                    const gchar *root_env_var2,
+                                    const gchar *subdir,
+                                    const gchar *target_env_var)
+{
+  const gchar *root_dir1   = NULL;
+  const gchar *root_dir2   = NULL;
+  gchar       *target_dir1 = NULL;
+  gchar       *target_dir2 = NULL;
+  gchar       *target_path = NULL;
+
+  /* Get root dir */
+  root_dir1 = g_getenv (root_env_var1);
+  if (! root_dir1)
+    g_printerr ("*\n"
+                "*  The env var %s is not set, you are probably running\n"
+                "*  in a debugger. Set it manually, e.g.:\n"
+                "*\n"
+                "*    set env %s=%s/source/gimp\n"
+                "*\n",
+                root_env_var1,
+                root_env_var1, g_get_home_dir ());
+
+  root_dir2 = g_getenv (root_env_var2);
+  if (! root_dir2)
+    g_printerr ("*\n"
+                "*  The env var %s is not set, you are probably running\n"
+                "*  in a debugger. Set it manually, e.g.:\n"
+                "*\n"
+                "*    set env %s=%s/source/gimp\n"
+                "*\n",
+                root_env_var2,
+                root_env_var2, g_get_home_dir ());
+
+  /* Construct path and setup target env var */
+  target_dir1 = g_build_filename (root_dir1, subdir, NULL);
+  target_dir2 = g_build_filename (root_dir2, subdir, NULL);
+
+  target_path = g_strconcat (target_dir1, G_SEARCHPATH_SEPARATOR_S,
+                             target_dir2, NULL);
+
+  g_free (target_dir1);
+  g_free (target_dir2);
+
+  g_setenv (target_env_var, target_path, TRUE);
+  g_free (target_path);
+}
+
 
 /**
  * gimp_test_utils_set_gimp2_directory:
@@ -89,25 +138,26 @@ void
 gimp_test_utils_set_gimp2_directory (const gchar *root_env_var,
                                      const gchar *subdir)
 {
-  gimp_test_utils_set_env_to_subpath (root_env_var,
-                                      subdir,
-                                      "GIMP2_DIRECTORY" /*target_env_var*/);
+  gimp_test_utils_set_env_to_subdir (root_env_var,
+                                     subdir,
+                                     "GIMP2_DIRECTORY" /*target_env_var*/);
 }
 
 /**
- * gimp_test_utils_setup_menus_dir:
+ * gimp_test_utils_setup_menus_path:
  *
- * Sets GIMP_TESTING_MENUS_DIR to "$top_srcdir/menus".
+ * Sets GIMP_TESTING_MENUS_PATH to "$top_srcdir/menus:$top_builddir/menus".
  **/
 void
-gimp_test_utils_setup_menus_dir (void)
+gimp_test_utils_setup_menus_path (void)
 {
   /* GIMP_TESTING_ABS_TOP_SRCDIR is set by the automake test runner,
    * see Makefile.am
    */
-  gimp_test_utils_set_env_to_subpath ("GIMP_TESTING_ABS_TOP_SRCDIR" /*root_env_var*/,
-                                      "menus" /*subdir*/,
-                                      "GIMP_TESTING_MENUS_DIR" /*target_env_var*/);
+  gimp_test_utils_set_env_to_subpath ("GIMP_TESTING_ABS_TOP_SRCDIR",
+                                      "GIMP_TESTING_ABS_TOP_BUILDDIR",
+                                      "menus",
+                                      "GIMP_TESTING_MENUS_PATH");
 }
 
 /**
diff --git a/app/tests/gimp-app-test-utils.h b/app/tests/gimp-app-test-utils.h
index 9cb22287fe..5c952df8a0 100644
--- a/app/tests/gimp-app-test-utils.h
+++ b/app/tests/gimp-app-test-utils.h
@@ -19,12 +19,16 @@
 #define  __GIMP_APP_TEST_UTILS_H__
 
 
-void            gimp_test_utils_set_env_to_subpath   (const gchar *root_env_var,
+void            gimp_test_utils_set_env_to_subdir    (const gchar *root_env_var,
+                                                      const gchar *subdir,
+                                                      const gchar *target_env_var);
+void            gimp_test_utils_set_env_to_subpath   (const gchar *root_env_var1,
+                                                      const gchar *root_env_var2,
                                                       const gchar *subdir,
                                                       const gchar *target_env_var);
 void            gimp_test_utils_set_gimp2_directory  (const gchar *root_env_var,
                                                       const gchar *subdir);
-void            gimp_test_utils_setup_menus_dir      (void);
+void            gimp_test_utils_setup_menus_path     (void);
 void            gimp_test_utils_create_image         (Gimp        *gimp,
                                                       gint         width,
                                                       gint         height);
diff --git a/app/tests/gimp-test-session-utils.c b/app/tests/gimp-test-session-utils.c
index dd35b9038b..41b7d12d2b 100644
--- a/app/tests/gimp-test-session-utils.c
+++ b/app/tests/gimp-test-session-utils.c
@@ -177,7 +177,7 @@ gimp_test_session_load_and_write_session_files (const gchar *loaded_sessionrc,
   /* Make sure to run this before we use any GIMP functions */
   gimp_test_utils_set_gimp2_directory ("GIMP_TESTING_ABS_TOP_SRCDIR",
                                        "app/tests/gimpdir");
-  gimp_test_utils_setup_menus_dir ();
+  gimp_test_utils_setup_menus_path ();
 
   /* Note that we expect the resulting sessionrc to be different from
    * the read file, which is why we check the MD5 of the -expected
diff --git a/app/tests/test-save-and-export.c b/app/tests/test-save-and-export.c
index da47a906ad..dbb1f076ba 100644
--- a/app/tests/test-save-and-export.c
+++ b/app/tests/test-save-and-export.c
@@ -368,7 +368,7 @@ main(int    argc,
 
   gimp_test_utils_set_gimp2_directory ("GIMP_TESTING_ABS_TOP_SRCDIR",
                                        "app/tests/gimpdir");
-  gimp_test_utils_setup_menus_dir ();
+  gimp_test_utils_setup_menus_path ();
 
   /* Start up GIMP */
   gimp = gimp_init_for_gui_testing (TRUE /*show_gui*/);
diff --git a/app/tests/test-single-window-mode.c b/app/tests/test-single-window-mode.c
index ca1b2f3f28..0f9a823777 100644
--- a/app/tests/test-single-window-mode.c
+++ b/app/tests/test-single-window-mode.c
@@ -135,7 +135,7 @@ int main(int argc, char **argv)
 
   gimp_test_utils_set_gimp2_directory ("GIMP_TESTING_ABS_TOP_SRCDIR",
                                        "app/tests/gimpdir");
-  gimp_test_utils_setup_menus_dir ();
+  gimp_test_utils_setup_menus_path ();
 
   /* Launch GIMP in single-window mode */
   g_setenv ("GIMP_TESTING_SESSIONRC_NAME", "sessionrc-2-8-single-window", TRUE /*overwrite*/);
diff --git a/app/tests/test-tools.c b/app/tests/test-tools.c
index 2d1c83ef68..0c36afe928 100644
--- a/app/tests/test-tools.c
+++ b/app/tests/test-tools.c
@@ -468,7 +468,7 @@ int main(int argc, char **argv)
 
   gimp_test_utils_set_gimp2_directory ("GIMP_TESTING_ABS_TOP_SRCDIR",
                                        "app/tests/gimpdir");
-  gimp_test_utils_setup_menus_dir ();
+  gimp_test_utils_setup_menus_path ();
 
   /* Start up GIMP */
   gimp = gimp_init_for_gui_testing (TRUE /*show_gui*/);
diff --git a/app/tests/test-ui.c b/app/tests/test-ui.c
index 6384d6f1dd..94de4f5b4c 100644
--- a/app/tests/test-ui.c
+++ b/app/tests/test-ui.c
@@ -933,7 +933,7 @@ int main(int argc, char **argv)
 
   gimp_test_utils_set_gimp2_directory ("GIMP_TESTING_ABS_TOP_SRCDIR",
                                        "app/tests/gimpdir");
-  gimp_test_utils_setup_menus_dir ();
+  gimp_test_utils_setup_menus_path ();
 
   /* Start up GIMP */
   gimp = gimp_init_for_gui_testing (TRUE /*show_gui*/);
diff --git a/app/widgets/gimpuimanager.c b/app/widgets/gimpuimanager.c
index 7c26e29942..aceb04960a 100644
--- a/app/widgets/gimpuimanager.c
+++ b/app/widgets/gimpuimanager.c
@@ -704,18 +704,36 @@ gimp_ui_manager_entry_load (GimpUIManager         *manager,
                             GimpUIManagerUIEntry  *entry,
                             GError               **error)
 {
-  gchar       *filename           = NULL;
-  const gchar *menus_dir_override = g_getenv ("GIMP_TESTING_MENUS_DIR");
+  gchar       *filename            = NULL;
+  const gchar *menus_path_override = g_getenv ("GIMP_TESTING_MENUS_PATH");
 
   /* In order for test cases to be able to run without GIMP being
    * installed yet, allow them to override the menus directory to the
    * menus dir in the source root
    */
-  if (menus_dir_override)
-    filename = g_build_filename (menus_dir_override, entry->basename, NULL);
+  if (menus_path_override)
+    {
+      GList *path = gimp_path_parse (menus_path_override, 2, FALSE, NULL);
+      GList *list;
+
+      for (list = path; list; list = g_list_next (list))
+        {
+          filename = g_build_filename (list->data, entry->basename, NULL);
+
+          if (! list->next ||
+              g_file_test (filename, G_FILE_TEST_EXISTS))
+            break;
+
+          g_free (filename);
+        }
+
+      g_list_free_full (path, g_free);
+    }
   else
-    filename = g_build_filename (gimp_data_directory (), "menus",
-                                 entry->basename, NULL);
+    {
+      filename = g_build_filename (gimp_data_directory (), "menus",
+                                   entry->basename, NULL);
+    }
 
   if (manager->gimp->be_verbose)
     g_print ("loading menu '%s' for %s\n",


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