[gegl/wip/Jehan/runtime-availability-check: 2/2] operations: gegl:introspect to use the new is_available() class method.




commit 1f50456de59c686941a861d299a63bfcd4126ee5
Author: Jehan <jehan girinstud io>
Date:   Mon Dec 14 19:04:09 2020 +0100

    operations: gegl:introspect to use the new is_available() class method.
    
    "gegl:introspect" depends on the external "dot" tool availability. If
    absent, we should hide the operation.
    
    We still search for `dot` on the main configure step, but now only for
    informative purpose (and outputting the result on the configuration
    summary). It does not block anymore the build and the operation is
    always built, whether or not dot is found at configure time.

 meson.build                    |  3 ++-
 operations/common/introspect.c | 22 ++++++++++++++++++++--
 operations/common/meson.build  |  2 +-
 3 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/meson.build b/meson.build
index 72581e9fe..a8846c155 100644
--- a/meson.build
+++ b/meson.build
@@ -136,7 +136,7 @@ add_project_arguments(cpp.get_supported_arguments(cflags_cpp), language: 'cpp')
 # Utilities
 
 bash        = find_program('bash')
-dot         = os_win32 ? find_program('dot.exe') : find_program('dot')
+dot         = os_win32 ? find_program('dot.exe', required: false) : find_program('dot', required: false)
 
 perl        = find_program('perl5', 'perl', required: false)
 asciidoc    = find_program('asciidoc',      required: false)
@@ -378,6 +378,7 @@ message('\n'.join(['',
 '',
 'Optional dependencies:',
 '  asciidoc:        @0@'.format(asciidoc.found()),
+'  dot:             @0@'.format(dot.found()),
 '  enscript:        @0@'.format(enscript.found()),
 '  mrg:             @0@'.format(mrg.found()),
 '  Ruby:            @0@'.format(ruby.found()),
diff --git a/operations/common/introspect.c b/operations/common/introspect.c
index a86e12ae7..2b9820148 100644
--- a/operations/common/introspect.c
+++ b/operations/common/introspect.c
@@ -43,9 +43,12 @@ gegl_introspect_load_cache (GeglProperties *op_introspect)
   gchar      *png_filename = NULL;
   gchar      *dot_filename = NULL;
   gchar      *dot_cmd      = NULL;
+  gchar      *dot;
   gint        fd;
 
-  if (op_introspect->user_data || op_introspect->node == NULL)
+  dot = g_find_program_in_path ("dot");
+
+  if (! dot || op_introspect->user_data || op_introspect->node == NULL)
     return;
 
   /* Construct temp filenames */
@@ -67,7 +70,7 @@ gegl_introspect_load_cache (GeglProperties *op_introspect)
   close (fd);
 
   /* Process the .dot to a .png */
-  dot_cmd = g_strdup_printf ("%s -o %s -Tpng %s", DOT, png_filename, dot_filename);
+  dot_cmd = g_strdup_printf ("%s -o %s -Tpng %s", dot, png_filename, dot_filename);
   if (system (dot_cmd) != 0)
     {
       g_warning ("Error executing GraphViz dot program");
@@ -103,6 +106,7 @@ gegl_introspect_load_cache (GeglProperties *op_introspect)
   unlink (png_filename);
 
   /* Cleanup */
+  g_free (dot);
   g_free (dot_string);
   g_free (dot_cmd);
   g_free (dot_filename);
@@ -167,6 +171,19 @@ gegl_introspect_process (GeglOperation        *operation,
   return  TRUE;
 }
 
+static gboolean
+gegl_introspect_is_available (void)
+{
+  gchar    *dot;
+  gboolean  found = FALSE;
+
+  dot = g_find_program_in_path ("dot");
+  found = (dot != NULL);
+  g_free (dot);
+
+  return found;
+}
+
 static void
 gegl_op_class_init (GeglOpClass *klass)
 {
@@ -180,6 +197,7 @@ gegl_op_class_init (GeglOpClass *klass)
 
   operation_class->process          = gegl_introspect_process;
   operation_class->get_bounding_box = gegl_introspect_get_bounding_box;
+  operation_class->is_available     = gegl_introspect_is_available;
 
   gegl_operation_class_set_keys (operation_class,
     "name"       , "gegl:introspect",
diff --git a/operations/common/meson.build b/operations/common/meson.build
index a7a2b7dd2..13575b571 100644
--- a/operations/common/meson.build
+++ b/operations/common/meson.build
@@ -140,7 +140,7 @@ gegl_common = shared_library('gegl-common',
     gegl_lib,
   ],
   c_args: [
-    '-DGEGL_OP_BUNDLE', '-DDOT="' + (os_win32 ? 'dot.exe' : dot.path()) + '"'
+    '-DGEGL_OP_BUNDLE',
   ],
   name_prefix: '',
   install: true,


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