[gnome-builder/wip/chergert/pipeline-merge] flatpak: Don't assume the config is a GbpFlatpakConfiguration



commit 17f21a25ec6a27f0fd603d4ccd1c16432ba5a9e6
Author: Matthew Leeds <mleeds redhat com>
Date:   Mon Feb 6 22:53:10 2017 -0600

    flatpak: Don't assume the config is a GbpFlatpakConfiguration
    
    If an IdeConfiguration (from buildconfig for example) is using a flatpak
    runtime, the pipeline should still be able to do most things. This commit
    changes GbpFlatpakPipelineAddin so it doesn't assume the configuration is
    a GbpFlatpakConfiguration by getting platform, branch, and sdk from the
    runtime instead and skipping parts of the pipeline (like building
    dependencies).

 plugins/flatpak/gbp-flatpak-pipeline-addin.c |   73 +++++++++++++++++++-------
 plugins/flatpak/gbp-flatpak-pipeline-addin.h |    9 +++
 plugins/flatpak/gbp-flatpak-runtime.c        |   69 ++++++++++++++++++++++--
 plugins/flatpak/gbp-flatpak-runtime.h        |   10 ++++
 4 files changed, 136 insertions(+), 25 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-pipeline-addin.c b/plugins/flatpak/gbp-flatpak-pipeline-addin.c
index e28800b..a0599d4 100644
--- a/plugins/flatpak/gbp-flatpak-pipeline-addin.c
+++ b/plugins/flatpak/gbp-flatpak-pipeline-addin.c
@@ -24,6 +24,8 @@
 #include "gbp-flatpak-util.h"
 #include "gbp-flatpak-configuration.h"
 
