[gnome-builder/wip/gtk4-port] plugin/buildstream: port buildstream plugin to C



commit ee5f34b0ae1d790f8eda28d9ff89ba3681dd2be1
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 25 15:14:25 2022 -0700

    plugin/buildstream: port buildstream plugin to C
    
    More work towards #1670

 meson_options.txt                                  |   1 +
 src/plugins/buildstream/buildstream-plugin.c       |  47 +++++++
 src/plugins/buildstream/buildstream.gresource.xml  |   6 +
 src/plugins/buildstream/buildstream.plugin         |  12 +-
 src/plugins/buildstream/buildstream_plugin.py      |  53 --------
 .../gbp-buildstream-build-system-discovery.c       |  47 +++++++
 .../gbp-buildstream-build-system-discovery.h       |  31 +++++
 .../buildstream/gbp-buildstream-build-system.c     | 142 +++++++++++++++++++++
 .../buildstream/gbp-buildstream-build-system.h     |  31 +++++
 .../buildstream/gbp-buildstream-pipeline-addin.c   | 112 ++++++++++++++++
 .../buildstream/gbp-buildstream-pipeline-addin.h   |  31 +++++
 src/plugins/buildstream/meson.build                |  25 ++--
 src/plugins/meson.build                            |   1 +
 13 files changed, 472 insertions(+), 67 deletions(-)
---
diff --git a/meson_options.txt b/meson_options.txt
index 13e3c09e4..fb24ce66c 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -25,6 +25,7 @@ option('plugin_autotools', type: 'boolean')
 option('plugin_bash_language_server', type: 'boolean')
 option('plugin_beautifier', type: 'boolean')
 option('plugin_blueprint', type: 'boolean')
+option('plugin_buildstream', type: 'boolean')
 option('plugin_c_pack', type: 'boolean')
 option('plugin_cargo', type: 'boolean')
 option('plugin_clang', type: 'boolean')
