[gnome-builder] plugins/host: add noop runtime



commit 968caefb108f3e62f2840cc29a69cf9f32705a6d
Author: Christian Hergert <chergert redhat com>
Date:   Wed Sep 28 21:09:20 2022 -0700

    plugins/host: add noop runtime
    
    This allows using the bundled runtime of Builder when running from Flatpak
    as a build runtime target for applications. It's simpler than selecting
    a Flatpak runtime directly as it does not require trampolining through
    the host to the Flatpak runtime.
    
    Mostly just for small testing where you don't have another pet container
    setup to be used.
    
    Related #1826

 src/plugins/host/gbp-host-runtime-provider.c | 40 +++++++++----
 src/plugins/host/gbp-host-runtime.c          | 20 +++++--
 src/plugins/host/gbp-host-runtime.h          |  3 +
 src/plugins/host/gbp-noop-runtime.c          | 87 ++++++++++++++++++++++++++++
 src/plugins/host/gbp-noop-runtime.h          | 31 ++++++++++
 src/plugins/host/meson.build                 |  1 +
 6 files changed, 167 insertions(+), 15 deletions(-)
---
diff --git a/src/plugins/host/gbp-host-runtime-provider.c b/src/plugins/host/gbp-host-runtime-provider.c
index 27b395d13..cb33d71aa 100644
--- a/src/plugins/host/gbp-host-runtime-provider.c
+++ b/src/plugins/host/gbp-host-runtime-provider.c
@@ -28,11 +28,13 @@
 
 #include "gbp-host-runtime.h"
 #include "gbp-host-runtime-provider.h"
+#include "gbp-noop-runtime.h"
 
 struct _GbpHostRuntimeProvider
 {
   IdeObject       parent_instance;
-  GbpHostRuntime *runtime;
+  GbpHostRuntime *host;
+  GbpNoopRuntime *noop;
 };
 
 static void
@@ -47,13 +49,28 @@ gbp_host_runtime_provider_load (IdeRuntimeProvider *provider,
   g_assert (GBP_IS_HOST_RUNTIME_PROVIDER (self));
   g_assert (IDE_IS_RUNTIME_MANAGER (runtime_manager));
 
-  self->runtime = g_object_new (GBP_TYPE_HOST_RUNTIME,
-                                "id", "host",
-                                "name", _("Host Operating System"),
-                                "category", _("Host System"),
-                                "parent", self,
-                                NULL);
-  ide_runtime_manager_add (runtime_manager, IDE_RUNTIME (self->runtime));
+  self->host = g_object_new (GBP_TYPE_HOST_RUNTIME,
+                             "id", "host",
+                             "name", _("Host Operating System"),
+                             "category", _("Host System"),
+                             "parent", self,
+                             NULL);
+  ide_runtime_manager_add (runtime_manager, IDE_RUNTIME (self->host));
+
+  if (ide_is_flatpak ())
+    {
+      /* Allow using Builder itself as a runtime/SDK to allow for
+       * cases where there are no other toolchain options.
+       */
+      self->noop = g_object_new (GBP_TYPE_NOOP_RUNTIME,
+                                 "id", "noop",
+                                 /* translators: Bundled means a runtime "bundled" with Builder */
+                                 "name", _("Bundled with Builder"),
+                                 "category", _("Host System"),
+                                 "parent", self,
+                                 NULL);
+      ide_runtime_manager_add (runtime_manager, IDE_RUNTIME (self->noop));
+    }
 
   IDE_EXIT;
 }
@@ -70,8 +87,11 @@ gbp_host_runtime_provider_unload (IdeRuntimeProvider *provider,
   g_assert (GBP_IS_HOST_RUNTIME_PROVIDER (self));
   g_assert (IDE_IS_RUNTIME_MANAGER (runtime_manager));
 
-  ide_runtime_manager_remove (runtime_manager, IDE_RUNTIME (self->runtime));
-  ide_clear_and_destroy_object (&self->runtime);
+  ide_runtime_manager_remove (runtime_manager, IDE_RUNTIME (self->host));
+  ide_clear_and_destroy_object (&self->host);
+
+  ide_runtime_manager_remove (runtime_manager, IDE_RUNTIME (self->noop));
+  ide_clear_and_destroy_object (&self->noop);
 
   IDE_EXIT;
 }
diff --git a/src/plugins/host/gbp-host-runtime.c b/src/plugins/host/gbp-host-runtime.c
index f09c33b91..03fe36119 100644
--- a/src/plugins/host/gbp-host-runtime.c
+++ b/src/plugins/host/gbp-host-runtime.c
@@ -94,10 +94,9 @@ gbp_host_runtime_prepare_to_build (IdeRuntime    *runtime,
   IDE_EXIT;
 }
 
