[gnome-builder] flatpak: implement get_extensions vfunc



commit c2510c438b6986eb527ee513c2bade7688a9a23a
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 1 17:43:32 2019 -0700

    flatpak: implement get_extensions vfunc
    
    This allows other plumbing to check SDK extensions for programs.

 .../flatpak/gbp-flatpak-application-addin.c        | 35 ++++++++++++++--
 .../flatpak/gbp-flatpak-application-addin.h        |  2 +
 src/plugins/flatpak/gbp-flatpak-manifest.c         | 49 ++++++++++++++++++++++
 src/plugins/flatpak/gbp-flatpak-runtime-provider.c |  2 +-
 src/plugins/flatpak/gbp-flatpak-runtime.c          | 10 +++--
 src/plugins/flatpak/gbp-flatpak-runtime.h          |  1 +
 6 files changed, 91 insertions(+), 8 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-application-addin.c 
b/src/plugins/flatpak/gbp-flatpak-application-addin.c
index 8b74c4b1a..41468475a 100644
--- a/src/plugins/flatpak/gbp-flatpak-application-addin.c
+++ b/src/plugins/flatpak/gbp-flatpak-application-addin.c
@@ -28,6 +28,7 @@
 #include <libide-gui.h>
 #include <errno.h>
 #include <flatpak.h>
+#include <string.h>
 #include <unistd.h>
 
 #include "gbp-flatpak-application-addin.h"
@@ -1344,10 +1345,16 @@ gbp_flatpak_application_addin_find_ref (GbpFlatpakApplicationAddin *self,
             {
               FlatpakRef *ref = g_ptr_array_index (ar, j);
 
-              if (g_strcmp0 (id, flatpak_ref_get_name (ref)) == 0 &&
-                  g_strcmp0 (arch, flatpak_ref_get_arch (ref)) == 0 &&
-                  g_strcmp0 (branch, flatpak_ref_get_branch (ref)) == 0)
-                return g_object_ref (FLATPAK_INSTALLED_REF (ref));
+              if (g_strcmp0 (id, flatpak_ref_get_name (ref)) != 0)
+                continue;
+
+              if (arch && g_strcmp0 (arch, flatpak_ref_get_arch (ref)) != 0)
+                continue;
+
+              if (branch && g_strcmp0 (branch, flatpak_ref_get_branch (ref)) != 0)
+                continue;
+
+              return g_object_ref (FLATPAK_INSTALLED_REF (ref));
             }
         }
     }
@@ -1468,3 +1475,23 @@ gbp_flatpak_application_addin_check_sysdeps_finish (GbpFlatpakApplicationAddin
 
   IDE_RETURN (ret);
 }
