[gnome-builder] flatpak: add IdeBuildTargetProvider
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] flatpak: add IdeBuildTargetProvider
- Date: Mon, 20 Nov 2017 06:28:13 +0000 (UTC)
commit 65d4d4aa996aef7c2d97e795a913d72f586d8ef0
Author: Christian Hergert <chergert redhat com>
Date: Sun Nov 19 20:09:06 2017 -0800
flatpak: add IdeBuildTargetProvider
This adds a build target provider by using the command
member of the flatpak json manifest.
.../flatpak/gbp-flatpak-build-target-provider.c | 109 ++++++++++++++++
.../flatpak/gbp-flatpak-build-target-provider.h | 29 ++++
src/plugins/flatpak/gbp-flatpak-build-target.c | 136 ++++++++++++++++++++
src/plugins/flatpak/gbp-flatpak-build-target.h | 29 ++++
src/plugins/flatpak/gbp-flatpak-plugin.c | 4 +
src/plugins/flatpak/meson.build | 4 +
6 files changed, 311 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-build-target-provider.c
b/src/plugins/flatpak/gbp-flatpak-build-target-provider.c
new file mode 100644
index 0000000..dc9a3b0
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-build-target-provider.c
@@ -0,0 +1,109 @@
+/* gbp-flatpak-build-target-provider.c
+ *
+ * Copyright (C) 2017 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-build-target-provider"
+
+#include "gbp-flatpak-build-target.h"
+#include "gbp-flatpak-build-target-provider.h"
+#include "gbp-flatpak-configuration.h"
+
+struct _GbpFlatpakBuildTargetProvider
+{
+ IdeObject parent_instance;
+};
+
+static void
+gbp_flatpak_build_target_provider_get_targets_async (IdeBuildTargetProvider *provider,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GbpFlatpakBuildTargetProvider *self = (GbpFlatpakBuildTargetProvider *)provider;
+ g_autoptr(GTask) task = NULL;
+ g_autoptr(GPtrArray) targets = NULL;
+ IdeConfigurationManager *config_manager;
+ IdeConfiguration *config;
+ IdeContext *context;
+
+ g_assert (GBP_IS_FLATPAK_BUILD_TARGET_PROVIDER (self));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, gbp_flatpak_build_target_provider_get_targets_async);
+ g_task_set_priority (task, G_PRIORITY_LOW);
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ config_manager = ide_context_get_configuration_manager (context);
+ config = ide_configuration_manager_get_current (config_manager);
+
+ targets = g_ptr_array_new_with_free_func (g_object_unref);
+
+ if (GBP_IS_FLATPAK_CONFIGURATION (config))
+ {
+ g_autoptr(IdeBuildTarget) target = NULL;
+ const gchar *command;
+
+ command = gbp_flatpak_configuration_get_command (GBP_FLATPAK_CONFIGURATION (config));
+
+ target = g_object_new (GBP_TYPE_FLATPAK_BUILD_TARGET,
+ "context", context,
+ "command", command,
+ NULL);
+
+ g_ptr_array_add (targets, g_steal_pointer (&target));
+ }
+
+ g_task_return_pointer (task,
+ g_steal_pointer (&targets),
+ (GDestroyNotify)g_ptr_array_unref);
+}
+
+static GPtrArray *
+gbp_flatpak_build_target_provider_get_targets_finish (IdeBuildTargetProvider *provider,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_assert (GBP_IS_FLATPAK_BUILD_TARGET_PROVIDER (provider));
+ g_assert (G_IS_TASK (result));
+ g_assert (g_task_is_valid (G_TASK (result), provider));
+
+ return g_task_propagate_pointer (G_TASK (result), error);
+}
+
+static void
+build_target_provider_iface_init (IdeBuildTargetProviderInterface *iface)
+{
+ iface->get_targets_async = gbp_flatpak_build_target_provider_get_targets_async;
+ iface->get_targets_finish = gbp_flatpak_build_target_provider_get_targets_finish;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpFlatpakBuildTargetProvider,
+ gbp_flatpak_build_target_provider,
+ IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_TARGET_PROVIDER,
+ build_target_provider_iface_init))
+
+static void
+gbp_flatpak_build_target_provider_class_init (GbpFlatpakBuildTargetProviderClass *klass)
+{
+}
+
+static void
+gbp_flatpak_build_target_provider_init (GbpFlatpakBuildTargetProvider *self)
+{
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-build-target-provider.h
b/src/plugins/flatpak/gbp-flatpak-build-target-provider.h
new file mode 100644
index 0000000..51e16b9
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-build-target-provider.h
@@ -0,0 +1,29 @@
+/* gbp-flatpak-build-target-provider.h
+ *
+ * Copyright (C) 2017 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/>.
+ */
+
+#pragma once
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_FLATPAK_BUILD_TARGET_PROVIDER (gbp_flatpak_build_target_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakBuildTargetProvider, gbp_flatpak_build_target_provider, GBP,
FLATPAK_BUILD_TARGET_PROVIDER, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-build-target.c b/src/plugins/flatpak/gbp-flatpak-build-target.c
new file mode 100644
index 0000000..09118b6
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-build-target.c
@@ -0,0 +1,136 @@
+/* gbp-flatpak-build-target.c
+ *
+ * Copyright (C) 2017 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/>.
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-build-target"
+
+#include "gbp-flatpak-build-target.h"
+
+struct _GbpFlatpakBuildTarget
+{
+ IdeObject parent;
+
+ gchar *command;
+};
+
+enum {
+ PROP_0,
+ PROP_COMMAND,
+ N_PROPS
+};
+
+static gchar *
+gbp_flatpak_build_target_get_name (IdeBuildTarget *build_target)
+{
+ GbpFlatpakBuildTarget *self = GBP_FLATPAK_BUILD_TARGET (build_target);
+
+ return g_strdup (self->command);
+}
+
+static GFile *
+gbp_flatpak_build_target_get_install_directory (IdeBuildTarget *build_target)
+{
+ return NULL;
+}
+
+static gint
+gbp_flatpak_build_target_get_priority (IdeBuildTarget *build_target)
+{
+ return -100;
+}
+
+static void
+build_target_iface_init (IdeBuildTargetInterface *iface)
+{
+ iface->get_name = gbp_flatpak_build_target_get_name;
+ iface->get_install_directory = gbp_flatpak_build_target_get_install_directory;
+ iface->get_priority = gbp_flatpak_build_target_get_priority;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpFlatpakBuildTarget, gbp_flatpak_build_target, IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_TARGET, build_target_iface_init))
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+gbp_flatpak_build_target_finalize (GObject *object)
+{
+ GbpFlatpakBuildTarget *self = (GbpFlatpakBuildTarget *)object;
+
+ g_clear_pointer (&self->command, g_free);
+
+ G_OBJECT_CLASS (gbp_flatpak_build_target_parent_class)->finalize (object);
+}
+
+static void
+gbp_flatpak_build_target_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbpFlatpakBuildTarget *self = GBP_FLATPAK_BUILD_TARGET (object);
+
+ switch (prop_id)
+ {
+ case PROP_COMMAND:
+ g_value_set_string (value, self->command);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gbp_flatpak_build_target_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GbpFlatpakBuildTarget *self = GBP_FLATPAK_BUILD_TARGET (object);
+
+ switch (prop_id)
+ {
+ case PROP_COMMAND:
+ self->command = g_value_dup_string (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gbp_flatpak_build_target_class_init (GbpFlatpakBuildTargetClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gbp_flatpak_build_target_finalize;
+ object_class->get_property = gbp_flatpak_build_target_get_property;
+ object_class->set_property = gbp_flatpak_build_target_set_property;
+
+ properties [PROP_COMMAND] =
+ g_param_spec_string ("command", NULL, NULL, NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+gbp_flatpak_build_target_init (GbpFlatpakBuildTarget *self)
+{
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-build-target.h b/src/plugins/flatpak/gbp-flatpak-build-target.h
new file mode 100644
index 0000000..138b7ef
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-build-target.h
@@ -0,0 +1,29 @@
+/* gbp-flatpak-build-target.h
+ *
+ * Copyright (C) 2017 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/>.
+ */
+
+#pragma once
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_FLATPAK_BUILD_TARGET (gbp_flatpak_build_target_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakBuildTarget, gbp_flatpak_build_target, GBP, FLATPAK_BUILD_TARGET, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-plugin.c b/src/plugins/flatpak/gbp-flatpak-plugin.c
index b0ec6e5..06219fd 100644
--- a/src/plugins/flatpak/gbp-flatpak-plugin.c
+++ b/src/plugins/flatpak/gbp-flatpak-plugin.c
@@ -21,6 +21,7 @@
#include "gbp-flatpak-application-addin.h"
#include "gbp-flatpak-build-system-discovery.h"
+#include "gbp-flatpak-build-target-provider.h"
#include "gbp-flatpak-configuration-provider.h"
#include "gbp-flatpak-genesis-addin.h"
#include "gbp-flatpak-pipeline-addin.h"
@@ -37,6 +38,9 @@ gbp_flatpak_register_types (PeasObjectModule *module)
IDE_TYPE_BUILD_SYSTEM_DISCOVERY,
GBP_TYPE_FLATPAK_BUILD_SYSTEM_DISCOVERY);
peas_object_module_register_extension_type (module,
+ IDE_TYPE_BUILD_TARGET_PROVIDER,
+ GBP_TYPE_FLATPAK_BUILD_TARGET_PROVIDER);
+ peas_object_module_register_extension_type (module,
IDE_TYPE_CONFIGURATION_PROVIDER,
GBP_TYPE_FLATPAK_CONFIGURATION_PROVIDER);
peas_object_module_register_extension_type (module,
diff --git a/src/plugins/flatpak/meson.build b/src/plugins/flatpak/meson.build
index 8c8ae7c..a811b05 100644
--- a/src/plugins/flatpak/meson.build
+++ b/src/plugins/flatpak/meson.build
@@ -11,6 +11,10 @@ flatpak_sources = [
'gbp-flatpak-application-addin.h',
'gbp-flatpak-build-system-discovery.c',
'gbp-flatpak-build-system-discovery.h',
+ 'gbp-flatpak-build-target.c',
+ 'gbp-flatpak-build-target.h',
+ 'gbp-flatpak-build-target-provider.c',
+ 'gbp-flatpak-build-target-provider.h',
'gbp-flatpak-clone-widget.c',
'gbp-flatpak-clone-widget.h',
'gbp-flatpak-configuration.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]