+G_DEFINE_QUARK (gb-flatpak-pipeline-error-quark, gb_flatpak_pipeline_error)
+
 enum {
   PREPARE_MKDIRS,
   PREPARE_BUILD_INIT,
@@ -85,6 +87,7 @@ register_remotes_stage (GbpFlatpakPipelineAddin  *self,
   g_autoptr(IdeBuildStage) stage = NULL;
   g_autoptr(IdeSubprocessLauncher) launcher = NULL;
   IdeConfiguration *config;
+  IdeRuntime *runtime;
   const gchar *branch;
   const gchar *platform;
   const gchar *sdk;
@@ -97,10 +100,20 @@ register_remotes_stage (GbpFlatpakPipelineAddin  *self,
   g_assert (IDE_IS_CONTEXT (context));
 
   config = ide_build_pipeline_get_configuration (pipeline);
+  runtime = ide_configuration_get_runtime (config);
 
-  platform = gbp_flatpak_configuration_get_platform (GBP_FLATPAK_CONFIGURATION (config));
-  sdk = gbp_flatpak_configuration_get_sdk (GBP_FLATPAK_CONFIGURATION (config));
-  branch = gbp_flatpak_configuration_get_branch (GBP_FLATPAK_CONFIGURATION (config));
+  if (!GBP_IS_FLATPAK_RUNTIME (runtime))
+    {
+      g_set_error (error,
+                   GB_FLATPAK_PIPELINE_ERROR,
+                   GB_FLATPAK_PIPELINE_ERROR_WRONG_RUNTIME,
+                   "Configuration changed to a non-flatpak runtime during pipeline initialization");
+      return FALSE;
+    }
+
+  platform = gbp_flatpak_runtime_get_platform (GBP_FLATPAK_RUNTIME (runtime));
+  sdk = gbp_flatpak_runtime_get_sdk (GBP_FLATPAK_RUNTIME (runtime));
+  branch = gbp_flatpak_runtime_get_branch (GBP_FLATPAK_RUNTIME (runtime));
 
   if (ide_str_equal0 (platform, "org.gnome.Platform") ||
       ide_str_equal0 (platform, "org.gnome.Sdk") ||
@@ -168,6 +181,7 @@ register_download_stage (GbpFlatpakPipelineAddin  *self,
                          GError                  **error)
 {
   IdeConfiguration *config;
+  IdeRuntime *runtime;
   const gchar *items[2] = { NULL };
   const gchar *platform;
   const gchar *sdk;
@@ -178,9 +192,20 @@ register_download_stage (GbpFlatpakPipelineAddin  *self,
   g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
 
   config = ide_build_pipeline_get_configuration (pipeline);
-  platform = gbp_flatpak_configuration_get_platform (GBP_FLATPAK_CONFIGURATION (config));
-  sdk = gbp_flatpak_configuration_get_sdk (GBP_FLATPAK_CONFIGURATION (config));
-  branch = gbp_flatpak_configuration_get_branch (GBP_FLATPAK_CONFIGURATION (config));
+  runtime = ide_configuration_get_runtime (config);
+
+  if (!GBP_IS_FLATPAK_RUNTIME (runtime))
+    {
+      g_set_error (error,
+                   GB_FLATPAK_PIPELINE_ERROR,
+                   GB_FLATPAK_PIPELINE_ERROR_WRONG_RUNTIME,
+                   "Configuration changed to a non-flatpak runtime during pipeline initialization");
+      return FALSE;
+    }
+
+  platform = gbp_flatpak_runtime_get_platform (GBP_FLATPAK_RUNTIME (runtime));
+  sdk = gbp_flatpak_runtime_get_sdk (GBP_FLATPAK_RUNTIME (runtime));
+  branch = gbp_flatpak_runtime_get_branch (GBP_FLATPAK_RUNTIME (runtime));
 
   items[0] = platform;
   items[1] = sdk;
@@ -247,6 +272,7 @@ register_build_init_stage (GbpFlatpakPipelineAddin  *self,
   g_autofree gchar *staging_dir = NULL;
   g_autofree gchar *metadata_path = NULL;
   IdeConfiguration *config;
+  IdeRuntime *runtime;
   const gchar *app_id;
   const gchar *platform;
   const gchar *sdk;
@@ -260,13 +286,22 @@ register_build_init_stage (GbpFlatpakPipelineAddin  *self,
   launcher = create_subprocess_launcher ();
 
   config = ide_build_pipeline_get_configuration (pipeline);
+  runtime = ide_configuration_get_runtime (config);
+
+  if (!GBP_IS_FLATPAK_RUNTIME (runtime))
+    {
+      g_set_error (error,
+                   GB_FLATPAK_PIPELINE_ERROR,
+                   GB_FLATPAK_PIPELINE_ERROR_WRONG_RUNTIME,
+                   "Configuration changed to a non-flatpak runtime during pipeline initialization");
+      return FALSE;
+    }
 
   staging_dir = gbp_flatpak_get_staging_dir (config);
   app_id = ide_configuration_get_app_id (config);
-  platform = gbp_flatpak_configuration_get_platform (GBP_FLATPAK_CONFIGURATION (config));
-  sdk = gbp_flatpak_configuration_get_sdk (GBP_FLATPAK_CONFIGURATION (config));
-  branch = gbp_flatpak_configuration_get_branch (GBP_FLATPAK_CONFIGURATION (config));
-
+  platform = gbp_flatpak_runtime_get_platform (GBP_FLATPAK_RUNTIME (runtime));
+  sdk = gbp_flatpak_runtime_get_sdk (GBP_FLATPAK_RUNTIME (runtime));
+  branch = gbp_flatpak_runtime_get_branch (GBP_FLATPAK_RUNTIME (runtime));
 
   if (platform == NULL && sdk == NULL)
     {
@@ -340,15 +375,15 @@ register_dependencies_stage (GbpFlatpakPipelineAddin  *self,
 
   config = ide_build_pipeline_get_configuration (pipeline);
 
-  primary_module = gbp_flatpak_configuration_get_primary_module (GBP_FLATPAK_CONFIGURATION (config));
-  manifest_path = gbp_flatpak_configuration_get_manifest_path (GBP_FLATPAK_CONFIGURATION (config));
-
   /* If there is no manifest, then there are no dependencies
    * to build for this configuration.
    */
-  if (manifest_path == NULL)
+  if (!GBP_IS_FLATPAK_CONFIGURATION (config))
     return TRUE;
 
+  primary_module = gbp_flatpak_configuration_get_primary_module (GBP_FLATPAK_CONFIGURATION (config));
+  manifest_path = gbp_flatpak_configuration_get_manifest_path (GBP_FLATPAK_CONFIGURATION (config));
+
   staging_dir = gbp_flatpak_get_staging_dir (config);
 
   launcher = create_subprocess_launcher ();
@@ -394,16 +429,16 @@ register_build_finish_stage (GbpFlatpakPipelineAddin  *self,
 
   config = ide_build_pipeline_get_configuration (pipeline);
 
-  manifest_path = gbp_flatpak_configuration_get_manifest_path (GBP_FLATPAK_CONFIGURATION (config));
-  command = gbp_flatpak_configuration_get_command (GBP_FLATPAK_CONFIGURATION (config));
-  finish_args = gbp_flatpak_configuration_get_finish_args (GBP_FLATPAK_CONFIGURATION (config));
-
   /* If there is no manifest, then there are no dependencies
    * to build for this configuration.
    */
-  if (manifest_path == NULL)
+  if (!GBP_IS_FLATPAK_CONFIGURATION (config))
     return TRUE;
 
+  manifest_path = gbp_flatpak_configuration_get_manifest_path (GBP_FLATPAK_CONFIGURATION (config));
+  command = gbp_flatpak_configuration_get_command (GBP_FLATPAK_CONFIGURATION (config));
+  finish_args = gbp_flatpak_configuration_get_finish_args (GBP_FLATPAK_CONFIGURATION (config));
+
   staging_dir = gbp_flatpak_get_staging_dir (config);
 
   launcher = create_subprocess_launcher ();
diff --git a/plugins/flatpak/gbp-flatpak-pipeline-addin.h b/plugins/flatpak/gbp-flatpak-pipeline-addin.h
index c6abf38..25b3b66 100644
--- a/plugins/flatpak/gbp-flatpak-pipeline-addin.h
+++ b/plugins/flatpak/gbp-flatpak-pipeline-addin.h
@@ -27,6 +27,15 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbpFlatpakPipelineAddin, gbp_flatpak_pipeline_addin, GBP, FLATPAK_PIPELINE_ADDIN, 
IdeObject)
 
+#define GB_FLATPAK_PIPELINE_ERROR (gb_flatpak_pipeline_error_quark())
+
+typedef enum
+{
+  GB_FLATPAK_PIPELINE_ERROR_WRONG_RUNTIME
+} GbFlatpakPipelineError;
+
+GQuark     gb_flatpak_pipeline_error_quark (void);
+
 G_END_DECLS
 
 #endif /* GBP_FLATPAK_PIPELINE_ADDIN_H */
diff --git a/plugins/flatpak/gbp-flatpak-runtime.c b/plugins/flatpak/gbp-flatpak-runtime.c
index 6503b32..d7f626e 100644
--- a/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/plugins/flatpak/gbp-flatpak-runtime.c
@@ -382,6 +382,63 @@ gbp_flatpak_runtime_translate_file (IdeRuntime *runtime,
   return NULL;
 }
 
+const gchar *
+gbp_flatpak_runtime_get_branch (GbpFlatpakRuntime *self)
+{
+  g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
+
+  return self->branch;
+}
+
+void
+gbp_flatpak_runtime_set_branch (GbpFlatpakRuntime *self,
+                                const gchar       *branch)
+{
+  g_return_if_fail (GBP_IS_FLATPAK_RUNTIME (self));
+
+  g_free (self->branch);
+  self->branch = g_strdup (branch);
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BRANCH]);
+}
+
+const gchar *
+gbp_flatpak_runtime_get_platform (GbpFlatpakRuntime *self)
+{
+  g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
+
+  return self->platform;
+}
+
+void
+gbp_flatpak_runtime_set_platform (GbpFlatpakRuntime *self,
+                                  const gchar       *platform)
+{
+  g_return_if_fail (GBP_IS_FLATPAK_RUNTIME (self));
+
+  g_free (self->platform);
+  self->platform = g_strdup (platform);
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PLATFORM]);
+}
+
+const gchar *
+gbp_flatpak_runtime_get_sdk (GbpFlatpakRuntime *self)
+{
+  g_return_val_if_fail (GBP_IS_FLATPAK_RUNTIME (self), NULL);
+
+  return self->sdk;
+}
+
+void
+gbp_flatpak_runtime_set_sdk (GbpFlatpakRuntime *self,
+                             const gchar       *sdk)
+{
+  g_return_if_fail (GBP_IS_FLATPAK_RUNTIME (self));
+
+  g_free (self->sdk);
+  self->sdk = g_strdup (sdk);
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SDK]);
+}
+
 static void
 gbp_flatpak_runtime_get_property (GObject    *object,
                                   guint       prop_id,
@@ -393,15 +450,15 @@ gbp_flatpak_runtime_get_property (GObject    *object,
   switch (prop_id)
     {
     case PROP_BRANCH:
-      g_value_set_string (value, self->branch);
+      g_value_set_string (value, gbp_flatpak_runtime_get_branch (self));
       break;
 
     case PROP_PLATFORM:
-      g_value_set_string (value, self->platform);
+      g_value_set_string (value, gbp_flatpak_runtime_get_platform (self));
       break;
 
     case PROP_SDK:
-      g_value_set_string (value, self->sdk);
+      g_value_set_string (value, gbp_flatpak_runtime_get_sdk (self));
       break;
 
     case PROP_DEPLOY_DIR:
@@ -424,15 +481,15 @@ gbp_flatpak_runtime_set_property (GObject      *object,
   switch (prop_id)
     {
     case PROP_BRANCH:
-      self->branch = g_value_dup_string (value);
+      gbp_flatpak_runtime_set_branch (self, g_value_get_string (value));
       break;
 
     case PROP_PLATFORM:
-      self->platform = g_value_dup_string (value);
+      gbp_flatpak_runtime_set_platform (self, g_value_get_string (value));
       break;
 
     case PROP_SDK:
-      self->sdk = g_value_dup_string (value);
+      gbp_flatpak_runtime_set_sdk (self, g_value_get_string (value));
       break;
 
     case PROP_DEPLOY_DIR:
diff --git a/plugins/flatpak/gbp-flatpak-runtime.h b/plugins/flatpak/gbp-flatpak-runtime.h
index 3579994..cc3e26c 100644
--- a/plugins/flatpak/gbp-flatpak-runtime.h
+++ b/plugins/flatpak/gbp-flatpak-runtime.h
@@ -29,6 +29,16 @@ G_DECLARE_FINAL_TYPE (GbpFlatpakRuntime, gbp_flatpak_runtime, GBP, FLATPAK_RUNTI
 
 #define FLATPAK_REPO_NAME "gnome-builder-builds"
 
+const gchar         *gbp_flatpak_runtime_get_branch   (GbpFlatpakRuntime *self);
+void                 gbp_flatpak_runtime_set_branch   (GbpFlatpakRuntime *self,
+                                                       const gchar *branch);
+const gchar         *gbp_flatpak_runtime_get_platform (GbpFlatpakRuntime *self);
+void                 gbp_flatpak_runtime_set_platform (GbpFlatpakRuntime *self,
+                                                       const gchar *platform);
+const gchar         *gbp_flatpak_runtime_get_sdk      (GbpFlatpakRuntime *self);
+void                 gbp_flatpak_runtime_set_sdk      (GbpFlatpakRuntime *self,
+                                                       const gchar *sdk);
+
 G_END_DECLS
 
 #endif /* GBP_FLATPAK_RUNTIME_H */


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