diff --git a/src/plugins/buildstream/buildstream-plugin.c b/src/plugins/buildstream/buildstream-plugin.c
new file mode 100644
index 000000000..b26285540
--- /dev/null
+++ b/src/plugins/buildstream/buildstream-plugin.c
@@ -0,0 +1,47 @@
+/* buildstream-plugin.c
+ *
+ * Copyright 2016-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 "buildstream-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-editor.h>
+#include <libide-gui.h>
+#include <libide-tree.h>
+
+#include "gbp-buildstream-build-system.h"
+#include "gbp-buildstream-build-system-discovery.h"
+#include "gbp-buildstream-pipeline-addin.h"
+
+_IDE_EXTERN void
+_gbp_buildstream_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUILD_SYSTEM,
+                                              GBP_TYPE_BUILDSTREAM_BUILD_SYSTEM);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUILD_SYSTEM_DISCOVERY,
+                                              GBP_TYPE_BUILDSTREAM_BUILD_SYSTEM_DISCOVERY);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_PIPELINE_ADDIN,
+                                              GBP_TYPE_BUILDSTREAM_PIPELINE_ADDIN);
+}
diff --git a/src/plugins/buildstream/buildstream.gresource.xml 
b/src/plugins/buildstream/buildstream.gresource.xml
new file mode 100644
index 000000000..f4c0df8f4
--- /dev/null
+++ b/src/plugins/buildstream/buildstream.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/buildstream">
+    <file>buildstream.plugin</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/buildstream/buildstream.plugin b/src/plugins/buildstream/buildstream.plugin
index b15837f77..c27f99613 100644
--- a/src/plugins/buildstream/buildstream.plugin
+++ b/src/plugins/buildstream/buildstream.plugin
@@ -1,11 +1,11 @@
 [Plugin]
-Authors=Adam
+Authors=Adam, Christian Hergert
 Builtin=true
-Description=Provides integration with the BuildStream build tool
-Hidden=true
-Loader=python3
-Module=buildstream_plugin
+Copyright=Copyright 2019 Adam, 2022 Christian Hergert <chergert redhat com>
+Description=Provides integration with BuildStream projects
+Embedded=_gbp_buildstream_register_types
+Module=buildstream
 Name=BuildStream
-X-Builder-ABI=@PACKAGE_ABI@
+X-Category=buildsystems
 X-Project-File-Filter-Name=BuildStream (project.conf)
 X-Project-File-Filter-Pattern=project.conf
diff --git a/src/plugins/buildstream/gbp-buildstream-build-system-discovery.c 
b/src/plugins/buildstream/gbp-buildstream-build-system-discovery.c
new file mode 100644
index 000000000..b03416566
--- /dev/null
+++ b/src/plugins/buildstream/gbp-buildstream-build-system-discovery.c
@@ -0,0 +1,47 @@
+/* gbp-buildstream-build-system-discovery.c
+ *
+ * Copyright 2016-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-buildstream-build-system-discovery"
+
+#include "config.h"
+
+#include "gbp-buildstream-build-system-discovery.h"
+
+struct _GbpBuildstreamBuildSystemDiscovery
+{
+  IdeSimpleBuildSystemDiscovery parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GbpBuildstreamBuildSystemDiscovery, gbp_buildstream_build_system_discovery, 
IDE_TYPE_SIMPLE_BUILD_SYSTEM_DISCOVERY)
+
+static void
+gbp_buildstream_build_system_discovery_class_init (GbpBuildstreamBuildSystemDiscoveryClass *klass)
+{
+}
+
+static void
+gbp_buildstream_build_system_discovery_init (GbpBuildstreamBuildSystemDiscovery *self)
+{
+  g_object_set (self,
+                "glob", "project.conf",
+                "hint", "buildstream",
+                "priority", 2000,
+                NULL);
+}
diff --git a/src/plugins/buildstream/gbp-buildstream-build-system-discovery.h 
b/src/plugins/buildstream/gbp-buildstream-build-system-discovery.h
new file mode 100644
index 000000000..61e8a2976
--- /dev/null
+++ b/src/plugins/buildstream/gbp-buildstream-build-system-discovery.h
@@ -0,0 +1,31 @@
+/* gbp-buildstream-build-system-discovery.h
+ *
+ * Copyright 2016-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_BUILDSTREAM_BUILD_SYSTEM_DISCOVERY (gbp_buildstream_build_system_discovery_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpBuildstreamBuildSystemDiscovery, gbp_buildstream_build_system_discovery, GBP, 
BUILDSTREAM_BUILD_SYSTEM_DISCOVERY, IdeSimpleBuildSystemDiscovery)
+
+G_END_DECLS
diff --git a/src/plugins/buildstream/gbp-buildstream-build-system.c 
b/src/plugins/buildstream/gbp-buildstream-build-system.c
new file mode 100644
index 000000000..a04f2ac0d
--- /dev/null
+++ b/src/plugins/buildstream/gbp-buildstream-build-system.c
@@ -0,0 +1,142 @@
+/* gbp-buildstream-build-system.c
+ *
+ * Copyright 2016-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-buildstream-build-system"
+
+#include "config.h"
+
+#include <libide-foundry.h>
+
+#include "gbp-buildstream-build-system.h"
+
+struct _GbpBuildstreamBuildSystem
+{
+  IdeObject  parent_instance;
+  GFile     *project_file;
+};
+
+enum {
+  PROP_0,
+  PROP_PROJECT_FILE,
+  N_PROPS
+};
+
+static char *
+gbp_buildstream_build_system_get_id (IdeBuildSystem *build_system)
+{
+  return g_strdup ("buildstream");
+}
+
+static char *
+gbp_buildstream_build_system_get_display_name (IdeBuildSystem *build_system)
+{
+  return g_strdup ("BuildStream");
+}
+
+static int
+gbp_buildstream_build_system_get_priority (IdeBuildSystem *build_system)
+{
+  return 2000;
+}
+
+static void
+build_system_iface_init (IdeBuildSystemInterface *iface)
+{
+  iface->get_id = gbp_buildstream_build_system_get_id;
+  iface->get_display_name = gbp_buildstream_build_system_get_display_name;
+  iface->get_priority = gbp_buildstream_build_system_get_priority;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpBuildstreamBuildSystem, gbp_buildstream_build_system, IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_SYSTEM, build_system_iface_init))
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+gbp_buildstream_build_system_dispose (GObject *object)
+{
+  GbpBuildstreamBuildSystem *self = (GbpBuildstreamBuildSystem *)object;
+
+  g_clear_object (&self->project_file);
+
+  G_OBJECT_CLASS (gbp_buildstream_build_system_parent_class)->dispose (object);
+}
+
+static void
+gbp_buildstream_build_system_get_property (GObject    *object,
+                                           guint       prop_id,
+                                           GValue     *value,
+                                           GParamSpec *pspec)
+{
+  GbpBuildstreamBuildSystem *self = GBP_BUILDSTREAM_BUILD_SYSTEM (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROJECT_FILE:
+      g_value_set_object (value, self->project_file);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_buildstream_build_system_set_property (GObject      *object,
+                                           guint         prop_id,
+                                           const GValue *value,
+                                           GParamSpec   *pspec)
+{
+  GbpBuildstreamBuildSystem *self = GBP_BUILDSTREAM_BUILD_SYSTEM (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROJECT_FILE:
+      g_set_object (&self->project_file, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_buildstream_build_system_class_init (GbpBuildstreamBuildSystemClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = gbp_buildstream_build_system_dispose;
+  object_class->get_property = gbp_buildstream_build_system_get_property;
+  object_class->set_property = gbp_buildstream_build_system_set_property;
+
+  properties [PROP_PROJECT_FILE] =
+    g_param_spec_object ("project-file",
+                         "Project File",
+                         "The project file (Buildstream.toml)",
+                         G_TYPE_FILE,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+gbp_buildstream_build_system_init (GbpBuildstreamBuildSystem *self)
+{
+}
diff --git a/src/plugins/buildstream/gbp-buildstream-build-system.h 
b/src/plugins/buildstream/gbp-buildstream-build-system.h
new file mode 100644
index 000000000..bdf820598
--- /dev/null
+++ b/src/plugins/buildstream/gbp-buildstream-build-system.h
@@ -0,0 +1,31 @@
+/* gbp-buildstream-build-system.h
+ *
+ * Copyright 2016-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_BUILDSTREAM_BUILD_SYSTEM (gbp_buildstream_build_system_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpBuildstreamBuildSystem, gbp_buildstream_build_system, GBP, 
BUILDSTREAM_BUILD_SYSTEM, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/buildstream/gbp-buildstream-pipeline-addin.c 
b/src/plugins/buildstream/gbp-buildstream-pipeline-addin.c
new file mode 100644
index 000000000..bfebdde78
--- /dev/null
+++ b/src/plugins/buildstream/gbp-buildstream-pipeline-addin.c
@@ -0,0 +1,112 @@
+/* gbp-buildstream-pipeline-addin.c
+ *
+ * Copyright 2016-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-buildstream-pipeline-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-buildstream-build-system.h"
+#include "gbp-buildstream-pipeline-addin.h"
+
+struct _GbpBuildstreamPipelineAddin
+{
+  IdeObject parent_instance;
+};
+
+static void
+query_cb (IdePipelineStage *stage,
+          IdePipeline      *pipeline,
+          GPtrArray        *targets,
+          GCancellable     *cancellable,
+          gpointer          user_data)
+{
+  g_assert (IDE_IS_PIPELINE_STAGE (stage));
+  g_assert (IDE_IS_PIPELINE (pipeline));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  /* Always defer to buildstream to check if build is needed */
+  ide_pipeline_stage_set_completed (stage, FALSE);
+}
+
+static void
+gbp_buildstream_pipeline_addin_load (IdePipelineAddin *addin,
+                                     IdePipeline      *pipeline)
+{
+  g_autoptr(IdeSubprocessLauncher) fetch_launcher = NULL;
+  g_autoptr(IdeSubprocessLauncher) build_launcher = NULL;
+  g_autoptr(IdeSubprocessLauncher) clean_launcher = NULL;
+  IdeBuildSystem *build_system;
+  IdePipelineStage *stage;
+  IdeContext *context;
+  guint id;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_BUILDSTREAM_PIPELINE_ADDIN (addin));
+  g_assert (IDE_IS_PIPELINE (pipeline));
+
+  context = ide_object_get_context (IDE_OBJECT (addin));
+  build_system = ide_build_system_from_context (context);
+
+  if (!GBP_IS_BUILDSTREAM_BUILD_SYSTEM (build_system))
+    IDE_EXIT;
+
+  if (!ide_pipeline_contains_program_in_path (pipeline, "bst", NULL))
+    {
+      ide_object_message (addin, "%s",
+                          _("BuildStream project in use but “bst” executable could not be found."));
+      IDE_EXIT;
+    }
+
+  build_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+  ide_subprocess_launcher_set_cwd (build_launcher, ide_pipeline_get_srcdir (pipeline));
+  ide_subprocess_launcher_push_args (build_launcher, IDE_STRV_INIT ("bst", "build"));
+
+  stage = ide_pipeline_stage_launcher_new (context, build_launcher);
+  ide_pipeline_stage_set_name (stage, _("Building project"));
+  g_signal_connect (stage, "query", G_CALLBACK (query_cb), NULL);
+  id = ide_pipeline_attach (pipeline, IDE_PIPELINE_PHASE_BUILD, 0, stage);
+  ide_pipeline_addin_track (addin, id);
+
+  IDE_EXIT;
+}
+
+static void
+pipeline_addin_iface_init (IdePipelineAddinInterface *iface)
+{
+  iface->load = gbp_buildstream_pipeline_addin_load;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpBuildstreamPipelineAddin, gbp_buildstream_pipeline_addin, IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_PIPELINE_ADDIN, pipeline_addin_iface_init))
+
+static void
+gbp_buildstream_pipeline_addin_class_init (GbpBuildstreamPipelineAddinClass *klass)
+{
+}
+
+static void
+gbp_buildstream_pipeline_addin_init (GbpBuildstreamPipelineAddin *self)
+{
+}
diff --git a/src/plugins/buildstream/gbp-buildstream-pipeline-addin.h 
b/src/plugins/buildstream/gbp-buildstream-pipeline-addin.h
new file mode 100644
index 000000000..825be21af
--- /dev/null
+++ b/src/plugins/buildstream/gbp-buildstream-pipeline-addin.h
@@ -0,0 +1,31 @@
+/* gbp-buildstream-pipeline-addin.h
+ *
+ * Copyright 2016-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_BUILDSTREAM_PIPELINE_ADDIN (gbp_buildstream_pipeline_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpBuildstreamPipelineAddin, gbp_buildstream_pipeline_addin, GBP, 
BUILDSTREAM_PIPELINE_ADDIN, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/buildstream/meson.build b/src/plugins/buildstream/meson.build
index 6b7835a94..51c214032 100644
--- a/src/plugins/buildstream/meson.build
+++ b/src/plugins/buildstream/meson.build
@@ -1,9 +1,18 @@
-install_data('buildstream_plugin.py', install_dir: plugindir)
-
-configure_file(
-    input: 'buildstream.plugin',
-    output: 'buildstream.plugin',
-    configuration: config_h,
-    install: true,
-    install_dir: plugindir,
+if get_option('plugin_buildstream')
+
+plugins_sources += files([
+  'buildstream-plugin.c',
+  'gbp-buildstream-build-system-discovery.c',
+  'gbp-buildstream-build-system.c',
+  'gbp-buildstream-pipeline-addin.c',
+])
+
+plugin_buildstream_resources = gnome.compile_resources(
+  'buildstream-resources',
+  'buildstream.gresource.xml',
+  c_name: 'gbp_buildstream',
 )
+
+plugins_sources += plugin_buildstream_resources
+
+endif
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 8d615f82f..795e5577a 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -151,6 +151,7 @@ status += [
   '',
   'Autotools ............................ : @0@'.format(get_option('plugin_autotools')),
   'Beautifier ........................... : @0@'.format(get_option('plugin_beautifier')),
+  'BuildStream .......................... : @0@'.format(get_option('plugin_buildstream')),
   'C Pack ............................... : @0@'.format(get_option('plugin_c_pack')),
   'Cargo ................................ : @0@'.format(get_option('plugin_cargo')),
   'Clang Format ......................... : @0@'.format(get_option('plugin_clang_format')),


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