[gnome-builder/wip/gtk4-port: 1581/1774] libide/foundry: use prepare_run_context instead of create_run_context




commit 61e77685bc2b2268115d2f441e59cc485e29987e
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 21 15:01:30 2022 -0700

    libide/foundry: use prepare_run_context instead of create_run_context
    
    We want to be in control of the run context elsewhere rather than have an
    origin of a particular subsystem. This allows for more flexibility as we
    change the internals of the system to adapt to new features.

 src/libide/foundry/ide-deploy-strategy.c  | 56 ++++++++++++++++++++++++++++++-
 src/libide/foundry/ide-deploy-strategy.h  | 10 ++++--
 src/libide/foundry/ide-runtime.c          | 35 ++++++++++---------
 src/libide/foundry/ide-runtime.h          |  6 ++--
 src/plugins/jhbuild/gbp-jhbuild-runtime.c | 13 ++++---
 5 files changed, 92 insertions(+), 28 deletions(-)
---
diff --git a/src/libide/foundry/ide-deploy-strategy.c b/src/libide/foundry/ide-deploy-strategy.c
index 1e0bbd45d..ac1de76c5 100644
--- a/src/libide/foundry/ide-deploy-strategy.c
+++ b/src/libide/foundry/ide-deploy-strategy.c
@@ -22,8 +22,10 @@
 
 #include "config.h"
 
-#include "ide-pipeline.h"
 #include "ide-deploy-strategy.h"
+#include "ide-pipeline.h"
+#include "ide-run-context.h"
+#include "ide-runtime.h"
 
 G_DEFINE_ABSTRACT_TYPE (IdeDeployStrategy, ide_deploy_strategy, IDE_TYPE_OBJECT)
 
@@ -120,6 +122,30 @@ ide_deploy_strategy_real_create_runner_finish (IdeDeployStrategy  *self,
   return ide_task_propagate_pointer (IDE_TASK (result), error);
 }
 
+static void
+ide_deploy_strategy_real_prepare_run_context (IdeDeployStrategy *self,
+                                              IdePipeline       *pipeline,
+                                              IdeRunContext     *run_context)
+{
+  IdeRuntime *runtime;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_DEPLOY_STRATEGY (self));
+  g_assert (IDE_IS_PIPELINE (pipeline));
+  g_assert (IDE_IS_RUN_CONTEXT (run_context));
+
+  /* In the default implementation, for running locally, we just defer to
+   * the pipeline's runtime for how to create a run context.
+   */
+  if ((runtime = ide_pipeline_get_runtime (pipeline)))
+    ide_runtime_prepare_run_context (runtime, run_context);
+  else
+    g_return_if_reached ();
+
+  IDE_EXIT;
+}
+
 static void
 ide_deploy_strategy_class_init (IdeDeployStrategyClass *klass)
 {
@@ -129,6 +155,7 @@ ide_deploy_strategy_class_init (IdeDeployStrategyClass *klass)
   klass->deploy_finish = ide_deploy_strategy_real_deploy_finish;
   klass->create_runner_async = ide_deploy_strategy_real_create_runner_async;
   klass->create_runner_finish = ide_deploy_strategy_real_create_runner_finish;
+  klass->prepare_run_context = ide_deploy_strategy_real_prepare_run_context;
 }
 
 static void
@@ -337,3 +364,30 @@ ide_deploy_strategy_create_runner_finish (IdeDeployStrategy  *self,
 
   IDE_RETURN (ret);
 }
+
+/**
+ * ide_deploy_strategy_prepare_run_context:
+ * @self: a #IdeDeployStrategy
+ * @pipeline: an #IdePipeline
+ * @run_context: an #IdeRunContext
+ *
+ * Prepare an #IdeRunContext to run on a device.
+ *
+ * This virtual function should be implemented by device strategies to prepare
+ * a run context for running on a device or deployment situation.
+ *
+ * Typically this is either nothing (in the case of running locally) or pushing
+ * a layer into the run context which is a command to deliver the command to
+ * another device/container/simulator/etc.
+ */
+void
+ide_deploy_strategy_prepare_run_context (IdeDeployStrategy *self,
+                                         IdePipeline       *pipeline,
+                                         IdeRunContext     *run_context)
+{
+  g_return_if_fail (IDE_IS_DEPLOY_STRATEGY (self));
+  g_return_if_fail (IDE_IS_PIPELINE (pipeline));
+  g_return_if_fail (IDE_IS_RUN_CONTEXT (run_context));
+
+  IDE_DEPLOY_STRATEGY_GET_CLASS (self)->prepare_run_context (self, pipeline, run_context);
+}
diff --git a/src/libide/foundry/ide-deploy-strategy.h b/src/libide/foundry/ide-deploy-strategy.h
index 14061c544..c78e7cc46 100644
--- a/src/libide/foundry/ide-deploy-strategy.h
+++ b/src/libide/foundry/ide-deploy-strategy.h
@@ -25,6 +25,7 @@
 #endif
 
 #include <libide-core.h>
