[gnome-builder/gnome-builder-3-24] flatpak: add build-args property



commit b40e6e9bf67c067ed9cab0ee45cfdb63e14757a6
Author: Christian Hergert <chergert redhat com>
Date:   Wed Mar 29 18:15:40 2017 -0600

    flatpak: add build-args property
    
    These are from the builder-options and we might need them to setup the
    flatpak build command-line arguments.

 plugins/flatpak/gbp-flatpak-configuration.c |   96 ++++++++++++++++++++++-----
 plugins/flatpak/gbp-flatpak-configuration.h |    3 +
 2 files changed, 82 insertions(+), 17 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-configuration.c b/plugins/flatpak/gbp-flatpak-configuration.c
index 5ab66ea..a164a65 100644
--- a/plugins/flatpak/gbp-flatpak-configuration.c
+++ b/plugins/flatpak/gbp-flatpak-configuration.c
@@ -28,6 +28,7 @@ struct _GbpFlatpakConfiguration
   IdeConfiguration parent_instance;
 
   gchar  *branch;
+  gchar **build_args;
   gchar **build_commands;
   gchar  *command;
   gchar **finish_args;
@@ -43,6 +44,7 @@ G_DEFINE_TYPE (GbpFlatpakConfiguration, gbp_flatpak_configuration, IDE_TYPE_CONF
 enum {
   PROP_0,
   PROP_BRANCH,
+  PROP_BUILD_ARGS,
   PROP_BUILD_COMMANDS,
   PROP_COMMAND,
   PROP_FINISH_ARGS,
@@ -155,6 +157,34 @@ guess_primary_module (JsonNode    *modules_node,
   return NULL;
 }
 
+static gchar **
+get_strv_from_member (JsonObject  *obj,
+                      const gchar *name)
+{
+  GPtrArray *finish_args = g_ptr_array_new ();
+  JsonNode *node = json_object_get_member (obj, name);
+  JsonArray *ar;
+  guint len;
+
+  if (node == NULL || !JSON_NODE_HOLDS_ARRAY (node))
+    return NULL;
+
+  ar = json_node_get_array (node);
+  len = json_array_get_length (ar);
+
+  for (guint i = 0; i < len; i++)
+    {
+      const gchar *arg = json_array_get_string_element (ar, i);
+
+      if (!ide_str_empty0 (arg))
+        g_ptr_array_add (finish_args, g_strdup (arg));
+    }
+
+  g_ptr_array_add (finish_args, NULL);
+
+  return (gchar **)g_ptr_array_free (finish_args, FALSE);
+}
+
 /**
  * gbp_flatpak_configuration_load_from_file:
  * @self: a #GbpFlatpakConfiguration
@@ -184,7 +214,6 @@ gbp_flatpak_configuration_load_from_file (GbpFlatpakConfiguration *self,
   JsonNode *modules_node = NULL;
   JsonNode *primary_module_node = NULL;
   JsonNode *command_node = NULL;
-  JsonNode *finish_args_node = NULL;
   JsonObject *root_object = NULL;
   g_autoptr(GError) local_error = NULL;
   IdeContext *context;
@@ -259,6 +288,12 @@ gbp_flatpak_configuration_load_from_file (GbpFlatpakConfiguration *self,
           if (cxxflags != NULL)
             ide_environment_setenv (environment, "CXXFLAGS", cxxflags);
         }
+      if (json_object_has_member (build_options, "build-args"))
+        {
+          g_auto(GStrv) build_args = get_strv_from_member (build_options, "build-args");
+
+          gbp_flatpak_configuration_set_build_args (self, (const gchar * const *)build_args);
+        }
       if (json_object_has_member (build_options, "env"))
         {
           JsonObject *env_vars;
@@ -304,23 +339,11 @@ gbp_flatpak_configuration_load_from_file (GbpFlatpakConfiguration *self,
   if (JSON_NODE_HOLDS_VALUE (command_node))
     gbp_flatpak_configuration_set_command (self, json_node_get_string (command_node));
 
-  finish_args_node = json_object_get_member (root_object, "finish-args");
-  if (JSON_NODE_HOLDS_ARRAY (finish_args_node))
+  if (json_object_has_member (root_object, "finish-args"))
     {
-      JsonArray *finish_args_array;
-      GPtrArray *finish_args;
-      g_auto(GStrv) finish_args_strv = NULL;
-      finish_args = g_ptr_array_new ();
-      finish_args_array = json_node_get_array (finish_args_node);
-      for (guint i = 0; i < json_array_get_length (finish_args_array); i++)
-        {
-          const gchar *arg = json_array_get_string_element (finish_args_array, i);
-          if (!ide_str_empty0 (arg))
-            g_ptr_array_add (finish_args, g_strdup (arg));
-        }
-      g_ptr_array_add (finish_args, NULL);
-      finish_args_strv = (gchar **)g_ptr_array_free (finish_args, FALSE);
-      gbp_flatpak_configuration_set_finish_args (self, (const gchar * const *)finish_args_strv);
+      g_auto(GStrv) finish_args = get_strv_from_member (root_object, "finish-args");
+
+      gbp_flatpak_configuration_set_finish_args (self, (const gchar * const *)finish_args);
     }
 
   if (app_id_node != NULL && JSON_NODE_HOLDS_VALUE (app_id_node))
@@ -460,6 +483,28 @@ gbp_flatpak_configuration_set_command (GbpFlatpakConfiguration *self,
 }
 
 const gchar * const *
+gbp_flatpak_configuration_get_build_args (GbpFlatpakConfiguration *self)
+{
+  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
+
+  return (const gchar * const *)self->build_args;
+}
+
+void
+gbp_flatpak_configuration_set_build_args (GbpFlatpakConfiguration *self,
+                                          const gchar * const     *build_args)
+{
+  g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));
+
+  if (self->build_args != (gchar **)build_args)
+    {
+      g_strfreev (self->build_args);
+      self->build_args = g_strdupv ((gchar **)build_args);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUILD_ARGS]);
+    }
+}
+
+const gchar * const *
 gbp_flatpak_configuration_get_finish_args (GbpFlatpakConfiguration *self)
 {
   g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
@@ -616,6 +661,10 @@ gbp_flatpak_configuration_get_property (GObject    *object,
       g_value_set_string (value, gbp_flatpak_configuration_get_branch (self));
       break;
 
+    case PROP_BUILD_ARGS:
+      g_value_set_boxed (value, gbp_flatpak_configuration_get_build_args (self));
+      break;
+
     case PROP_BUILD_COMMANDS:
       g_value_set_boxed (value, gbp_flatpak_configuration_get_build_commands (self));
       break;
@@ -667,6 +716,10 @@ gbp_flatpak_configuration_set_property (GObject      *object,
       gbp_flatpak_configuration_set_branch (self, g_value_get_string (value));
       break;
 
+    case PROP_BUILD_ARGS:
+      gbp_flatpak_configuration_set_build_args (self, g_value_get_boxed (value));
+      break;
+
     case PROP_BUILD_COMMANDS:
       gbp_flatpak_configuration_set_build_commands (self, g_value_get_boxed (value));
       break;
@@ -743,6 +796,15 @@ gbp_flatpak_configuration_class_init (GbpFlatpakConfigurationClass *klass)
                           G_PARAM_CONSTRUCT |
                           G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_BUILD_ARGS] =
+    g_param_spec_boxed ("build-args",
+                        "Build args",
+                        "Build args",
+                        G_TYPE_STRV,
+                        (G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT |
+                         G_PARAM_STATIC_STRINGS));
+
   properties [PROP_BUILD_COMMANDS] =
     g_param_spec_boxed ("build-commands",
                         "Build commands",
diff --git a/plugins/flatpak/gbp-flatpak-configuration.h b/plugins/flatpak/gbp-flatpak-configuration.h
index b6c0d86..c5f1b3d 100644
--- a/plugins/flatpak/gbp-flatpak-configuration.h
+++ b/plugins/flatpak/gbp-flatpak-configuration.h
@@ -41,6 +41,9 @@ void                      gbp_flatpak_configuration_set_build_commands        (G
 const gchar              *gbp_flatpak_configuration_get_command               (GbpFlatpakConfiguration 
*self);
 void                      gbp_flatpak_configuration_set_command               (GbpFlatpakConfiguration *self,
                                                                                const gchar             
*command);
+const gchar * const      *gbp_flatpak_configuration_get_build_args            (GbpFlatpakConfiguration 
*self);
+void                      gbp_flatpak_configuration_set_build_args            (GbpFlatpakConfiguration *self,
+                                                                               const gchar *const      
*build_args);
 const gchar * const      *gbp_flatpak_configuration_get_finish_args           (GbpFlatpakConfiguration 
*self);
 void                      gbp_flatpak_configuration_set_finish_args           (GbpFlatpakConfiguration *self,
                                                                                const gchar *const      
*finish_args);


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