[gnome-builder] flatpak: Use build-commands field from manifest



commit 1fedcfe4cdd9bfb6b3077708c91d4bde3940e21e
Author: Matthew Leeds <mleeds redhat com>
Date:   Wed Mar 15 21:54:29 2017 -0500

    flatpak: Use build-commands field from manifest
    
    Flatpak manifests can specify shell commands to be run after "make" and
    before "make install" in the "build-commands" field of a module. This
    commit makes Builder read those and execute them by adding a pipeline stage.

 plugins/flatpak/gbp-flatpak-configuration.c  |   59 ++++++++++++++++++++++++++
 plugins/flatpak/gbp-flatpak-configuration.h  |    3 +
 plugins/flatpak/gbp-flatpak-pipeline-addin.c |   56 ++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 0 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-configuration.c b/plugins/flatpak/gbp-flatpak-configuration.c
index 1080890..4dff875 100644
--- a/plugins/flatpak/gbp-flatpak-configuration.c
+++ b/plugins/flatpak/gbp-flatpak-configuration.c
@@ -26,6 +26,7 @@ struct _GbpFlatpakConfiguration
   IdeConfiguration parent_instance;
 
   gchar  *branch;
+  gchar **build_commands;
   gchar  *command;
   gchar **finish_args;
   GFile  *manifest;
@@ -39,6 +40,7 @@ G_DEFINE_TYPE (GbpFlatpakConfiguration, gbp_flatpak_configuration, IDE_TYPE_CONF
 enum {
   PROP_0,
   PROP_BRANCH,
+  PROP_BUILD_COMMANDS,
   PROP_COMMAND,
   PROP_FINISH_ARGS,
   PROP_MANIFEST,
@@ -354,6 +356,23 @@ gbp_flatpak_configuration_load_from_file (GbpFlatpakConfiguration *self,
                 }
             }
         }
+      if (json_object_has_member (primary_module_object, "build-commands"))
+        {
+          JsonArray *build_commands_array;
+          GPtrArray *build_commands;
+          g_auto(GStrv) build_commands_strv = NULL;
+          build_commands = g_ptr_array_new ();
+          build_commands_array = json_object_get_array_member (primary_module_object, "build-commands");
+          for (guint i = 0; i < json_array_get_length (build_commands_array); i++)
+            {
+              const gchar *arg = json_array_get_string_element (build_commands_array, i);
+              if (!ide_str_empty0 (arg))
+                g_ptr_array_add (build_commands, g_strdup (arg));
+            }
+          g_ptr_array_add (build_commands, NULL);
+          build_commands_strv = (gchar **)g_ptr_array_free (build_commands, FALSE);
+          gbp_flatpak_configuration_set_build_commands (self, (const gchar * const *)build_commands_strv);
+        }
     }
 
   return TRUE;
@@ -378,6 +397,28 @@ gbp_flatpak_configuration_set_branch (GbpFlatpakConfiguration *self,
   g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BRANCH]);
 }
 
