[gnome-builder] flatpak: Use post-install field from manifest



commit 1da421defb05727f61b515c3b79ca10d295f028e
Author: Matthew Leeds <mleeds redhat com>
Date:   Wed Mar 15 23:54:44 2017 -0500

    flatpak: Use post-install field from manifest
    
    Flatpak manifests can specify shell commands to be run after "make install"
    in the "post-install" field of a module. This commit makes Builder read
    those and execute them by adding a pipeline stage. Ideally it might
    share more code with the processing of the build commands and finish
    args.

 plugins/flatpak/gbp-flatpak-configuration.c  |   59 ++++++++++++++++++++++++++
 plugins/flatpak/gbp-flatpak-configuration.h  |   59 +++++++++++++------------
 plugins/flatpak/gbp-flatpak-pipeline-addin.c |   56 ++++++++++++++++++++++++
 3 files changed, 146 insertions(+), 28 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-configuration.c b/plugins/flatpak/gbp-flatpak-configuration.c
index 4dff875..8d291af 100644
--- a/plugins/flatpak/gbp-flatpak-configuration.c
+++ b/plugins/flatpak/gbp-flatpak-configuration.c
@@ -31,6 +31,7 @@ struct _GbpFlatpakConfiguration
   gchar **finish_args;
   GFile  *manifest;
   gchar  *platform;
+  gchar **post_install_commands;
   gchar  *primary_module;
   gchar  *sdk;
 };
@@ -45,6 +46,7 @@ enum {
   PROP_FINISH_ARGS,
   PROP_MANIFEST,
   PROP_PLATFORM,
+  PROP_POST_INSTALL_COMMANDS,
   PROP_PRIMARY_MODULE,
   PROP_SDK,
   N_PROPS
@@ -373,6 +375,23 @@ gbp_flatpak_configuration_load_from_file (GbpFlatpakConfiguration *self,
           build_commands_strv = (gchar **)g_ptr_array_free (build_commands, FALSE);
           gbp_flatpak_configuration_set_build_commands (self, (const gchar * const *)build_commands_strv);
         }
+      if (json_object_has_member (primary_module_object, "post-install"))
+        {
+          JsonArray *post_install_commands_array;
+          GPtrArray *post_install_commands;
+          g_auto(GStrv) post_install_commands_strv = NULL;
+          post_install_commands = g_ptr_array_new ();
+          post_install_commands_array = json_object_get_array_member (primary_module_object, "post-install");
+          for (guint i = 0; i < json_array_get_length (post_install_commands_array); i++)
+            {
+              const gchar *arg = json_array_get_string_element (post_install_commands_array, i);
+              if (!ide_str_empty0 (arg))
+                g_ptr_array_add (post_install_commands, g_strdup (arg));
+            }
+          g_ptr_array_add (post_install_commands, NULL);
+          post_install_commands_strv = (gchar **)g_ptr_array_free (post_install_commands, FALSE);
+          gbp_flatpak_configuration_set_post_install_commands (self, (const gchar * const 
*)post_install_commands_strv);
+        }
     }
 
   return TRUE;
@@ -508,6 +527,28 @@ gbp_flatpak_configuration_set_platform (GbpFlatpakConfiguration *self,
   g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PLATFORM]);
 }
 
