[gnome-builder/gnome-builder-43] plugins/meson: allow installed executables to be default-run



commit ba1b335e9583e4706cc24d0aab1a48706ed427ba
Author: Christian Hergert <chergert redhat com>
Date:   Sat Sep 24 13:39:52 2022 -0700

    plugins/meson: allow installed executables to be default-run
    
    This will allow things like command-line tools to run an executable that
    is installed if otherwise not found. We do not allow unit tests to set
    can-default as that doesn't make much sense, they should be assigned
    manually.
    
    Fixes #1809

 src/plugins/meson/gbp-meson-introspection.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
---
diff --git a/src/plugins/meson/gbp-meson-introspection.c b/src/plugins/meson/gbp-meson-introspection.c
index 59038844d..212b1c22f 100644
--- a/src/plugins/meson/gbp-meson-introspection.c
+++ b/src/plugins/meson/gbp-meson-introspection.c
@@ -52,6 +52,30 @@ struct _GbpMesonIntrospection
 
 G_DEFINE_FINAL_TYPE (GbpMesonIntrospection, gbp_meson_introspection, IDE_TYPE_PIPELINE_STAGE)
 
+static gboolean
+get_bool_member (JsonObject *object,
+                 const char *member,
+                 gboolean   *location)
+{
+  JsonNode *node;
+
+  g_assert (object != NULL);
+  g_assert (member != NULL);
+  g_assert (location != NULL);
+
+  *location = FALSE;
+
+  if (json_object_has_member (object, member) &&
+      (node = json_object_get_member (object, member)) &&
+      JSON_NODE_HOLDS_VALUE (node))
+    {
+      *location = json_node_get_boolean (node);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 static gboolean
 get_string_member (JsonObject  *object,
                    const char  *member,
@@ -218,6 +242,7 @@ gbp_meson_introspection_load_test (GbpMesonIntrospection *self,
   ide_run_command_set_environ (run_command, (const char * const *)env);
   ide_run_command_set_argv (run_command, (const char * const *)cmd);
   ide_run_command_set_cwd (run_command, workdir);
+  ide_run_command_set_can_default (run_command, FALSE);
 
   g_list_store_append (self->run_commands, run_command);
 
@@ -294,8 +319,10 @@ gbp_meson_introspection_load_targets (GbpMesonIntrospection *self,
       if (ide_str_equal0 (type, "executable"))
         {
           g_auto(GStrv) filename = NULL;
+          gboolean installed = FALSE;
 
           get_strv_member (obj, "filename", &filename);
+          get_bool_member (obj, "installed", &installed);
 
           if (filename != NULL && filename[0] != NULL)
             {
@@ -305,6 +332,7 @@ gbp_meson_introspection_load_targets (GbpMesonIntrospection *self,
               ide_run_command_set_id (run_command, id);
               ide_run_command_set_display_name (run_command, name);
               ide_run_command_set_argv (run_command, IDE_STRV_INIT (filename[0]));
+              ide_run_command_set_can_default (run_command, installed);
 
               g_list_store_append (self->run_commands, run_command);
             }


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