+const gchar * const *
+gbp_flatpak_configuration_get_build_commands (GbpFlatpakConfiguration *self)
+{
+  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
+
+  return (const gchar * const *)self->build_commands;
+}
+
+void
+gbp_flatpak_configuration_set_build_commands (GbpFlatpakConfiguration *self,
+                                              const gchar * const     *build_commands)
+{
+  g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));
+
+  if (self->build_commands != (gchar **)build_commands)
+    {
+      g_strfreev (self->build_commands);
+      self->build_commands = g_strdupv ((gchar **)build_commands);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUILD_COMMANDS]);
+    }
+}
+
 const gchar *
 gbp_flatpak_configuration_get_command (GbpFlatpakConfiguration *self)
 {
@@ -532,6 +573,10 @@ gbp_flatpak_configuration_get_property (GObject    *object,
       g_value_set_string (value, gbp_flatpak_configuration_get_branch (self));
       break;
 
+    case PROP_BUILD_COMMANDS:
+      g_value_set_boxed (value, gbp_flatpak_configuration_get_build_commands (self));
+      break;
+
     case PROP_COMMAND:
       g_value_set_string (value, gbp_flatpak_configuration_get_command (self));
       break;
@@ -575,6 +620,10 @@ gbp_flatpak_configuration_set_property (GObject      *object,
       gbp_flatpak_configuration_set_branch (self, g_value_get_string (value));
       break;
 
+    case PROP_BUILD_COMMANDS:
+      gbp_flatpak_configuration_set_build_commands (self, g_value_get_boxed (value));
+      break;
+
     case PROP_COMMAND:
       gbp_flatpak_configuration_set_command (self, g_value_get_string (value));
       break;
@@ -610,6 +659,7 @@ gbp_flatpak_configuration_finalize (GObject *object)
   GbpFlatpakConfiguration *self = (GbpFlatpakConfiguration *)object;
 
   g_clear_pointer (&self->branch, g_free);
+  g_clear_pointer (&self->build_commands, g_strfreev);
   g_clear_pointer (&self->command, g_free);
   g_clear_pointer (&self->finish_args, g_strfreev);
   g_clear_object (&self->manifest);
@@ -641,6 +691,15 @@ gbp_flatpak_configuration_class_init (GbpFlatpakConfigurationClass *klass)
                           G_PARAM_CONSTRUCT |
                           G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_BUILD_COMMANDS] =
+    g_param_spec_boxed ("build-commands",
+                        "Build commands",
+                        "Build commands",
+                        G_TYPE_STRV,
+                        (G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT |
+                         G_PARAM_STATIC_STRINGS));
+
   properties [PROP_COMMAND] =
     g_param_spec_string ("command",
                          "Command",
diff --git a/plugins/flatpak/gbp-flatpak-configuration.h b/plugins/flatpak/gbp-flatpak-configuration.h
index 10a961d..7595d0b 100644
--- a/plugins/flatpak/gbp-flatpak-configuration.h
+++ b/plugins/flatpak/gbp-flatpak-configuration.h
@@ -35,6 +35,9 @@ gboolean                  gbp_flatpak_configuration_load_from_file     (GbpFlatp
 const gchar              *gbp_flatpak_configuration_get_branch         (GbpFlatpakConfiguration *self);
 void                      gbp_flatpak_configuration_set_branch         (GbpFlatpakConfiguration *self,
                                                                         const gchar             *branch);
+const gchar * const      *gbp_flatpak_configuration_get_build_commands (GbpFlatpakConfiguration *self);
+void                      gbp_flatpak_configuration_set_build_commands (GbpFlatpakConfiguration *self,
+                                                                        const gchar *const      
*build_commands);
 const gchar              *gbp_flatpak_configuration_get_command        (GbpFlatpakConfiguration *self);
 void                      gbp_flatpak_configuration_set_command        (GbpFlatpakConfiguration *self,
                                                                         const gchar             *command);
diff --git a/plugins/flatpak/gbp-flatpak-pipeline-addin.c b/plugins/flatpak/gbp-flatpak-pipeline-addin.c
index 958fd03..a729f25 100644
--- a/plugins/flatpak/gbp-flatpak-pipeline-addin.c
+++ b/plugins/flatpak/gbp-flatpak-pipeline-addin.c
@@ -352,6 +352,61 @@ register_dependencies_stage (GbpFlatpakPipelineAddin  *self,
 }
 
 static gboolean
+register_build_commands_stage (GbpFlatpakPipelineAddin  *self,
+                               IdeBuildPipeline         *pipeline,
+                               IdeContext               *context,
+                               GError                  **error)
+{
+  g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+  g_autoptr(IdeBuildStage) stage = NULL;
+  IdeConfiguration *config;
+  guint stage_id;
+  const gchar * const *build_commands;
+  const gchar *builddir;
+
+  g_assert (GBP_IS_FLATPAK_PIPELINE_ADDIN (self));
+  g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
+  g_assert (IDE_IS_CONTEXT (context));
+
+  config = ide_build_pipeline_get_configuration (pipeline);
+  if (!GBP_IS_FLATPAK_CONFIGURATION (config))
+    return TRUE;
+
+  launcher = create_subprocess_launcher ();
+
+  ide_subprocess_launcher_push_argv (launcher, "/bin/sh");
+  ide_subprocess_launcher_push_argv (launcher, "-c");
+
+  build_commands = gbp_flatpak_configuration_get_build_commands (GBP_FLATPAK_CONFIGURATION (config));
+  if (build_commands == NULL)
+    return TRUE;
+  else
+    {
+      /* Join the commands so we can use one launcher */
+      g_autofree gchar *build_commands_joined = NULL;
+      build_commands_joined = g_strjoinv (" && ", (gchar **)build_commands);
+      ide_subprocess_launcher_push_argv (launcher, build_commands_joined);
+    }
+
+  builddir = ide_build_pipeline_get_builddir (pipeline);
+  if (builddir != NULL)
+    ide_subprocess_launcher_set_cwd (launcher, builddir);
+
+  stage = g_object_new (IDE_TYPE_BUILD_STAGE_LAUNCHER,
+                        "context", context,
+                        "launcher", launcher,
+                        NULL);
+
+  stage_id = ide_build_pipeline_connect (pipeline,
+                                         IDE_BUILD_PHASE_BUILD | IDE_BUILD_PHASE_AFTER,
+                                         0,
+                                         stage);
+  ide_build_pipeline_addin_track (IDE_BUILD_PIPELINE_ADDIN (self), stage_id);
+
+  return TRUE;
+}
+
+static gboolean
 register_build_finish_stage (GbpFlatpakPipelineAddin  *self,
                              IdeBuildPipeline         *pipeline,
                              IdeContext               *context,
@@ -521,6 +576,7 @@ gbp_flatpak_pipeline_addin_load (IdeBuildPipelineAddin *addin,
       !register_build_init_stage (self, pipeline, context, &error) ||
       !register_downloads_stage (self, pipeline, context, &error) ||
       !register_dependencies_stage (self, pipeline, context, &error) ||
+      !register_build_commands_stage (self, pipeline, context, &error) ||
       !register_build_finish_stage (self, pipeline, context, &error) ||
       !register_build_bundle_stage (self, pipeline, context, &error))
     g_warning ("%s", error->message);


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