[gnome-builder] plugins/buildconfig: add run command provider
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/buildconfig: add run command provider
- Date: Tue, 19 Jul 2022 23:58:54 +0000 (UTC)
commit caa6f2504b08c5f44c8f0466a2517eccf503c7a6
Author: Christian Hergert <chergert redhat com>
Date: Tue Jul 19 16:58:44 2022 -0700
plugins/buildconfig: add run command provider
This adds a run command provider which was missing for buildconfig, so that
previous uses of .buildconfig still work to run the project with the
configured run-command.
src/plugins/buildconfig/buildconfig-plugin.c | 4 +
.../gbp-buildconfig-run-command-provider.c | 145 +++++++++++++++++++++
.../gbp-buildconfig-run-command-provider.h | 31 +++++
src/plugins/buildconfig/meson.build | 1 +
4 files changed, 181 insertions(+)
---
diff --git a/src/plugins/buildconfig/buildconfig-plugin.c b/src/plugins/buildconfig/buildconfig-plugin.c
index c3376615c..c604522b2 100644
--- a/src/plugins/buildconfig/buildconfig-plugin.c
+++ b/src/plugins/buildconfig/buildconfig-plugin.c
@@ -29,6 +29,7 @@
#include "ide-buildconfig-build-target-provider.h"
#include "ide-buildconfig-config-provider.h"
#include "ide-buildconfig-pipeline-addin.h"
+#include "gbp-buildconfig-run-command-provider.h"
_IDE_EXTERN void
_gbp_buildconfig_register_types (PeasObjectModule *module)
@@ -42,4 +43,7 @@ _gbp_buildconfig_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_PIPELINE_ADDIN,
IDE_TYPE_BUILDCONFIG_PIPELINE_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_RUN_COMMAND_PROVIDER,
+ GBP_TYPE_BUILDCONFIG_RUN_COMMAND_PROVIDER);
}
diff --git a/src/plugins/buildconfig/gbp-buildconfig-run-command-provider.c
b/src/plugins/buildconfig/gbp-buildconfig-run-command-provider.c
new file mode 100644
index 000000000..43c9bad2a
--- /dev/null
+++ b/src/plugins/buildconfig/gbp-buildconfig-run-command-provider.c
@@ -0,0 +1,145 @@
+/* gbp-buildconfig-run-command-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-buildconfig-run-command-provider"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+#include <libide-threading.h>
+
+#include "gbp-buildconfig-run-command-provider.h"
+#include "ide-buildconfig-config.h"
+
+struct _GbpBuildconfigRunCommandProvider
+{
+ IdeObject parent_instance;
+};
+
+static void
+gbp_buildconfig_run_command_provider_list_commands_async (IdeRunCommandProvider *provider,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GbpBuildconfigRunCommandProvider *self = (GbpBuildconfigRunCommandProvider *)provider;
+ g_autoptr(GListStore) store = NULL;
+ g_autoptr(IdeTask) task = NULL;
+ g_autoptr(IdeRunCommand) command = NULL;
+ g_auto(GStrv) env = NULL;
+ IdeConfigManager *config_manager;
+ const char * const *argv;
+ IdeEnvironment *envobj;
+ IdeContext *context;
+ IdeConfig *config;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_BUILDCONFIG_RUN_COMMAND_PROVIDER (self));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, gbp_buildconfig_run_command_provider_list_commands_async);
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ config_manager = ide_config_manager_from_context (context);
+ config = ide_config_manager_get_current (config_manager);
+
+ if (!IDE_IS_BUILDCONFIG_CONFIG (config))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Project is not configured with buildconfig, cannot list commands");
+ IDE_EXIT;
+ }
+
+ if (!(argv = ide_buildconfig_config_get_run_command (IDE_BUILDCONFIG_CONFIG (config))) || argv[0] == NULL)
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "No configured run commands for buildconfig");
+ IDE_EXIT;
+ }
+
+ if ((envobj = ide_config_get_runtime_environment (config)))
+ {
+ env = ide_environment_get_environ (envobj);
+
+ if (env != NULL && env[0] == NULL)
+ g_clear_pointer (&env, g_strfreev);
+ }
+
+ command = ide_run_command_new ();
+ ide_run_command_set_id (command, "buildconfig:");
+ ide_run_command_set_priority (command, -500);
+ ide_run_command_set_display_name (command, argv[0]);
+ ide_run_command_set_argv (command, (const char * const *)argv);
+ ide_run_command_set_environ (command, (const char * const *)env);
+ ide_run_command_set_can_default (command, TRUE);
+
+ store = g_list_store_new (IDE_TYPE_RUN_COMMAND);
+ g_list_store_append (store, command);
+
+ ide_task_return_pointer (task, g_steal_pointer (&store), g_object_unref);
+
+ IDE_EXIT;
+}
+
+static GListModel *
+gbp_buildconfig_run_command_provider_list_commands_finish (IdeRunCommandProvider *provider,
+ GAsyncResult *result,
+ GError **error)
+{
+ GListModel *ret;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_BUILDCONFIG_RUN_COMMAND_PROVIDER (provider));
+ g_assert (IDE_IS_TASK (result));
+ g_assert (ide_task_is_valid (IDE_TASK (result), provider));
+
+ ret = ide_task_propagate_pointer (IDE_TASK (result), error);
+
+ IDE_RETURN (ret);
+}
+
+static void
+run_command_provider_iface_init (IdeRunCommandProviderInterface *iface)
+{
+ iface->list_commands_async = gbp_buildconfig_run_command_provider_list_commands_async;
+ iface->list_commands_finish = gbp_buildconfig_run_command_provider_list_commands_finish;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpBuildconfigRunCommandProvider, gbp_buildconfig_run_command_provider,
IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_RUN_COMMAND_PROVIDER,
run_command_provider_iface_init))
+
+static void
+gbp_buildconfig_run_command_provider_class_init (GbpBuildconfigRunCommandProviderClass *klass)
+{
+}
+
+static void
+gbp_buildconfig_run_command_provider_init (GbpBuildconfigRunCommandProvider *self)
+{
+}
diff --git a/src/plugins/buildconfig/gbp-buildconfig-run-command-provider.h
b/src/plugins/buildconfig/gbp-buildconfig-run-command-provider.h
new file mode 100644
index 000000000..484662ad7
--- /dev/null
+++ b/src/plugins/buildconfig/gbp-buildconfig-run-command-provider.h
@@ -0,0 +1,31 @@
+/* gbp-buildconfig-build-target-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_BUILDCONFIG_RUN_COMMAND_PROVIDER (gbp_buildconfig_run_command_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpBuildconfigRunCommandProvider, gbp_buildconfig_run_command_provider, GBP,
BUILDCONFIG_RUN_COMMAND_PROVIDER, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/buildconfig/meson.build b/src/plugins/buildconfig/meson.build
index a3ef88ada..b4f1e84a4 100644
--- a/src/plugins/buildconfig/meson.build
+++ b/src/plugins/buildconfig/meson.build
@@ -5,6 +5,7 @@ plugins_sources += files([
'ide-buildconfig-config.c',
'ide-buildconfig-config-provider.c',
'ide-buildconfig-pipeline-addin.c',
+ 'gbp-buildconfig-run-command-provider.c',
])
plugin_buildconfig_resources = gnome.compile_resources(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]