[gnome-builder] plugins/host: break local host support into a runtime
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/host: break local host support into a runtime
- Date: Tue, 12 Jul 2022 06:39:16 +0000 (UTC)
commit b51dfdceeb3fc8cf927a3070499ad549e4ebf839
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 11 22:54:26 2022 -0700
plugins/host: break local host support into a runtime
This makes it easier to reason about compared to IdeRuntime w/o a subclass.
src/plugins/host/gbp-host-runtime-provider.c | 97 ++++++++++++++++
src/plugins/host/gbp-host-runtime-provider.h | 31 ++++++
src/plugins/host/gbp-host-runtime.c | 161 +++++++++++++++++++++++++++
src/plugins/host/gbp-host-runtime.h | 31 ++++++
src/plugins/host/host-plugin.c | 35 ++++++
src/plugins/host/host.gresource.xml | 6 +
src/plugins/host/host.plugin | 9 ++
src/plugins/host/meson.build | 13 +++
8 files changed, 383 insertions(+)
---
diff --git a/src/plugins/host/gbp-host-runtime-provider.c b/src/plugins/host/gbp-host-runtime-provider.c
new file mode 100644
index 000000000..27b395d13
--- /dev/null
+++ b/src/plugins/host/gbp-host-runtime-provider.c
@@ -0,0 +1,97 @@
+/* gbp-host-runtime-provider.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-host-runtime-provider"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-host-runtime.h"
+#include "gbp-host-runtime-provider.h"
+
+struct _GbpHostRuntimeProvider
+{
+ IdeObject parent_instance;
+ GbpHostRuntime *runtime;
+};
+
+static void
+gbp_host_runtime_provider_load (IdeRuntimeProvider *provider,
+ IdeRuntimeManager *runtime_manager)
+{
+ GbpHostRuntimeProvider *self = (GbpHostRuntimeProvider *)provider;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ 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));
+
+ IDE_EXIT;
+}
+
+static void
+gbp_host_runtime_provider_unload (IdeRuntimeProvider *provider,
+ IdeRuntimeManager *runtime_manager)
+{
+ GbpHostRuntimeProvider *self = (GbpHostRuntimeProvider *)provider;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ 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_EXIT;
+}
+
+static void
+runtime_provider_iface_emit (IdeRuntimeProviderInterface *iface)
+{
+ iface->load = gbp_host_runtime_provider_load;
+ iface->unload = gbp_host_runtime_provider_unload;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpHostRuntimeProvider, gbp_host_runtime_provider, IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_RUNTIME_PROVIDER,
runtime_provider_iface_emit))
+
+static void
+gbp_host_runtime_provider_class_init (GbpHostRuntimeProviderClass *klass)
+{
+}
+
+static void
+gbp_host_runtime_provider_init (GbpHostRuntimeProvider *self)
+{
+}
diff --git a/src/plugins/host/gbp-host-runtime-provider.h b/src/plugins/host/gbp-host-runtime-provider.h
new file mode 100644
index 000000000..3b9be6321
--- /dev/null
+++ b/src/plugins/host/gbp-host-runtime-provider.h
@@ -0,0 +1,31 @@
+/* gbp-host-runtime-provider.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-core.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_HOST_RUNTIME_PROVIDER (gbp_host_runtime_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpHostRuntimeProvider, gbp_host_runtime_provider, GBP, HOST_RUNTIME_PROVIDER,
IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/host/gbp-host-runtime.c b/src/plugins/host/gbp-host-runtime.c
new file mode 100644
index 000000000..058142081
--- /dev/null
+++ b/src/plugins/host/gbp-host-runtime.c
@@ -0,0 +1,161 @@
+/* gbp-host-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-host-runtime"
+
+#include "config.h"
+
+#include "gbp-host-runtime.h"
+
+struct _GbpHostRuntime
+{
+ IdeRuntime parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GbpHostRuntime, gbp_host_runtime, IDE_TYPE_RUNTIME)
+
+static gboolean
+gbp_host_runtime_native_contains_program_in_path (IdeRuntime *runtime,
+ const char *program,
+ GCancellable *cancellable)
+{
+ return g_find_program_in_path (program) != NULL;
+}
+
+static gboolean
+gbp_host_runtime_flatpak_contains_program_in_path (IdeRuntime *runtime,
+ const char *program,
+ GCancellable *cancellable)
+{
+ g_autoptr(IdeSubprocess) subprocess = NULL;
+ g_autoptr(IdeRunContext) run_context = NULL;
+ g_autoptr(GError) error = NULL;
+ gboolean ret = FALSE;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_HOST_RUNTIME (runtime));
+ g_assert (program != NULL);
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ run_context = ide_run_context_new ();
+ ide_run_context_push_host (run_context);
+ ide_run_context_push_shell (run_context, TRUE);
+ ide_run_context_append_argv (run_context, "which");
+ ide_run_context_append_argv (run_context, program);
+
+ if ((subprocess = ide_run_context_spawn (run_context, &error)))
+ ret = ide_subprocess_wait_check (subprocess, cancellable, NULL);
+
+ if (error != NULL)
+ g_warning ("Failed to spawn subprocess: %s", error->message);
+
+ IDE_RETURN (ret);
+}
+
+static void
+gbp_host_runtime_prepare_to_build (IdeRuntime *runtime,
+ IdePipeline *pipeline,
+ IdeRunContext *run_context)
+{
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_HOST_RUNTIME (runtime));
+ g_assert (IDE_IS_PIPELINE (pipeline));
+ g_assert (IDE_IS_RUN_CONTEXT (run_context));
+
+ ide_run_context_push_host (run_context);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_host_runtime_prepare_to_run (IdeRuntime *runtime,
+ IdePipeline *pipeline,
+ IdeRunContext *run_context)
+{
+ g_autofree char *libdir = NULL;
+ const char *prefix;
+ IdeConfig *config;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_HOST_RUNTIME (runtime));
+ g_assert (IDE_IS_PIPELINE (pipeline));
+ g_assert (IDE_IS_RUN_CONTEXT (run_context));
+
+ ide_run_context_push_host (run_context);
+
+ config = ide_pipeline_get_config (pipeline);
+ prefix = ide_config_get_prefix (config);
+
+ /* LD_LIBRARY_PATH */
+ {
+ static const gchar *tries[] = { "lib64", "lib", "lib32", };
+
+ for (guint i = 0; i < G_N_ELEMENTS (tries); i++)
+ {
+ g_autofree gchar *ld_library_path = g_build_filename (prefix, tries[i], NULL);
+
+ if (g_file_test (ld_library_path, G_FILE_TEST_IS_DIR))
+ {
+ ide_run_context_setenv (run_context, "LD_LIBRARY_PATH", ld_library_path);
+ libdir = g_steal_pointer (&ld_library_path);
+ break;
+ }
+ }
+ }
+
+ /* GSETTINGS_SCHEMA_DIR */
+ {
+ g_autofree gchar *schemadir = NULL;
+
+ schemadir = g_build_filename (prefix, "share", "glib-2.0", "schemas", NULL);
+ ide_run_context_setenv (run_context, "GSETTINGS_SCHEMA_DIR", schemadir);
+ }
+
+ /* GI_TYPELIB_PATH */
+ if (libdir != NULL)
+ {
+ g_autofree char *typelib_path = g_build_filename (libdir, "girepository-1.0", NULL);
+ ide_run_context_setenv (run_context, "GI_TYPELIB_PATH", typelib_path);
+ }
+
+ IDE_EXIT;
+}
+
+static void
+gbp_host_runtime_class_init (GbpHostRuntimeClass *klass)
+{
+ IdeRuntimeClass *runtime_class = IDE_RUNTIME_CLASS (klass);
+
+ if (ide_is_flatpak ())
+ runtime_class->contains_program_in_path = gbp_host_runtime_flatpak_contains_program_in_path;
+ else
+ runtime_class->contains_program_in_path = gbp_host_runtime_native_contains_program_in_path;
+
+ runtime_class->prepare_to_run = gbp_host_runtime_prepare_to_run;
+ runtime_class->prepare_to_build = gbp_host_runtime_prepare_to_build;
+}
+
+static void
+gbp_host_runtime_init (GbpHostRuntime *self)
+{
+}
diff --git a/src/plugins/host/gbp-host-runtime.h b/src/plugins/host/gbp-host-runtime.h
new file mode 100644
index 000000000..d39efcc16
--- /dev/null
+++ b/src/plugins/host/gbp-host-runtime.h
@@ -0,0 +1,31 @@
+/* gbp-host-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_HOST_RUNTIME (gbp_host_runtime_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpHostRuntime, gbp_host_runtime, GBP, HOST_RUNTIME, IdeRuntime)
+
+G_END_DECLS
diff --git a/src/plugins/host/host-plugin.c b/src/plugins/host/host-plugin.c
new file mode 100644
index 000000000..65c4d115d
--- /dev/null
+++ b/src/plugins/host/host-plugin.c
@@ -0,0 +1,35 @@
+/* host-plugin.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
+ */
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-host-runtime-provider.h"
+
+_IDE_EXTERN void
+_gbp_host_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_RUNTIME_PROVIDER,
+ GBP_TYPE_HOST_RUNTIME_PROVIDER);
+}
diff --git a/src/plugins/host/host.gresource.xml b/src/plugins/host/host.gresource.xml
new file mode 100644
index 000000000..d4ee03a92
--- /dev/null
+++ b/src/plugins/host/host.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/plugins/host">
+ <file>host.plugin</file>
+ </gresource>
+</gresources>
diff --git a/src/plugins/host/host.plugin b/src/plugins/host/host.plugin
new file mode 100644
index 000000000..2a52274a7
--- /dev/null
+++ b/src/plugins/host/host.plugin
@@ -0,0 +1,9 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2022 Christian Hergert
+Description=Access to host system as a runtime
+Embedded=_gbp_host_register_types
+Hidden=true
+Module=host
+Name=Host
diff --git a/src/plugins/host/meson.build b/src/plugins/host/meson.build
new file mode 100644
index 000000000..36be52139
--- /dev/null
+++ b/src/plugins/host/meson.build
@@ -0,0 +1,13 @@
+plugins_sources += files([
+ 'host-plugin.c',
+ 'gbp-host-runtime.c',
+ 'gbp-host-runtime-provider.c',
+])
+
+plugin_host_resources = gnome.compile_resources(
+ 'host-resources',
+ 'host.gresource.xml',
+ c_name: 'gbp_host',
+)
+
+plugins_sources += plugin_host_resources
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]