[gnome-builder] plugins/host: port GbpNoopRuntime to IdePathCache
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/host: port GbpNoopRuntime to IdePathCache
- Date: Tue, 4 Oct 2022 23:50:24 +0000 (UTC)
commit b82bbda5965228094b82010e9785425c6c3ca654
Author: Christian Hergert <chergert redhat com>
Date: Tue Oct 4 16:47:15 2022 -0700
plugins/host: port GbpNoopRuntime to IdePathCache
src/plugins/host/gbp-noop-runtime.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/host/gbp-noop-runtime.c b/src/plugins/host/gbp-noop-runtime.c
index fff031596..2e2ba1c99 100644
--- a/src/plugins/host/gbp-noop-runtime.c
+++ b/src/plugins/host/gbp-noop-runtime.c
@@ -31,7 +31,8 @@
struct _GbpNoopRuntime
{
- IdeRuntime parent_instance;
+ IdeRuntime parent_instance;
+ IdePathCache *path_cache;
};
G_DEFINE_FINAL_TYPE (GbpNoopRuntime, gbp_noop_runtime, IDE_TYPE_RUNTIME)
@@ -41,7 +42,19 @@ gbp_noop_runtime_contains_program_in_path (IdeRuntime *runtime,
const char *program,
GCancellable *cancellable)
{
- return g_find_program_in_path (program) != NULL;
+ GbpNoopRuntime *self = (GbpNoopRuntime *)runtime;
+ g_autofree char *path = NULL;
+ gboolean found;
+
+ g_assert (GBP_IS_NOOP_RUNTIME (self));
+ g_assert (program != NULL);
+
+ if (ide_path_cache_contains (self->path_cache, program, &found))
+ return found;
+
+ path = g_find_program_in_path (program);
+ ide_path_cache_insert (self->path_cache, program, path);
+ return path != NULL;
}
static void
@@ -69,12 +82,24 @@ gbp_noop_runtime_prepare_to_run (IdeRuntime *runtime,
_gbp_host_runtime_prepare_to_run (pipeline, run_context);
}
+static void
+gbp_noop_runtime_finalize (GObject *object)
+{
+ GbpNoopRuntime *self = (GbpNoopRuntime *)object;
+
+ g_clear_object (&self->path_cache);
+
+ G_OBJECT_CLASS (gbp_noop_runtime_parent_class)->finalize (object);
+}
static void
gbp_noop_runtime_class_init (GbpNoopRuntimeClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
IdeRuntimeClass *runtime_class = IDE_RUNTIME_CLASS (klass);
+ object_class->finalize = gbp_noop_runtime_finalize;
+
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;
@@ -83,5 +108,7 @@ gbp_noop_runtime_class_init (GbpNoopRuntimeClass *klass)
static void
gbp_noop_runtime_init (GbpNoopRuntime *self)
{
+ self->path_cache = ide_path_cache_new ();
+
ide_runtime_set_icon_name (IDE_RUNTIME (self), "container-terminal-symbolic");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]