-static void
-gbp_host_runtime_prepare_to_run (IdeRuntime    *runtime,
-                                 IdePipeline   *pipeline,
-                                 IdeRunContext *run_context)
+void
+_gbp_host_runtime_prepare_to_run (IdePipeline   *pipeline,
+                                  IdeRunContext *run_context)
 {
   g_autofree char *libdir = NULL;
   const char *prefix;
@@ -105,7 +104,6 @@ gbp_host_runtime_prepare_to_run (IdeRuntime    *runtime,
 
   IDE_ENTRY;
 
-  g_assert (GBP_IS_HOST_RUNTIME (runtime));
   g_assert (IDE_IS_PIPELINE (pipeline));
   g_assert (IDE_IS_RUN_CONTEXT (run_context));
 
@@ -151,6 +149,18 @@ gbp_host_runtime_prepare_to_run (IdeRuntime    *runtime,
   IDE_EXIT;
 }
 
+void
+gbp_host_runtime_prepare_to_run (IdeRuntime    *runtime,
+                                 IdePipeline   *pipeline,
+                                 IdeRunContext *run_context)
+{
+  g_assert (GBP_IS_HOST_RUNTIME (runtime));
+  g_assert (IDE_IS_PIPELINE (pipeline));
+  g_assert (IDE_IS_RUN_CONTEXT (run_context));
+
+  _gbp_host_runtime_prepare_to_run (pipeline, run_context);
+}
+
 static void
 gbp_host_runtime_class_init (GbpHostRuntimeClass *klass)
 {
diff --git a/src/plugins/host/gbp-host-runtime.h b/src/plugins/host/gbp-host-runtime.h
index d39efcc16..1834d4237 100644
--- a/src/plugins/host/gbp-host-runtime.h
+++ b/src/plugins/host/gbp-host-runtime.h
@@ -28,4 +28,7 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbpHostRuntime, gbp_host_runtime, GBP, HOST_RUNTIME, IdeRuntime)
 
+void _gbp_host_runtime_prepare_to_run (IdePipeline   *pipeline,
+                                       IdeRunContext *run_context);
+
 G_END_DECLS
diff --git a/src/plugins/host/gbp-noop-runtime.c b/src/plugins/host/gbp-noop-runtime.c
new file mode 100644
index 000000000..fff031596
--- /dev/null
+++ b/src/plugins/host/gbp-noop-runtime.c
@@ -0,0 +1,87 @@
+/* gbp-noop-runtime.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-noop-runtime"
+
+#include "config.h"
+
+#include <libide-foundry.h>
+
+#include "ide-run-context-private.h"
+
+#include "gbp-host-runtime.h"
+#include "gbp-noop-runtime.h"
+
+struct _GbpNoopRuntime
+{
+  IdeRuntime parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GbpNoopRuntime, gbp_noop_runtime, IDE_TYPE_RUNTIME)
+
+static gboolean
+gbp_noop_runtime_contains_program_in_path (IdeRuntime   *runtime,
+                                           const char   *program,
+                                           GCancellable *cancellable)
+{
+  return g_find_program_in_path (program) != NULL;
+}
+
+static void
+gbp_noop_runtime_prepare_to_build (IdeRuntime    *runtime,
+                                   IdePipeline   *pipeline,
+                                   IdeRunContext *run_context)
+{
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_NOOP_RUNTIME (runtime));
+  g_assert (IDE_IS_PIPELINE (pipeline));
+  g_assert (IDE_IS_RUN_CONTEXT (run_context));
+
+  ide_run_context_add_minimal_environment (run_context);
+  _ide_run_context_push_user_shell (run_context, TRUE);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_noop_runtime_prepare_to_run (IdeRuntime    *runtime,
+                                 IdePipeline   *pipeline,
+                                 IdeRunContext *run_context)
+{
+  _gbp_host_runtime_prepare_to_run (pipeline, run_context);
+}
+
+
+static void
+gbp_noop_runtime_class_init (GbpNoopRuntimeClass *klass)
+{
+  IdeRuntimeClass *runtime_class = IDE_RUNTIME_CLASS (klass);
+
+  runtime_class->contains_program_in_path = gbp_noop_runtime_contains_program_in_path;
+  runtime_class->prepare_to_run = gbp_noop_runtime_prepare_to_run;
+  runtime_class->prepare_to_build = gbp_noop_runtime_prepare_to_build;
+}
+
+static void
+gbp_noop_runtime_init (GbpNoopRuntime *self)
+{
+  ide_runtime_set_icon_name (IDE_RUNTIME (self), "container-terminal-symbolic");
+}
diff --git a/src/plugins/host/gbp-noop-runtime.h b/src/plugins/host/gbp-noop-runtime.h
new file mode 100644
index 000000000..41e5798ad
--- /dev/null
+++ b/src/plugins/host/gbp-noop-runtime.h
@@ -0,0 +1,31 @@
+/* gbp-noop-runtime.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-foundry.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_NOOP_RUNTIME (gbp_noop_runtime_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpNoopRuntime, gbp_noop_runtime, GBP, NOOP_RUNTIME, IdeRuntime)
+
+G_END_DECLS
diff --git a/src/plugins/host/meson.build b/src/plugins/host/meson.build
index 36be52139..645c21b18 100644
--- a/src/plugins/host/meson.build
+++ b/src/plugins/host/meson.build
@@ -2,6 +2,7 @@ plugins_sources += files([
   'host-plugin.c',
   'gbp-host-runtime.c',
   'gbp-host-runtime-provider.c',
+  'gbp-noop-runtime.c',
 ])
 
 plugin_host_resources = gnome.compile_resources(


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