+
 #include "ide-foundry-types.h"
 
 G_BEGIN_DECLS
@@ -66,8 +67,9 @@ struct _IdeDeployStrategyClass
   IdeRunner     *(*create_runner_finish) (IdeDeployStrategy      *self,
                                           GAsyncResult           *result,
                                           GError                **error);
-
-  gpointer _reserved[16];
+  void           (*prepare_run_context)  (IdeDeployStrategy      *self,
+                                          IdePipeline            *pipeline,
+                                          IdeRunContext          *run_context);
 };
 
 IDE_AVAILABLE_IN_ALL
@@ -104,5 +106,9 @@ IDE_AVAILABLE_IN_ALL
 IdeRunner *ide_deploy_strategy_create_runner_finish (IdeDeployStrategy  *self,
                                                      GAsyncResult       *result,
                                                      GError            **error);
+IDE_AVAILABLE_IN_ALL
+void       ide_deploy_strategy_prepare_run_context  (IdeDeployStrategy  *self,
+                                                     IdePipeline        *pipeline,
+                                                     IdeRunContext      *run_context);
 
 G_END_DECLS
diff --git a/src/libide/foundry/ide-runtime.c b/src/libide/foundry/ide-runtime.c
index 235a6bf5c..6e23d61e1 100644
--- a/src/libide/foundry/ide-runtime.c
+++ b/src/libide/foundry/ide-runtime.c
@@ -92,14 +92,6 @@ ide_runtime_real_create_launcher (IdeRuntime  *self,
   IDE_RETURN (ret);
 }
 
-static IdeRunContext *
-ide_runtime_real_create_run_context (IdeRuntime *self)
-{
-  g_assert (IDE_IS_RUNTIME (self));
-
-  return ide_run_context_new ();
-}
-
 static gboolean
 ide_runtime_real_contains_program_in_path (IdeRuntime   *self,
                                            const gchar  *program,
@@ -458,7 +450,6 @@ ide_runtime_class_init (IdeRuntimeClass *klass)
   i_object_class->repr = ide_runtime_repr;
 
   klass->create_launcher = ide_runtime_real_create_launcher;
-  klass->create_run_context = ide_runtime_real_create_run_context;
   klass->create_runner = ide_runtime_real_create_runner;
   klass->contains_program_in_path = ide_runtime_real_contains_program_in_path;
   klass->prepare_configuration = ide_runtime_real_prepare_configuration;
@@ -867,17 +858,29 @@ ide_runtime_supports_toolchain (IdeRuntime   *self,
 }
 
 /**
- * ide_runtime_create_run_context:
+ * ide_runtime_prepare_run_context:
  * @self: a #IdeRuntime
+ * @run_context: an #IdeRunContext
+ *
+ * Prepares a run context to run within the runtime.
  *
- * Creates a new #IdeRunContext for the runtime.
+ * The virtual function implementation should add to the run context anything
+ * necessary to be able to run within the runtime.
  *
- * Returns: (transfer full): an #IdeRunContext
+ * That might include pushing a new layer so that the command will run within
+ * a subcommand such as "flatpak", "jhbuild", or "podman".
  */
-IdeRunContext *
-ide_runtime_create_run_context (IdeRuntime *self)
+void
+ide_runtime_prepare_run_context (IdeRuntime    *self,
+                                 IdeRunContext *run_context)
 {
-  g_return_val_if_fail (IDE_IS_RUNTIME (self), NULL);
+  IDE_ENTRY;
+
+  g_return_if_fail (IDE_IS_RUNTIME (self));
+  g_return_if_fail (IDE_IS_RUN_CONTEXT (run_context));
+
+  if (IDE_RUNTIME_GET_CLASS (self)->prepare_run_context)
+    IDE_RUNTIME_GET_CLASS (self)->prepare_run_context (self, run_context);
 
-  return IDE_RUNTIME_GET_CLASS (self)->create_run_context (self);
+  IDE_EXIT;
 }
diff --git a/src/libide/foundry/ide-runtime.h b/src/libide/foundry/ide-runtime.h
index 51b9458f6..73094f288 100644
--- a/src/libide/foundry/ide-runtime.h
+++ b/src/libide/foundry/ide-runtime.h
@@ -56,7 +56,8 @@ struct _IdeRuntimeClass
                                                        GError              **error);
   void                    (*prepare_configuration)    (IdeRuntime           *self,
                                                        IdeConfig            *config);