+const gchar * const *
+gbp_flatpak_configuration_get_post_install_commands (GbpFlatpakConfiguration *self)
+{
+  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);
+
+  return (const gchar * const *)self->post_install_commands;
+}
+
+void
+gbp_flatpak_configuration_set_post_install_commands (GbpFlatpakConfiguration *self,
+                                                     const gchar * const     *post_install_commands)
+{
+  g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));
+
+  if (self->post_install_commands != (gchar **)post_install_commands)
+    {
+      g_strfreev (self->post_install_commands);
+      self->post_install_commands = g_strdupv ((gchar **)post_install_commands);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_POST_INSTALL_COMMANDS]);
+    }
+}
+
 const gchar *
 gbp_flatpak_configuration_get_primary_module (GbpFlatpakConfiguration *self)
 {
@@ -593,6 +634,10 @@ gbp_flatpak_configuration_get_property (GObject    *object,
       g_value_set_string (value, gbp_flatpak_configuration_get_platform (self));
       break;
 
+    case PROP_POST_INSTALL_COMMANDS:
+      g_value_set_boxed (value, gbp_flatpak_configuration_get_post_install_commands (self));
+      break;
+
     case PROP_PRIMARY_MODULE:
       g_value_set_string (value, gbp_flatpak_configuration_get_primary_module (self));
       break;
@@ -640,6 +685,10 @@ gbp_flatpak_configuration_set_property (GObject      *object,
       gbp_flatpak_configuration_set_platform (self, g_value_get_string (value));
       break;
 
+    case PROP_POST_INSTALL_COMMANDS:
+      gbp_flatpak_configuration_set_post_install_commands (self, g_value_get_boxed (value));
+      break;
+
     case PROP_PRIMARY_MODULE:
       gbp_flatpak_configuration_set_primary_module (self, g_value_get_string (value));
       break;
@@ -664,6 +713,7 @@ gbp_flatpak_configuration_finalize (GObject *object)
   g_clear_pointer (&self->finish_args, g_strfreev);
   g_clear_object (&self->manifest);
   g_clear_pointer (&self->platform, g_free);
+  g_clear_pointer (&self->post_install_commands, g_strfreev);
   g_clear_pointer (&self->primary_module, g_free);
   g_clear_pointer (&self->sdk, g_free);
 
@@ -736,6 +786,15 @@ gbp_flatpak_configuration_class_init (GbpFlatpakConfigurationClass *klass)
                           G_PARAM_CONSTRUCT |
                           G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_POST_INSTALL_COMMANDS] =
+    g_param_spec_boxed ("post-install-commands",
+                        "Post install commands",
+                        "Post install commands",
+                        G_TYPE_STRV,
+                        (G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT |
+                         G_PARAM_STATIC_STRINGS));
+
   properties [PROP_PRIMARY_MODULE] =
     g_param_spec_string ("primary-module",
                          "Primary module",
diff --git a/plugins/flatpak/gbp-flatpak-configuration.h b/plugins/flatpak/gbp-flatpak-configuration.h
index 7595d0b..b6c0d86 100644
--- a/plugins/flatpak/gbp-flatpak-configuration.h
+++ b/plugins/flatpak/gbp-flatpak-configuration.h
@@ -27,34 +27,37 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbpFlatpakConfiguration, gbp_flatpak_configuration, GBP, FLATPAK_CONFIGURATION, 
IdeConfiguration)
 
-GbpFlatpakConfiguration  *gbp_flatpak_configuration_new                (IdeContext              *context,
-                                                                        const gchar             *id,
-                                                                        const gchar             
*display_name);
-gboolean                  gbp_flatpak_configuration_load_from_file     (GbpFlatpakConfiguration *self,
-                                                                        GFile                   *manifest);
-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);
-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);
-GFile                    *gbp_flatpak_configuration_get_manifest       (GbpFlatpakConfiguration *self);
-gchar                    *gbp_flatpak_configuration_get_manifest_path  (GbpFlatpakConfiguration *self);
-const gchar              *gbp_flatpak_configuration_get_platform       (GbpFlatpakConfiguration *self);
-void                      gbp_flatpak_configuration_set_platform       (GbpFlatpakConfiguration *self,
-                                                                        const gchar             *platform);
-const gchar              *gbp_flatpak_configuration_get_primary_module (GbpFlatpakConfiguration *self);
-void                      gbp_flatpak_configuration_set_primary_module (GbpFlatpakConfiguration *self,
-                                                                        const gchar             
*primary_module);
-const gchar              *gbp_flatpak_configuration_get_sdk            (GbpFlatpakConfiguration *self);
-void                      gbp_flatpak_configuration_set_sdk            (GbpFlatpakConfiguration *self,
-                                                                        const gchar             *sdk);
+GbpFlatpakConfiguration  *gbp_flatpak_configuration_new                       (IdeContext              
*context,
+                                                                               const gchar             *id,
+                                                                               const gchar             
*display_name);
+gboolean                  gbp_flatpak_configuration_load_from_file            (GbpFlatpakConfiguration *self,
+                                                                               GFile                   
*manifest);
+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);
+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);
+GFile                    *gbp_flatpak_configuration_get_manifest              (GbpFlatpakConfiguration 
*self);
+gchar                    *gbp_flatpak_configuration_get_manifest_path         (GbpFlatpakConfiguration 
*self);
+const gchar              *gbp_flatpak_configuration_get_platform              (GbpFlatpakConfiguration 
*self);
+void                      gbp_flatpak_configuration_set_platform              (GbpFlatpakConfiguration *self,
+                                                                               const gchar             
*platform);
+const gchar * const      *gbp_flatpak_configuration_get_post_install_commands (GbpFlatpakConfiguration 
*self);
+void                      gbp_flatpak_configuration_set_post_install_commands (GbpFlatpakConfiguration *self,
+                                                                               const gchar *const      
*post_install_commands);
+const gchar              *gbp_flatpak_configuration_get_primary_module        (GbpFlatpakConfiguration 
*self);
+void                      gbp_flatpak_configuration_set_primary_module        (GbpFlatpakConfiguration *self,
+                                                                               const gchar             
*primary_module);
+const gchar              *gbp_flatpak_configuration_get_sdk                   (GbpFlatpakConfiguration 
*self);
+void                      gbp_flatpak_configuration_set_sdk                   (GbpFlatpakConfiguration *self,
+                                                                               const gchar             *sdk);
 G_END_DECLS
 
 #endif /* GBP_FLATPAK_CONFIGURATION_H */
diff --git a/plugins/flatpak/gbp-flatpak-pipeline-addin.c b/plugins/flatpak/gbp-flatpak-pipeline-addin.c
index a729f25..0a8be15 100644
--- a/plugins/flatpak/gbp-flatpak-pipeline-addin.c
+++ b/plugins/flatpak/gbp-flatpak-pipeline-addin.c
@@ -407,6 +407,61 @@ register_build_commands_stage (GbpFlatpakPipelineAddin  *self,
 }
 
 static gboolean
+register_post_install_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 *post_install_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");
+
+  post_install_commands = gbp_flatpak_configuration_get_post_install_commands (GBP_FLATPAK_CONFIGURATION 
(config));
+  if (post_install_commands == NULL)
+    return TRUE;
+  else
+    {
+      /* Join the commands so we can use one launcher */
+      g_autofree gchar *post_install_commands_joined = NULL;
+      post_install_commands_joined = g_strjoinv (" && ", (gchar **)post_install_commands);
+      ide_subprocess_launcher_push_argv (launcher, post_install_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_INSTALL | 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,
@@ -577,6 +632,7 @@ gbp_flatpak_pipeline_addin_load (IdeBuildPipelineAddin *addin,
       !register_downloads_stage (self, pipeline, context, &error) ||
       !register_dependencies_stage (self, pipeline, context, &error) ||
       !register_build_commands_stage (self, pipeline, context, &error) ||
+      !register_post_install_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]