[gnome-builder/wip/gtk4-port] plugins/phpize: port phpize build system plugin to C



commit 150d1de86a68106318497603dbb0190e42df7166
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 25 16:30:43 2022 -0700

    plugins/phpize: port phpize build system plugin to C
    
    Part of #1670

 .../phpize/gbp-phpize-build-system-discovery.c     |  83 +++++
 .../phpize/gbp-phpize-build-system-discovery.h     |  31 ++
 src/plugins/phpize/gbp-phpize-build-system.c       | 352 +++++++++++++++++++++
 src/plugins/phpize/gbp-phpize-build-system.h       |  31 ++
 src/plugins/phpize/gbp-phpize-pipeline-addin.c     | 175 ++++++++++
 src/plugins/phpize/gbp-phpize-pipeline-addin.h     |  31 ++
 src/plugins/phpize/meson.build                     |  21 +-
 src/plugins/phpize/phpize-plugin.c                 |  47 +++
 src/plugins/phpize/phpize.gresource.xml            |   6 +
 src/plugins/phpize/phpize.plugin                   |  11 +-
 src/plugins/phpize/phpize_plugin.py                | 234 --------------
 11 files changed, 774 insertions(+), 248 deletions(-)
---
diff --git a/src/plugins/phpize/gbp-phpize-build-system-discovery.c 
b/src/plugins/phpize/gbp-phpize-build-system-discovery.c
new file mode 100644
index 000000000..07c1b3d30
--- /dev/null
+++ b/src/plugins/phpize/gbp-phpize-build-system-discovery.c
@@ -0,0 +1,83 @@
+/* gbp-phpize-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-phpize-build-system-discovery"
+
+#include "config.h"
+
+#include "gbp-phpize-build-system-discovery.h"
+
+struct _GbpPhpizeBuildSystemDiscovery
+{
+  IdeSimpleBuildSystemDiscovery parent_instance;
+};
+
+static char *
+gbp_phpize_build_system_discovery_discover (IdeBuildSystemDiscovery  *discovery,
+                                            GFile                    *directory,
+                                            GCancellable             *cancellable,
+                                            int                      *priority,
+                                            GError                  **error)
+{
+  g_autoptr(GFile) config_m4 = NULL;
+  g_autofree char *contents = NULL;
+  char *ret = NULL;
+  gsize len;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_PHPIZE_BUILD_SYSTEM_DISCOVERY (discovery));
+  g_assert (G_IS_FILE (directory));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+  g_assert (priority != NULL);
+
+  config_m4 = g_file_get_child (directory, "config.m4");
+
+  if (g_file_load_contents (config_m4, cancellable, &contents, &len, NULL, NULL))
+    {
+      if (strstr (contents, "PHP_ARG_ENABLE") != NULL)
+        {
+          g_debug ("Found PHP_ARG_ENABLE in configure.ac");
+          ret = g_strdup ("phpize");
+          *priority = 1000;
+        }
+    }
+
+  IDE_RETURN (ret);
+}
+
+static void
+build_system_discovery_iface_init (IdeBuildSystemDiscoveryInterface *iface)
+{
+  iface->discover = gbp_phpize_build_system_discovery_discover;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpPhpizeBuildSystemDiscovery, gbp_phpize_build_system_discovery, 
G_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_SYSTEM_DISCOVERY, 
build_system_discovery_iface_init))
+
+static void
+gbp_phpize_build_system_discovery_class_init (GbpPhpizeBuildSystemDiscoveryClass *klass)
+{
+}
+
+static void
+gbp_phpize_build_system_discovery_init (GbpPhpizeBuildSystemDiscovery *self)
+{
+}
diff --git a/src/plugins/phpize/gbp-phpize-build-system-discovery.h 
b/src/plugins/phpize/gbp-phpize-build-system-discovery.h
new file mode 100644
index 000000000..fe4348a46
--- /dev/null
+++ b/src/plugins/phpize/gbp-phpize-build-system-discovery.h
@@ -0,0 +1,31 @@
+/* gbp-phpize-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_PHPIZE_BUILD_SYSTEM_DISCOVERY (gbp_phpize_build_system_discovery_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpPhpizeBuildSystemDiscovery, gbp_phpize_build_system_discovery, GBP, 
PHPIZE_BUILD_SYSTEM_DISCOVERY, IdeSimpleBuildSystemDiscovery)
+
+G_END_DECLS
diff --git a/src/plugins/phpize/gbp-phpize-build-system.c b/src/plugins/phpize/gbp-phpize-build-system.c
new file mode 100644
index 000000000..547ff25a1
--- /dev/null
+++ b/src/plugins/phpize/gbp-phpize-build-system.c
@@ -0,0 +1,352 @@
+/* gbp-phpize-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-phpize-build-system"
+
+#include "config.h"
+
+#include <libide-foundry.h>
+#include <libide-io.h>
+
+#include "gbp-phpize-build-system.h"
+
+#define BUILD_FLAGS_STDIN_BUF "\n\
+include Makefile\n\
+\n\
+print-%: ; @echo $* = $($*)\n\
+"
+
+struct _GbpPhpizeBuildSystem
+{
+  IdeObject  parent_instance;
+  GFile     *project_file;
+};
+
+enum {
+  PROP_0,
+  PROP_PROJECT_FILE,
+  N_PROPS
+};
+
+typedef enum {
+  FILE_TYPE_UNKNOWN,
+  FILE_TYPE_C,
+  FILE_TYPE_CPP,
+} FileType;
+
+static guint
+get_file_type (const char *path)
+{
+  static const char * const c_suffix[] = IDE_STRV_INIT (".c", ".h");
+  static const char * const cpp_suffix[] = IDE_STRV_INIT (".cpp", ".c++", ".cxx", ".cc", ".hpp", ".h++", 
".hxx", ".hh");
+  const char *suffix = strrchr (path, '.');
+
+  if (suffix == NULL)
+    return FILE_TYPE_UNKNOWN;
+
+  if (g_strv_contains (c_suffix, suffix))
+    return FILE_TYPE_C;
+
+  if (g_strv_contains (cpp_suffix, suffix))
+    return FILE_TYPE_CPP;
+
+  return FILE_TYPE_UNKNOWN;
+}
+
+static char *
+gbp_phpize_build_system_get_id (IdeBuildSystem *build_system)
+{
+  return g_strdup ("phpize");
+}
+
+static char *
+gbp_phpize_build_system_get_display_name (IdeBuildSystem *build_system)
+{
+  return g_strdup ("PHP Build System");
+}
+
+static int
+gbp_phpize_build_system_get_priority (IdeBuildSystem *build_system)
+{
+  return 3000;
+}
+
+static void
+gbp_phpize_build_system_communicate_cb (GObject      *object,
+                                        GAsyncResult *result,
+                                        gpointer      user_data)
+{
+  IdeSubprocess *subprocess = (IdeSubprocess *)object;
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GError) error = NULL;
+  g_autofree char *stdout_buf = NULL;
+  g_autoptr(GString) str = NULL;
+  g_auto(GStrv) argv = NULL;
+  IdeLineReader reader;
+  const char *key = NULL;
+  FileType file_type;
+  char *line;
+  gsize line_len;
+  int argc;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_SUBPROCESS (subprocess));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_TASK (task));
+
+  file_type = GPOINTER_TO_INT (ide_task_get_task_data (task));
+  g_assert (file_type != FILE_TYPE_UNKNOWN);
+
+  if (!ide_subprocess_communicate_utf8_finish (subprocess, result, &stdout_buf, NULL, &error))
+    {
+      ide_task_return_error (task, g_steal_pointer (&error));
+      IDE_EXIT;
+    }
+
+  switch (file_type)
+    {
+    case FILE_TYPE_C: key = "CFLAGS="; break;
+    case FILE_TYPE_CPP: key = "CPPFLAGS="; break;
+    case FILE_TYPE_UNKNOWN:
+    default:
+      g_assert_not_reached ();
+    }
+
+  str = g_string_new (NULL);
+
+  ide_line_reader_init (&reader, stdout_buf, -1);
+  while ((line = ide_line_reader_next (&reader, &line_len)))
+    {
+      line[line_len] = 0;
+
+      if (g_str_has_prefix (line, "INCLUDES="))
+        {
+          g_string_append (str, &line[strlen ("INCLUDES=")]);
+          g_string_append_c (str, ' ');
+          continue;
+        }
+
+      if (g_str_has_prefix (line, key))
+        {
+          g_string_append (str, &line[strlen (key)]);
+          g_string_append_c (str, ' ');
+          continue;
+        }
+    }
+
+  if (str->len == 0)
+    {
+      ide_task_return_unsupported_error (task);
+      IDE_EXIT;
+    }
+
+  if (!g_shell_parse_argv (str->str, &argc, &argv, &error))
+    ide_task_return_error (task, g_steal_pointer (&error));
+  else
+    ide_task_return_pointer (task, g_steal_pointer (&argv), g_strfreev);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_phpize_build_system_get_build_flags_async (IdeBuildSystem      *build_system,
+                                               GFile               *file,
+                                               GCancellable        *cancellable,
+                                               GAsyncReadyCallback  callback,
+                                               gpointer             user_data)
+{
+  GbpPhpizeBuildSystem *self = (GbpPhpizeBuildSystem *)build_system;
+  g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+  g_autoptr(IdeSubprocess) subprocess = NULL;
+  g_autoptr(IdeTask) task = NULL;
+  g_autoptr(GError) error = NULL;
+  IdeBuildManager *build_manager;
+  IdePipeline *pipeline;
+  IdeContext *context;
+  FileType file_type;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_PHPIZE_BUILD_SYSTEM (self));
+  g_assert (!file || G_IS_FILE (file));
+  g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = ide_task_new (self, cancellable, callback, user_data);
+  ide_task_set_source_tag (task, gbp_phpize_build_system_get_build_flags_async);
+
+  if (!(file_type = get_file_type (g_file_peek_path (file))))
+    {
+      ide_task_return_unsupported_error (task);
+      IDE_EXIT;
+    }
+
+  ide_task_set_task_data (task, GINT_TO_POINTER (file_type), (GDestroyNotify)NULL);
+
+  /* To get the build flags, we run make with some custom code to
+   * print variables, and then extract the values based on the file type.
+   * But the pipeline must be configured for us to do that. If not, just
+   * bail as most things don't want to force a build directly.
+   */
+  context = ide_object_get_context (IDE_OBJECT (self));
+  build_manager = ide_build_manager_from_context (context);
+  pipeline = ide_build_manager_get_pipeline (build_manager);
+
+  if (pipeline == NULL ||
+      !ide_pipeline_is_ready (pipeline) ||
+      ide_pipeline_get_phase (pipeline) < IDE_PIPELINE_PHASE_CONFIGURE)
+    {
+      g_debug ("Pipeline not ready, cannot extract build flags");
+      ide_task_return_unsupported_error (task);
+      IDE_EXIT;
+    }
+
+  if (!(launcher = ide_pipeline_create_launcher (pipeline, &error)))
+    {
+      ide_task_return_error (task, g_steal_pointer (&error));
+      IDE_EXIT;
+    }
+
+  ide_subprocess_launcher_set_flags (launcher,
+                                     (G_SUBPROCESS_FLAGS_STDIN_PIPE |
+                                      G_SUBPROCESS_FLAGS_STDOUT_PIPE |
+                                      G_SUBPROCESS_FLAGS_STDERR_SILENCE));
+  ide_subprocess_launcher_setenv (launcher, "V", "0", TRUE);
+  ide_subprocess_launcher_push_args (launcher, IDE_STRV_INIT ("make", "-f", "-", "print-CFLAGS", 
"print-CXXFLAGS", "print-INCLUDES"));
+
+  if (!(subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, &error)))
+    {
+      ide_task_return_error (task, g_steal_pointer (&error));
+      IDE_EXIT;
+    }
+
+  ide_subprocess_communicate_utf8_async (subprocess,
+                                         BUILD_FLAGS_STDIN_BUF,
+                                         cancellable,
+                                         gbp_phpize_build_system_communicate_cb,
+                                         g_steal_pointer (&task));
+
+  IDE_EXIT;
+}
+
+static char **
+gbp_phpize_build_system_get_build_flags_finish (IdeBuildSystem  *build_system,
+                                                GAsyncResult    *result,
+                                                GError         **error)
+{
+  char **ret;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_PHPIZE_BUILD_SYSTEM (build_system));
+  g_assert (IDE_IS_TASK (result));
+
+  ret = ide_task_propagate_pointer (IDE_TASK (result), error);
+
+  IDE_RETURN (ret);
+}
+
+static void
+build_system_iface_init (IdeBuildSystemInterface *iface)
+{
+  iface->get_id = gbp_phpize_build_system_get_id;
+  iface->get_display_name = gbp_phpize_build_system_get_display_name;
+  iface->get_priority = gbp_phpize_build_system_get_priority;
+  iface->get_build_flags_async = gbp_phpize_build_system_get_build_flags_async;
+  iface->get_build_flags_finish = gbp_phpize_build_system_get_build_flags_finish;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpPhpizeBuildSystem, gbp_phpize_build_system, IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_SYSTEM, build_system_iface_init))
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+gbp_phpize_build_system_dispose (GObject *object)
+{
+  GbpPhpizeBuildSystem *self = (GbpPhpizeBuildSystem *)object;
+
+  g_clear_object (&self->project_file);
+
+  G_OBJECT_CLASS (gbp_phpize_build_system_parent_class)->dispose (object);
+}
+
+static void
+gbp_phpize_build_system_get_property (GObject    *object,
+                                     guint       prop_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec)
+{
+  GbpPhpizeBuildSystem *self = GBP_PHPIZE_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_phpize_build_system_set_property (GObject      *object,
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
+{
+  GbpPhpizeBuildSystem *self = GBP_PHPIZE_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_phpize_build_system_class_init (GbpPhpizeBuildSystemClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = gbp_phpize_build_system_dispose;
+  object_class->get_property = gbp_phpize_build_system_get_property;
+  object_class->set_property = gbp_phpize_build_system_set_property;
+
+  properties [PROP_PROJECT_FILE] =
+    g_param_spec_object ("project-file",
+                         "Project File",
+                         "The project file (Phpize.toml)",
+                         G_TYPE_FILE,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+gbp_phpize_build_system_init (GbpPhpizeBuildSystem *self)
+{
+}
diff --git a/src/plugins/phpize/gbp-phpize-build-system.h b/src/plugins/phpize/gbp-phpize-build-system.h
new file mode 100644
index 000000000..abd9b22ab
--- /dev/null
+++ b/src/plugins/phpize/gbp-phpize-build-system.h
@@ -0,0 +1,31 @@
+/* gbp-phpize-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_PHPIZE_BUILD_SYSTEM (gbp_phpize_build_system_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpPhpizeBuildSystem, gbp_phpize_build_system, GBP, PHPIZE_BUILD_SYSTEM, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/phpize/gbp-phpize-pipeline-addin.c b/src/plugins/phpize/gbp-phpize-pipeline-addin.c
new file mode 100644
index 000000000..47f5e3a56
--- /dev/null
+++ b/src/plugins/phpize/gbp-phpize-pipeline-addin.c
@@ -0,0 +1,175 @@
+/* gbp-phpize-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-phpize-pipeline-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-phpize-build-system.h"
+#include "gbp-phpize-pipeline-addin.h"
+
+struct _GbpPhpizePipelineAddin
+{
+  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 make to check if build is needed */
+  ide_pipeline_stage_set_completed (stage, FALSE);
+}
+
+static void
+gbp_phpize_pipeline_addin_load (IdePipelineAddin *addin,
+                               IdePipeline      *pipeline)
+{
+  g_autoptr(IdeSubprocessLauncher) bootstrap_launcher = NULL;
+  g_autoptr(IdeSubprocessLauncher) config_launcher = NULL;
+  g_autoptr(IdeSubprocessLauncher) build_launcher = NULL;
+  g_autoptr(IdeSubprocessLauncher) clean_launcher = NULL;
+  g_autoptr(IdeSubprocessLauncher) install_launcher = NULL;
+  g_autoptr(IdePipelineStage) bootstrap_stage = NULL;
+  g_autoptr(IdePipelineStage) config_stage = NULL;
+  g_autoptr(IdePipelineStage) build_stage = NULL;
+  g_autoptr(IdePipelineStage) install_stage = NULL;
+  g_autoptr(GError) error = NULL;
+  g_autofree char *configure_path = NULL;
+  g_auto(GStrv) config_argv = NULL;
+  IdeBuildSystem *build_system;
+  const char *builddir;
+  const char *srcdir;
+  const char *prefix;
+  const char *config_opts;
+  IdeContext *context;
+  IdeConfig *config;
+  guint id;
+  int j;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_PHPIZE_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_PHPIZE_BUILD_SYSTEM (build_system))
+    IDE_EXIT;
+
+  srcdir = ide_pipeline_get_srcdir (pipeline);
+  builddir = ide_pipeline_get_srcdir (pipeline);
+  config = ide_pipeline_get_config (pipeline);
+  config_opts = ide_config_get_config_opts (config);
+  configure_path = g_build_filename (srcdir, "configure", NULL);
+  prefix = ide_config_get_prefix (config);
+
+  if (!ide_str_empty0 (config_opts))
+    {
+      int argc;
+
+      if (!g_shell_parse_argv (config_opts, &argc, &config_argv, &error))
+        {
+          ide_object_message (addin,
+                              "%s: %s",
+                              _("Cannot parse arguments to configure"),
+                              error->message);
+          IDE_EXIT;
+        }
+    }
+
+  g_assert (IDE_IS_CONFIG (config));
+  g_assert (srcdir != NULL);
+  g_assert (builddir != NULL);
+  g_assert (prefix != NULL);
+
+  bootstrap_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+  ide_subprocess_launcher_push_argv (bootstrap_launcher, "phpize");
+  ide_subprocess_launcher_set_cwd (bootstrap_launcher, srcdir);
+  bootstrap_stage = ide_pipeline_stage_launcher_new (context, bootstrap_launcher);
+  ide_pipeline_stage_set_name (bootstrap_stage, _("Bootstrapping project"));
+  ide_pipeline_stage_set_completed (bootstrap_stage, g_file_test (configure_path, G_FILE_TEST_EXISTS));
+  id = ide_pipeline_attach (pipeline, IDE_PIPELINE_PHASE_AUTOGEN, 0, bootstrap_stage);
+  ide_pipeline_addin_track (addin, id);
+
+  config_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+  ide_subprocess_launcher_push_argv (config_launcher, configure_path);
+  ide_subprocess_launcher_push_argv_format (config_launcher, "--prefix=%s", prefix);
+  if (config_argv)
+    ide_subprocess_launcher_push_args (config_launcher, (const char * const *)config_argv);
+  config_stage = ide_pipeline_stage_launcher_new (context, config_launcher);
+  ide_pipeline_stage_set_name (config_stage, _("Configuring project"));
+  id = ide_pipeline_attach (pipeline, IDE_PIPELINE_PHASE_CONFIGURE, 0, config_stage);
+  ide_pipeline_addin_track (addin, id);
+
+  build_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+  ide_subprocess_launcher_push_argv (build_launcher, "make");
+  if ((j = ide_config_get_parallelism (config)) > 0)
+    ide_subprocess_launcher_push_argv_format (build_launcher, "-j=%d", j);
+  clean_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+  ide_subprocess_launcher_push_args (clean_launcher, IDE_STRV_INIT ("make", "clean"));
+  build_stage = ide_pipeline_stage_launcher_new (context, build_launcher);
+  ide_pipeline_stage_launcher_set_clean_launcher (IDE_PIPELINE_STAGE_LAUNCHER (build_stage), clean_launcher);
+  ide_pipeline_stage_set_name (build_stage, _("Building project"));
+  g_signal_connect (build_stage, "query", G_CALLBACK (query_cb), NULL);
+  id = ide_pipeline_attach (pipeline, IDE_PIPELINE_PHASE_BUILD, 0, build_stage);
+  ide_pipeline_addin_track (addin, id);
+
+  install_launcher = ide_pipeline_create_launcher (pipeline, NULL);
+  ide_subprocess_launcher_push_args (install_launcher, IDE_STRV_INIT ("make", "install"));
+  install_stage = ide_pipeline_stage_launcher_new (context, install_launcher);
+  ide_pipeline_stage_set_name (install_stage, _("Installing project"));
+  ide_pipeline_stage_set_completed (install_stage, g_file_test (configure_path, G_FILE_TEST_EXISTS));
+  id = ide_pipeline_attach (pipeline, IDE_PIPELINE_PHASE_INSTALL, 0, install_stage);
+  ide_pipeline_addin_track (addin, id);
+
+  IDE_EXIT;
+}
+
+static void
+pipeline_addin_iface_init (IdePipelineAddinInterface *iface)
+{
+  iface->load = gbp_phpize_pipeline_addin_load;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpPhpizePipelineAddin, gbp_phpize_pipeline_addin, IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_PIPELINE_ADDIN, pipeline_addin_iface_init))
+
+static void
+gbp_phpize_pipeline_addin_class_init (GbpPhpizePipelineAddinClass *klass)
+{
+}
+
+static void
+gbp_phpize_pipeline_addin_init (GbpPhpizePipelineAddin *self)
+{
+}
diff --git a/src/plugins/phpize/gbp-phpize-pipeline-addin.h b/src/plugins/phpize/gbp-phpize-pipeline-addin.h
new file mode 100644
index 000000000..1d9a5e98c
--- /dev/null
+++ b/src/plugins/phpize/gbp-phpize-pipeline-addin.h
@@ -0,0 +1,31 @@
+/* gbp-phpize-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_PHPIZE_PIPELINE_ADDIN (gbp_phpize_pipeline_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpPhpizePipelineAddin, gbp_phpize_pipeline_addin, GBP, PHPIZE_PIPELINE_ADDIN, 
IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/phpize/meson.build b/src/plugins/phpize/meson.build
index 0c2fab0c9..b6ef5c06e 100644
--- a/src/plugins/phpize/meson.build
+++ b/src/plugins/phpize/meson.build
@@ -1,13 +1,18 @@
 if get_option('plugin_phpize')
 
-install_data('phpize_plugin.py', install_dir: plugindir)
-
-configure_file(
-          input: 'phpize.plugin',
-         output: 'phpize.plugin',
-  configuration: config_h,
-        install: true,
-    install_dir: plugindir,
+plugins_sources += files([
+  'phpize-plugin.c',
+  'gbp-phpize-build-system-discovery.c',
+  'gbp-phpize-build-system.c',
+  'gbp-phpize-pipeline-addin.c',
+])
+
+plugin_phpize_resources = gnome.compile_resources(
+  'phpize-resources',
+  'phpize.gresource.xml',
+  c_name: 'gbp_phpize',
 )
 
+plugins_sources += plugin_phpize_resources
+
 endif
diff --git a/src/plugins/phpize/phpize-plugin.c b/src/plugins/phpize/phpize-plugin.c
new file mode 100644
index 000000000..15b28f70d
--- /dev/null
+++ b/src/plugins/phpize/phpize-plugin.c
@@ -0,0 +1,47 @@
+/* phpize-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 "phpize-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-editor.h>
+#include <libide-gui.h>
+#include <libide-tree.h>
+
+#include "gbp-phpize-build-system.h"
+#include "gbp-phpize-build-system-discovery.h"
+#include "gbp-phpize-pipeline-addin.h"
+
+_IDE_EXTERN void
+_gbp_phpize_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUILD_SYSTEM,
+                                              GBP_TYPE_PHPIZE_BUILD_SYSTEM);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUILD_SYSTEM_DISCOVERY,
+                                              GBP_TYPE_PHPIZE_BUILD_SYSTEM_DISCOVERY);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_PIPELINE_ADDIN,
+                                              GBP_TYPE_PHPIZE_PIPELINE_ADDIN);
+}
diff --git a/src/plugins/phpize/phpize.gresource.xml b/src/plugins/phpize/phpize.gresource.xml
new file mode 100644
index 000000000..f969040f0
--- /dev/null
+++ b/src/plugins/phpize/phpize.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/phpize">
+    <file>phpize.plugin</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/phpize/phpize.plugin b/src/plugins/phpize/phpize.plugin
index 1342f6628..8f62ac6d1 100644
--- a/src/plugins/phpize/phpize.plugin
+++ b/src/plugins/phpize/phpize.plugin
@@ -1,12 +1,11 @@
 [Plugin]
 Authors=Christian Hergert <chergert redhat com>
 Builtin=true
-Copyright=Copyright © 2017 Christian Hergert
+Copyright=Copyright © 2017-2022 Christian Hergert
 Description=Provides integration with phpize-based PHP extensions
-Hidden=true
-Loader=python3
-Module=phpize_plugin
-Name=PHPize
+Embedded=_gbp_phpize_register_types
+Module=phpize
+Name=PHP Build System
+X-Category=buildsystems
 X-Project-File-Filter-Name=PHPize Project (config.m4)
 X-Project-File-Filter-Pattern=config.m4
-X-Builder-ABI=@PACKAGE_ABI@


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