-  IdeRunContext          *(*create_run_context)       (IdeRuntime           *self);
+  void                    (*prepare_run_context)      (IdeRuntime           *self,
+                                                       IdeRunContext        *run_context);
   IdeRunner              *(*create_runner)            (IdeRuntime           *self,
                                                        IdeBuildTarget       *build_target);
   GFile                  *(*translate_file)           (IdeRuntime           *self,
@@ -80,7 +81,8 @@ IDE_AVAILABLE_IN_ALL
 IdeSubprocessLauncher  *ide_runtime_create_launcher          (IdeRuntime      *self,
                                                               GError         **error);
 IDE_AVAILABLE_IN_ALL
-IdeRunContext          *ide_runtime_create_run_context       (IdeRuntime      *self);
+void                    ide_runtime_prepare_run_context      (IdeRuntime      *self,
+                                                              IdeRunContext   *run_context);
 IDE_AVAILABLE_IN_ALL
 IdeRunner              *ide_runtime_create_runner            (IdeRuntime      *self,
                                                               IdeBuildTarget  *build_target);
diff --git a/src/plugins/jhbuild/gbp-jhbuild-runtime.c b/src/plugins/jhbuild/gbp-jhbuild-runtime.c
index 6a8a5d1d6..7ef0b8615 100644
--- a/src/plugins/jhbuild/gbp-jhbuild-runtime.c
+++ b/src/plugins/jhbuild/gbp-jhbuild-runtime.c
@@ -127,24 +127,23 @@ gbp_jhbuild_runtime_run_handler (IdeRunContext       *run_context,
   IDE_RETURN (TRUE);
 }
 
-static IdeRunContext *
-gbp_jhbuild_runtime_create_run_context (IdeRuntime *runtime)
+static void
+gbp_jhbuild_runtime_prepare_run_context (IdeRuntime    *runtime,
+                                         IdeRunContext *run_context)
 {
   GbpJhbuildRuntime *self = (GbpJhbuildRuntime *)runtime;
-  IdeRunContext *run_context;
 
   IDE_ENTRY;
 
   g_assert (GBP_IS_JHBUILD_RUNTIME (self));
-
-  run_context = ide_run_context_new ();
+  g_assert (IDE_IS_RUN_CONTEXT (run_context));
 
   ide_run_context_push (run_context,
                         gbp_jhbuild_runtime_run_handler,
                         g_object_ref (self),
                         g_object_unref);
 
-  IDE_RETURN (run_context);
+  IDE_EXIT;
 }
 
 static gboolean
@@ -258,9 +257,9 @@ gbp_jhbuild_runtime_class_init (GbpJhbuildRuntimeClass *klass)
 
   runtime_class->contains_program_in_path = gbp_jhbuild_runtime_contains_program_in_path;
   runtime_class->create_launcher = gbp_jhbuild_runtime_create_launcher;
-  runtime_class->create_run_context = gbp_jhbuild_runtime_create_run_context;
   runtime_class->create_runner = gbp_jhbuild_runtime_create_runner;
   runtime_class->prepare_configuration = gbp_jhbuild_runtime_prepare_configuration;
+  runtime_class->prepare_run_context = gbp_jhbuild_runtime_prepare_run_context;
 
   properties [PROP_EXECUTABLE_PATH] =
     g_param_spec_string ("executable-path", NULL, NULL,


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