[gnome-builder] git: initialize git submodules from build pipeline
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] git: initialize git submodules from build pipeline
- Date: Wed, 3 Oct 2018 22:05:12 +0000 (UTC)
commit 1f9413a7e7fdfdba59bcb115873358afbb71bb02
Author: Christian Hergert <chergert redhat com>
Date: Wed Oct 3 15:04:20 2018 -0700
git: initialize git submodules from build pipeline
We can download submodules from the IDE_BUILD_PHASE_DOWNLOADS if we detect
that any are missing from `git submodule status` as lines prefixed with -.
We only run this once, to avoid being overly annoying when extracting build
flags.
This has brought to my attention that we probably also need a dependency
updater addin for submodules.
po/POTFILES.in | 1 +
src/plugins/flatpak/gbp-flatpak-download-stage.c | 2 +-
src/plugins/git/ide-git-pipeline-addin.c | 223 +++++++++++++++++++++++
src/plugins/git/ide-git-pipeline-addin.h | 31 ++++
src/plugins/git/ide-git-plugin.c | 4 +
src/plugins/git/meson.build | 2 +
6 files changed, 262 insertions(+), 1 deletion(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ceb0344ef..ac76df9d8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -178,6 +178,7 @@ src/plugins/git/ide-git-buffer-change-monitor.c
src/plugins/git/ide-git-clone-widget.c
src/plugins/git/ide-git-clone-widget.ui
src/plugins/git/ide-git-genesis-addin.c
+src/plugins/git/ide-git-pipeline-addin.c
src/plugins/git/ide-git-remote-callbacks.c
src/plugins/git/ide-git-vcs.c
src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
diff --git a/src/plugins/flatpak/gbp-flatpak-download-stage.c
b/src/plugins/flatpak/gbp-flatpak-download-stage.c
index 257c03d8e..4da62fc0e 100644
--- a/src/plugins/flatpak/gbp-flatpak-download-stage.c
+++ b/src/plugins/flatpak/gbp-flatpak-download-stage.c
@@ -65,7 +65,7 @@ gbp_flatpak_download_stage_query (IdeBuildStage *stage,
if (!ide_application_has_network (IDE_APPLICATION_DEFAULT))
{
ide_build_stage_log (stage,
- IDE_BUILD_LOG_STDOUT,
+ IDE_BUILD_LOG_STDERR,
_("Network is not available, skipping downloads"),
-1);
ide_build_stage_set_completed (stage, TRUE);
diff --git a/src/plugins/git/ide-git-pipeline-addin.c b/src/plugins/git/ide-git-pipeline-addin.c
new file mode 100644
index 000000000..ee48bf00f
--- /dev/null
+++ b/src/plugins/git/ide-git-pipeline-addin.c
@@ -0,0 +1,223 @@
+/* ide-git-pipeline-addin.c
+ *
+ * Copyright 2018 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"
+
+#define G_LOG_DOMAIN "ide-git-pipeline-addin"
+
+#include <glib/gi18n.h>
+
+#include "ide-git-pipeline-addin.h"
+#include "ide-git-vcs.h"
+
+struct _IdeGitPipelineAddin
+{
+ IdeObject parent_instance;
+ guint has_run : 1;
+};
+
+static void
+submodule_status_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdeSubprocess *subprocess = (IdeSubprocess *)object;
+ g_autoptr(IdeBuildStage) stage = user_data;
+ g_autoptr(GError) error = NULL;
+ g_autofree gchar *stdout_buf = NULL;
+ IdeLineReader reader;
+ const gchar *line;
+ gsize line_len;
+
+ g_assert (IDE_IS_SUBPROCESS (subprocess));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (IDE_IS_BUILD_STAGE_LAUNCHER (stage));
+
+ if (!ide_subprocess_communicate_utf8_finish (subprocess, result, &stdout_buf, NULL, &error))
+ {
+ ide_build_stage_log (stage,
+ IDE_BUILD_LOG_STDERR,
+ error->message,
+ -1);
+ goto failure;
+ }
+
+ ide_line_reader_init (&reader, stdout_buf, -1);
+ while ((line = ide_line_reader_next (&reader, &line_len)))
+ {
+ /* If we find a line starting with -, it isn't initialized
+ * and needs a submodule-init/update.
+ */
+ if (stdout_buf[0] == '-')
+ {
+ ide_build_stage_set_completed (stage, FALSE);
+ goto unpause;
+ }
+ }
+
+failure:
+ ide_build_stage_set_completed (stage, TRUE);
+
+unpause:
+ ide_build_stage_unpause (stage);
+}
+
+static void
+submodule_update_query_cb (IdeGitPipelineAddin *self,
+ IdeBuildPipeline *pipeline,
+ GCancellable *cancellable,
+ IdeBuildStageLauncher *stage)
+{
+ g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+ g_autoptr(IdeSubprocess) subprocess = NULL;
+ g_autoptr(GError) error = NULL;
+ IdeContext *context;
+ IdeVcs *vcs;
+ GFile *workdir;
+
+ g_assert (IDE_IS_GIT_PIPELINE_ADDIN (self));
+ g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+ g_assert (IDE_IS_BUILD_STAGE_LAUNCHER (stage));
+
+ /* Short-circuit if we've already run */
+ if (self->has_run)
+ {
+ ide_build_stage_set_completed (IDE_BUILD_STAGE (stage), TRUE);
+ return;
+ }
+
+ self->has_run = TRUE;
+
+ if (!ide_application_has_network (IDE_APPLICATION_DEFAULT))
+ {
+ ide_build_stage_log (IDE_BUILD_STAGE (stage),
+ IDE_BUILD_LOG_STDERR,
+ _("Network is not available, skipping submodule update"),
+ -1);
+ ide_build_stage_set_completed (IDE_BUILD_STAGE (stage), TRUE);
+ return;
+ }
+
+ /* We need to run "git submodule status" to see if there are any
+ * lines that are prefixed with - (meaning they have not yet been
+ * initialized).
+ *
+ * We only do a git submodule init/update if that is the case, otherwise
+ * dependencies are updated with the dependency updater.
+ */
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ vcs = ide_context_get_vcs (context);
+ workdir = ide_vcs_get_working_directory (vcs);
+
+ launcher = ide_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
+ ide_subprocess_launcher_push_argv (launcher, "git");
+ ide_subprocess_launcher_push_argv (launcher, "submodule");
+ ide_subprocess_launcher_push_argv (launcher, "status");
+ ide_subprocess_launcher_set_cwd (launcher, g_file_peek_path (workdir));
+ ide_subprocess_launcher_set_clear_env (launcher, FALSE);
+
+ if (!(subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, &error)))
+ {
+ ide_build_stage_log (IDE_BUILD_STAGE (stage),
+ IDE_BUILD_LOG_STDERR,
+ error->message,
+ -1);
+ ide_build_stage_set_completed (IDE_BUILD_STAGE (stage), TRUE);
+ return;
+ }
+
+ ide_build_stage_pause (IDE_BUILD_STAGE (stage));
+
+ ide_subprocess_communicate_utf8_async (subprocess,
+ NULL,
+ cancellable,
+ submodule_status_cb,
+ g_object_ref (stage));
+}
+
+static void
+ide_git_pipeline_addin_load (IdeBuildPipelineAddin *addin,
+ IdeBuildPipeline *pipeline)
+{
+ g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+ g_autoptr(GError) error = NULL;
+ IdeBuildStage *stage;
+ IdeContext *context;
+ IdeVcs *vcs;
+ GFile *workdir;
+ guint stage_id;
+
+ g_assert (IDE_IS_GIT_PIPELINE_ADDIN (addin));
+ g_assert (IDE_IS_BUILD_PIPELINE (pipeline));
+
+ context = ide_object_get_context (IDE_OBJECT (addin));
+ vcs = ide_context_get_vcs (context);
+ workdir = ide_vcs_get_working_directory (vcs);
+
+ /* Ignore everything if this isn't a git-based repository */
+ if (!IDE_IS_GIT_VCS (vcs))
+ return;
+
+ launcher = ide_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
+ G_SUBPROCESS_FLAGS_STDERR_PIPE);
+ ide_subprocess_launcher_set_clear_env (launcher, FALSE);
+ ide_subprocess_launcher_set_cwd (launcher, g_file_peek_path (workdir));
+ ide_subprocess_launcher_push_argv (launcher, "sh");
+ ide_subprocess_launcher_push_argv (launcher, "-c");
+ ide_subprocess_launcher_push_argv (launcher, "git submodule init && git submodule update");
+
+ stage_id = ide_build_pipeline_connect_launcher (pipeline,
+ IDE_BUILD_PHASE_DOWNLOADS,
+ 100,
+ launcher);
+ stage = ide_build_pipeline_get_stage_by_id (pipeline, stage_id);
+ ide_build_pipeline_addin_track (addin, stage_id);
+
+ ide_build_stage_launcher_set_ignore_exit_status (IDE_BUILD_STAGE_LAUNCHER (stage), TRUE);
+ ide_build_stage_set_name (stage, _("Initialize git submodules"));
+
+ g_signal_connect_object (stage,
+ "query",
+ G_CALLBACK (submodule_update_query_cb),
+ addin,
+ G_CONNECT_SWAPPED);
+}
+
+static void
+build_pipeline_addin_iface_init (IdeBuildPipelineAddinInterface *iface)
+{
+ iface->load = ide_git_pipeline_addin_load;
+}
+
+G_DEFINE_TYPE_WITH_CODE (IdeGitPipelineAddin, ide_git_pipeline_addin, IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_BUILD_PIPELINE_ADDIN,
+ build_pipeline_addin_iface_init))
+
+static void
+ide_git_pipeline_addin_class_init (IdeGitPipelineAddinClass *klass)
+{
+}
+
+static void
+ide_git_pipeline_addin_init (IdeGitPipelineAddin *self)
+{
+}
diff --git a/src/plugins/git/ide-git-pipeline-addin.h b/src/plugins/git/ide-git-pipeline-addin.h
new file mode 100644
index 000000000..e66df7a96
--- /dev/null
+++ b/src/plugins/git/ide-git-pipeline-addin.h
@@ -0,0 +1,31 @@
+/* ide-git-pipeline-addin.h
+ *
+ * Copyright 2018 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 <ide.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_GIT_PIPELINE_ADDIN (ide_git_pipeline_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeGitPipelineAddin, ide_git_pipeline_addin, IDE, GIT_PIPELINE_ADDIN, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/git/ide-git-plugin.c b/src/plugins/git/ide-git-plugin.c
index 53bd2559f..ac790b09d 100644
--- a/src/plugins/git/ide-git-plugin.c
+++ b/src/plugins/git/ide-git-plugin.c
@@ -20,6 +20,7 @@
#include <ide.h>
#include "ide-git-genesis-addin.h"
+#include "ide-git-pipeline-addin.h"
#include "ide-git-remote-callbacks.h"
#include "ide-git-vcs.h"
#include "ide-git-vcs-config.h"
@@ -72,6 +73,9 @@ ide_git_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_GENESIS_ADDIN,
IDE_TYPE_GIT_GENESIS_ADDIN);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_BUILD_PIPELINE_ADDIN,
+ IDE_TYPE_GIT_PIPELINE_ADDIN);
ide_vcs_register_ignored (".git");
}
diff --git a/src/plugins/git/meson.build b/src/plugins/git/meson.build
index fdd949942..e25d29701 100644
--- a/src/plugins/git/meson.build
+++ b/src/plugins/git/meson.build
@@ -13,6 +13,8 @@ git_sources = [
'ide-git-clone-widget.h',
'ide-git-genesis-addin.c',
'ide-git-genesis-addin.h',
+ 'ide-git-pipeline-addin.c',
+ 'ide-git-pipeline-addin.h',
'ide-git-plugin.c',
'ide-git-remote-callbacks.c',
'ide-git-remote-callbacks.h',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]