+
+FlatpakInstalledRef *
+gbp_flatpak_application_addin_find_extension (GbpFlatpakApplicationAddin *self,
+                                              const gchar                *name)
+{
+  g_autofree gchar *pname = NULL;
+  g_autofree gchar *parch = NULL;
+  g_autofree gchar *pversion = NULL;
+
+  g_return_val_if_fail (GBP_IS_FLATPAK_APPLICATION_ADDIN (self), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+
+  if (strchr (name, '/') != NULL)
+    {
+      if (gbp_flatpak_split_id (name, &pname, &parch, &pversion))
+        return gbp_flatpak_application_addin_find_ref (self, pname, parch, pversion);
+    }
+
+  return gbp_flatpak_application_addin_find_ref (self, name, NULL, NULL);
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-application-addin.h 
b/src/plugins/flatpak/gbp-flatpak-application-addin.h
index ce4ae7820..aa81813ef 100644
--- a/src/plugins/flatpak/gbp-flatpak-application-addin.h
+++ b/src/plugins/flatpak/gbp-flatpak-application-addin.h
@@ -30,6 +30,8 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GbpFlatpakApplicationAddin, gbp_flatpak_application_addin, GBP, 
FLATPAK_APPLICATION_ADDIN, GObject)
 
 GbpFlatpakApplicationAddin *gbp_flatpak_application_addin_get_default            (void);
+FlatpakInstalledRef        *gbp_flatpak_application_addin_find_extension         (GbpFlatpakApplicationAddin 
 *self,
+                                                                                  const gchar                
 *name);
 GPtrArray                  *gbp_flatpak_application_addin_get_runtimes           (GbpFlatpakApplicationAddin 
 *self);
 GPtrArray                  *gbp_flatpak_application_addin_get_installations      (GbpFlatpakApplicationAddin 
 *self);
 gboolean                    gbp_flatpak_application_addin_has_runtime            (GbpFlatpakApplicationAddin 
 *self,
diff --git a/src/plugins/flatpak/gbp-flatpak-manifest.c b/src/plugins/flatpak/gbp-flatpak-manifest.c
index faaeae1e6..07d8ff3e9 100644
--- a/src/plugins/flatpak/gbp-flatpak-manifest.c
+++ b/src/plugins/flatpak/gbp-flatpak-manifest.c
@@ -551,6 +551,54 @@ gbp_flatpak_manifest_set_file (GbpFlatpakManifest *self,
                            G_CONNECT_SWAPPED);
 }
 
+static IdeRuntime *
+find_extension (GbpFlatpakManifest *self,
+                const gchar        *name)
+{
+  g_autoptr(FlatpakInstalledRef) ref = NULL;
+  GbpFlatpakApplicationAddin *addin;
+  GbpFlatpakRuntime *ret = NULL;
+
+  g_assert (GBP_IS_FLATPAK_MANIFEST (self));
+  g_assert (name != NULL);
+
+  /* TODO: This doesn't allow pinning to the right version
+   * of extension because we need to know the right parent
+   * version of the extension.
+   */
+  addin = gbp_flatpak_application_addin_get_default ();
+  ref = gbp_flatpak_application_addin_find_extension (addin, name);
+
+  if (ref != NULL)
+    ret = gbp_flatpak_runtime_new (ref, TRUE, NULL, NULL);
+
+  return IDE_RUNTIME (g_steal_pointer (&ret));
+}
+
+static GPtrArray *
+gbp_flatpak_manifest_get_extensions (IdeConfig *config)
+{
+  GbpFlatpakManifest *self = (GbpFlatpakManifest *)config;
+  GPtrArray *ret;
+
+  g_assert (GBP_IS_FLATPAK_MANIFEST (self));
+
+  ret = g_ptr_array_new ();
+
+  if (self->sdk_extensions != NULL)
+    {
+      for (guint i = 0; self->sdk_extensions[i]; i++)
+        {
+          IdeRuntime *found = find_extension (self, self->sdk_extensions[i]);
+
+          if (found)
+            g_ptr_array_add (ret, g_steal_pointer (&found));
+        }
+    }
+
+  return g_steal_pointer (&ret);
+}
+
 static void
 gbp_flatpak_manifest_finalize (GObject *object)
 {
@@ -624,6 +672,7 @@ gbp_flatpak_manifest_class_init (GbpFlatpakManifestClass *klass)
   object_class->get_property = gbp_flatpak_manifest_get_property;
   object_class->set_property = gbp_flatpak_manifest_set_property;
 
+  config_class->get_extensions = gbp_flatpak_manifest_get_extensions;
   config_class->supports_runtime = gbp_flatpak_manifest_supports_runtime;
 
   properties [PROP_FILE] =
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c 
b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
index f49ddb9b7..725a4bf4c 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -169,7 +169,7 @@ 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, NULL, &error);
+  new_runtime = gbp_flatpak_runtime_new (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 f6a516ca6..9b86647e7 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.c
@@ -763,6 +763,7 @@ locate_deploy_dir (const gchar *sdk_id)
 
 GbpFlatpakRuntime *
 gbp_flatpak_runtime_new (FlatpakInstalledRef  *ref,
+                         gboolean              is_extension,
                          GCancellable         *cancellable,
                          GError              **error)
 {
@@ -814,7 +815,7 @@ gbp_flatpak_runtime_new (FlatpakInstalledRef  *ref,
   if (!g_key_file_load_from_bytes (keyfile, metadata, 0, error))
     return NULL;
 
-  if (g_key_file_has_group (keyfile, "ExtensionOf"))
+  if (g_key_file_has_group (keyfile, "ExtensionOf") && !is_extension)
     {
       g_set_error (error,
                    G_IO_ERROR,
@@ -836,8 +837,11 @@ gbp_flatpak_runtime_new (FlatpakInstalledRef  *ref,
    * If we have an SDK that is different from this runtime, we need to locate
    * the SDK deploy-dir instead (for things like includes, pkg-config, etc).
    */
-  if (sdk != NULL && !g_str_equal (sdk, triplet) && NULL != (sdk_deploy_dir = locate_deploy_dir (sdk)))
-    deploy_dir = sdk_deploy_dir;
+  if (!is_extension)
+    {
+      if (sdk != NULL && !g_str_equal (sdk, triplet) && NULL != (sdk_deploy_dir = locate_deploy_dir (sdk)))
+        deploy_dir = sdk_deploy_dir;
+    }
 
   return g_object_new (GBP_TYPE_FLATPAK_RUNTIME,
                        "id", id,
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.h b/src/plugins/flatpak/gbp-flatpak-runtime.h
index b41705ee0..af9923ce2 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.h
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GbpFlatpakRuntime, gbp_flatpak_runtime, GBP, FLATPAK_RUNTIME, IdeRuntime)
 
 GbpFlatpakRuntime   *gbp_flatpak_runtime_new          (FlatpakInstalledRef  *ref,
+                                                       gboolean              is_extension,
                                                        GCancellable         *cancellable,
                                                        GError              **error);
 IdeTriplet          *gbp_flatpak_runtime_get_triplet  (GbpFlatpakRuntime    *self);


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