[gnome-builder] flatpak: remove use of FlatpakRef from runtime



commit f40a836c1e55e01894564df0f97fb37b4bf9f4a6
Author: Christian Hergert <chergert redhat com>
Date:   Fri Apr 30 16:49:50 2021 -0700

    flatpak: remove use of FlatpakRef from runtime
    
    If we're going to start removing more and more of the libflatpak usage
    from the UI process, we need to weed out the usage here first and then
    slowly pull the curtains back from other modules.

 src/plugins/flatpak/gbp-flatpak-manifest.c         |  8 +++++-
 src/plugins/flatpak/gbp-flatpak-runtime-provider.c |  8 +++++-
 src/plugins/flatpak/gbp-flatpak-runtime.c          | 30 +++++++++-------------
 src/plugins/flatpak/gbp-flatpak-runtime.h          |  7 +++--
 4 files changed, 31 insertions(+), 22 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-manifest.c b/src/plugins/flatpak/gbp-flatpak-manifest.c
index 4ec0a325e..5ddc67fd6 100644
--- a/src/plugins/flatpak/gbp-flatpak-manifest.c
+++ b/src/plugins/flatpak/gbp-flatpak-manifest.c
@@ -560,6 +560,7 @@ find_extension (GbpFlatpakManifest *self,
   IpcFlatpakService *service;
   GbpFlatpakClient *client;
   IdeContext *context;
+  g_autoptr(GBytes) bytes = NULL;
 
   g_assert (GBP_IS_FLATPAK_MANIFEST (self));
   g_assert (name != NULL);
@@ -573,7 +574,12 @@ find_extension (GbpFlatpakManifest *self,
       addin = gbp_flatpak_application_addin_get_default ();
       ref = gbp_flatpak_application_addin_find_extension (addin, self->sdk, name);
       if (ref != NULL)
-        ret = gbp_flatpak_runtime_new (ref, TRUE, NULL, NULL);
+        ret = gbp_flatpak_runtime_new (flatpak_ref_get_name (FLATPAK_REF (ref)),
+                                       flatpak_ref_get_arch (FLATPAK_REF (ref)),
+                                       flatpak_ref_get_branch (FLATPAK_REF (ref)),
+                                       (bytes = flatpak_installed_ref_load_metadata (ref, NULL, NULL)),
+                                       flatpak_installed_ref_get_deploy_dir (ref),
+                                       TRUE, NULL, NULL);
     }
 
   return IDE_RUNTIME (g_steal_pointer (&ret));
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c 
b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
index 244863401..7db32dad2 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -139,6 +139,7 @@ runtime_added_cb (GbpFlatpakRuntimeProvider  *self,
                   GbpFlatpakApplicationAddin *app_addin)
 {
   g_autoptr(GbpFlatpakRuntime) new_runtime = NULL;
+  g_autoptr(GBytes) bytes = NULL;
   g_autoptr(GError) error = NULL;
   const gchar *name;
 
@@ -170,7 +171,12 @@ runtime_added_cb (GbpFlatpakRuntimeProvider  *self,
    * We didn't already have this runtime, so go ahead and just
    * add it now (and keep a copy so we can find it later).
    */
-  new_runtime = gbp_flatpak_runtime_new (ref, FALSE, NULL, &error);
+  new_runtime = gbp_flatpak_runtime_new (flatpak_ref_get_name (FLATPAK_REF (ref)),
+                                         flatpak_ref_get_arch (FLATPAK_REF (ref)),
+                                         flatpak_ref_get_branch (FLATPAK_REF (ref)),
+                                         (bytes = flatpak_installed_ref_load_metadata (ref, NULL, NULL)),
+                                         flatpak_installed_ref_get_deploy_dir (ref),
+                                         FALSE, NULL, &error);
 
   if (new_runtime == NULL)
     {
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.c b/src/plugins/flatpak/gbp-flatpak-runtime.c
index ef0c61e81..273416492 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.c
@@ -726,13 +726,16 @@ locate_deploy_dir (const gchar *sdk_id)
 }
 
 GbpFlatpakRuntime *
-gbp_flatpak_runtime_new (FlatpakInstalledRef  *ref,
-                         gboolean              is_extension,
-                         GCancellable         *cancellable,
-                         GError              **error)
+gbp_flatpak_runtime_new (const char    *name,
+                         const char    *arch,
+                         const char    *branch,
+                         GBytes        *metadata,
+                         const char    *deploy_dir,
+                         gboolean       is_extension,
+                         GCancellable  *cancellable,
+                         GError       **error)
 {
   g_autofree gchar *sdk_deploy_dir = NULL;
-  g_autoptr(GBytes) metadata = NULL;
   g_autoptr(GKeyFile) keyfile = NULL;
   g_autofree gchar *sdk = NULL;
   g_autofree gchar *id = NULL;
@@ -741,19 +744,13 @@ gbp_flatpak_runtime_new (FlatpakInstalledRef  *ref,
   g_autofree gchar *runtime_name = NULL;
   g_autoptr(IdeTriplet) triplet_object = NULL;
   g_autoptr(GString) category = NULL;
-  const gchar *name;
-  const gchar *arch;
-  const gchar *branch;
-  const gchar *deploy_dir;
 
-  g_return_val_if_fail (FLATPAK_IS_INSTALLED_REF (ref), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+  g_return_val_if_fail (branch != NULL, NULL);
+  g_return_val_if_fail (arch != NULL, NULL);
+  g_return_val_if_fail (deploy_dir != NULL, NULL);
   g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
 
-  arch = flatpak_ref_get_arch (FLATPAK_REF (ref));
-
-  name = flatpak_ref_get_name (FLATPAK_REF (ref));
-  branch = flatpak_ref_get_branch (FLATPAK_REF (ref));
-  deploy_dir = flatpak_installed_ref_get_deploy_dir (ref);
   triplet_object = ide_triplet_new (arch);
   triplet = g_strdup_printf ("%s/%s/%s", name, arch, branch);
   id = g_strdup_printf ("flatpak:%s", triplet);
@@ -772,9 +769,6 @@ gbp_flatpak_runtime_new (FlatpakInstalledRef  *ref,
   else
     g_string_append_printf (category, "%s (%s)", name, arch);
 
-  if (!(metadata = flatpak_installed_ref_load_metadata (ref, cancellable, error)))
-    return NULL;
-
   keyfile = g_key_file_new ();
   if (!g_key_file_load_from_bytes (keyfile, metadata, 0, error))
     return NULL;
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.h b/src/plugins/flatpak/gbp-flatpak-runtime.h
index af9923ce2..a5ed8949f 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.h
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.h
@@ -20,7 +20,6 @@
 
 #pragma once
 
-#include <flatpak.h>
 #include <libide-foundry.h>
 
 G_BEGIN_DECLS
@@ -29,7 +28,11 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbpFlatpakRuntime, gbp_flatpak_runtime, GBP, FLATPAK_RUNTIME, IdeRuntime)
 
-GbpFlatpakRuntime   *gbp_flatpak_runtime_new          (FlatpakInstalledRef  *ref,
+GbpFlatpakRuntime   *gbp_flatpak_runtime_new          (const char           *name,
+                                                       const char           *arch,
+                                                       const char           *branch,
+                                                       GBytes               *metadata,
+                                                       const char           *deploy_dir,
                                                        gboolean              is_extension,
                                                        GCancellable         *cancellable,
                                                        GError              **error);


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