[gnome-builder] plugins/autotools: port to run context
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/autotools: port to run context
- Date: Thu, 15 Sep 2022 23:00:15 +0000 (UTC)
commit be9a2692cfea03356ac2a93b040e0e6e52037a19
Author: Christian Hergert <chergert redhat com>
Date: Thu Sep 15 16:00:06 2022 -0700
plugins/autotools: port to run context
The makecache still needs work, but since it is doing some dicey thread
things with the pipeline, I can't port makecache at this time. We need to
create our launcher/run-context up front rather than in the worker.
.../autotools/ide-autotools-autogen-stage.c | 45 +++++----
src/plugins/autotools/ide-autotools-make-stage.c | 47 +++++----
.../autotools/ide-autotools-makecache-stage.c | 20 ++--
.../autotools/ide-autotools-pipeline-addin.c | 111 ++++++++++-----------
4 files changed, 113 insertions(+), 110 deletions(-)
---
diff --git a/src/plugins/autotools/ide-autotools-autogen-stage.c
b/src/plugins/autotools/ide-autotools-autogen-stage.c
index 870ae0534..2a58fce62 100644
--- a/src/plugins/autotools/ide-autotools-autogen-stage.c
+++ b/src/plugins/autotools/ide-autotools-autogen-stage.c
@@ -26,7 +26,7 @@ struct _IdeAutotoolsAutogenStage
{
IdePipelineStage parent_instance;
- gchar *srcdir;
+ char *srcdir;
};
G_DEFINE_FINAL_TYPE (IdeAutotoolsAutogenStage, ide_autotools_autogen_stage, IDE_TYPE_PIPELINE_STAGE)
@@ -65,12 +65,15 @@ ide_autotools_autogen_stage_build_async (IdePipelineStage *stage,
gpointer user_data)
{
IdeAutotoolsAutogenStage *self = (IdeAutotoolsAutogenStage *)stage;
- g_autofree gchar *autogen_path = NULL;
+ g_autofree char *autogen_path = NULL;
+ g_autoptr(IdeRunContext) run_context = NULL;
g_autoptr(IdeSubprocessLauncher) launcher = NULL;
g_autoptr(IdeSubprocess) subprocess = NULL;
g_autoptr(IdeTask) task = NULL;
g_autoptr(GError) error = NULL;
+ IDE_ENTRY;
+
g_assert (IDE_IS_AUTOTOOLS_AUTOGEN_STAGE (self));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
@@ -79,34 +82,27 @@ ide_autotools_autogen_stage_build_async (IdePipelineStage *stage,
autogen_path = g_build_filename (self->srcdir, "autogen.sh", NULL);
- launcher = ide_pipeline_create_launcher (pipeline, &error);
-
- if (launcher == NULL)
- {
- ide_task_return_error (task, g_steal_pointer (&error));
- return;
- }
-
- ide_subprocess_launcher_set_cwd (launcher, self->srcdir);
+ run_context = ide_run_context_new ();
+ ide_pipeline_prepare_run_context (pipeline, run_context);
+ ide_run_context_set_cwd (run_context, self->srcdir);
if (g_file_test (autogen_path, G_FILE_TEST_IS_REGULAR))
{
- ide_subprocess_launcher_push_argv (launcher, autogen_path);
- ide_subprocess_launcher_setenv (launcher, "NOCONFIGURE", "1", TRUE);
+ ide_run_context_append_argv (run_context, autogen_path);
+ ide_run_context_setenv (run_context, "NOCONFIGURE", "1");
}
else
{
- ide_subprocess_launcher_push_argv (launcher, "autoreconf");
- ide_subprocess_launcher_push_argv (launcher, "-fiv");
+ ide_run_context_append_args (run_context, IDE_STRV_INIT ("autoreconf", "-fiv"));
}
- subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, &error);
+ if (!(launcher = ide_run_context_end (run_context, &error)))
+ IDE_GOTO (handle_error);
- if (subprocess == NULL)
- {
- ide_task_return_error (task, g_steal_pointer (&error));
- return;
- }
+ ide_pipeline_attach_pty (pipeline, launcher);
+
+ if (!(subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, &error)))
+ IDE_GOTO (handle_error);
ide_pipeline_stage_log_subprocess (stage, subprocess);
@@ -114,6 +110,13 @@ ide_autotools_autogen_stage_build_async (IdePipelineStage *stage,
cancellable,
ide_autotools_autogen_stage_wait_check_cb,
g_steal_pointer (&task));
+
+ IDE_EXIT;
+
+handle_error:
+ ide_task_return_error (task, g_steal_pointer (&error));
+
+ IDE_EXIT;
}
static gboolean
diff --git a/src/plugins/autotools/ide-autotools-make-stage.c
b/src/plugins/autotools/ide-autotools-make-stage.c
index b826fe45e..5b8554e11 100644
--- a/src/plugins/autotools/ide-autotools-make-stage.c
+++ b/src/plugins/autotools/ide-autotools-make-stage.c
@@ -78,12 +78,13 @@ static GParamSpec *properties [N_PROPS];
static IdeSubprocessLauncher *
create_launcher (IdeAutotoolsMakeStage *self,
- IdePipeline *pipeline,
+ IdePipeline *pipeline,
GCancellable *cancellable,
const gchar *make_target,
GError **error)
{
g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+ g_autoptr(IdeRunContext) run_context = NULL;
g_assert (IDE_IS_AUTOTOOLS_MAKE_STAGE (self));
g_assert (IDE_IS_PIPELINE (pipeline));
@@ -101,21 +102,16 @@ create_launcher (IdeAutotoolsMakeStage *self,
self->make = "make";
}
- if (NULL == (launcher = ide_pipeline_create_launcher (pipeline, error)))
- return NULL;
+ run_context = ide_run_context_new ();
+ ide_pipeline_prepare_run_context (pipeline, run_context);
- ide_subprocess_launcher_set_flags (launcher,
- G_SUBPROCESS_FLAGS_STDIN_PIPE |
- G_SUBPROCESS_FLAGS_STDOUT_PIPE |
- G_SUBPROCESS_FLAGS_STDERR_PIPE);
-
- ide_subprocess_launcher_push_argv (launcher, self->make);
+ ide_run_context_append_argv (run_context, self->make);
/* Force disable previous V=1 that might be set by environment
* variables from things like flatpak. We really don't want to
* show verbose output here, its just too much.
*/
- ide_subprocess_launcher_push_argv (launcher, "V=0");
+ ide_run_context_append_argv (run_context, "V=0");
if (!g_str_equal (make_target, "clean"))
{
@@ -128,10 +124,10 @@ create_launcher (IdeAutotoolsMakeStage *self,
else
parallel = g_strdup_printf ("-j%u", self->parallel);
- ide_subprocess_launcher_push_argv (launcher, parallel);
+ ide_run_context_append_argv (run_context, parallel);
}
- ide_subprocess_launcher_push_argv (launcher, make_target);
+ ide_run_context_append_argv (run_context, make_target);
/*
* When doing the "make all" target, we need to force LANG=C so that
@@ -140,11 +136,14 @@ create_launcher (IdeAutotoolsMakeStage *self,
*/
if (ide_str_equal0 ("all", make_target))
{
- ide_subprocess_launcher_setenv (launcher, "LANG", "C.UTF-8", TRUE);
- ide_subprocess_launcher_setenv (launcher, "LC_ALL", "C.UTF-8", TRUE);
- ide_subprocess_launcher_setenv (launcher, "LC_MESSAGES", "C.UTF-8", TRUE);
+ ide_run_context_setenv (run_context, "LANG", "C.UTF-8");
+ ide_run_context_setenv (run_context, "LC_ALL", "C.UTF-8");
+ ide_run_context_setenv (run_context, "LC_MESSAGES", "C.UTF-8");
}
+ if ((launcher = ide_run_context_end (run_context, error)))
+ ide_pipeline_attach_pty (pipeline, launcher);
+
return g_steal_pointer (&launcher);
}
@@ -171,11 +170,11 @@ ide_autotools_make_stage_wait_cb (GObject *object,
}
static void
-ide_autotools_make_stage_build_async (IdePipelineStage *stage,
- IdePipeline *pipeline,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ide_autotools_make_stage_build_async (IdePipelineStage *stage,
+ IdePipeline *pipeline,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
IdeAutotoolsMakeStage *self = (IdeAutotoolsMakeStage *)stage;
g_autoptr(IdeSubprocessLauncher) launcher = NULL;
@@ -260,8 +259,8 @@ ide_autotools_make_stage_build_finish (IdePipelineStage *stage,
}
static void
-ide_autotools_make_stage_clean_async (IdePipelineStage *stage,
- IdePipeline *pipeline,
+ide_autotools_make_stage_clean_async (IdePipelineStage *stage,
+ IdePipeline *pipeline,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -338,8 +337,8 @@ ide_autotools_make_stage_clean_finish (IdePipelineStage *stage,
}
static void
-ide_autotools_make_stage_query (IdePipelineStage *stage,
- IdePipeline *pipeline,
+ide_autotools_make_stage_query (IdePipelineStage *stage,
+ IdePipeline *pipeline,
GPtrArray *targets,
GCancellable *cancellable)
{
diff --git a/src/plugins/autotools/ide-autotools-makecache-stage.c
b/src/plugins/autotools/ide-autotools-makecache-stage.c
index abb31fefc..6ad49977c 100644
--- a/src/plugins/autotools/ide-autotools-makecache-stage.c
+++ b/src/plugins/autotools/ide-autotools-makecache-stage.c
@@ -28,9 +28,9 @@ struct _IdeAutotoolsMakecacheStage
{
IdePipelineStageLauncher parent_instance;
- IdeMakecache *makecache;
- IdeRuntime *runtime;
- GFile *cache_file;
+ IdeMakecache *makecache;
+ IdeRuntime *runtime;
+ GFile *cache_file;
};
G_DEFINE_FINAL_TYPE (IdeAutotoolsMakecacheStage, ide_autotools_makecache_stage,
IDE_TYPE_PIPELINE_STAGE_LAUNCHER)
@@ -211,6 +211,7 @@ ide_autotools_makecache_stage_new_for_pipeline (IdePipeline *pipeline,
{
g_autoptr(IdeAutotoolsMakecacheStage) stage = NULL;
g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+ g_autoptr(IdeRunContext) run_context = NULL;
g_autofree gchar *cache_path = NULL;
const gchar *make = "make";
IdeConfig *config;
@@ -222,19 +223,20 @@ ide_autotools_makecache_stage_new_for_pipeline (IdePipeline *pipeline,
config = ide_pipeline_get_config (pipeline);
runtime = ide_config_get_runtime (config);
-
cache_path = ide_pipeline_build_builddir_path (pipeline, "Makecache", NULL);
+ run_context = ide_run_context_new ();
+ ide_pipeline_prepare_run_context (pipeline, run_context);
+
if (ide_runtime_contains_program_in_path (runtime, "gmake", NULL))
make = "gmake";
- if (NULL == (launcher = ide_pipeline_create_launcher (pipeline, error)))
+ ide_run_context_append_args (run_context, IDE_STRV_INIT (make, "-p", "-n", "-s"));
+
+ if (!(launcher = ide_run_context_end (run_context, error)))
IDE_RETURN (NULL);
- ide_subprocess_launcher_push_argv (launcher, make);
- ide_subprocess_launcher_push_argv (launcher, "-p");
- ide_subprocess_launcher_push_argv (launcher, "-n");
- ide_subprocess_launcher_push_argv (launcher, "-s");
+ ide_pipeline_attach_pty (pipeline, launcher);
stage = g_object_new (IDE_TYPE_AUTOTOOLS_MAKECACHE_STAGE,
"launcher", launcher,
diff --git a/src/plugins/autotools/ide-autotools-pipeline-addin.c
b/src/plugins/autotools/ide-autotools-pipeline-addin.c
index a38602d85..c59066b80 100644
--- a/src/plugins/autotools/ide-autotools-pipeline-addin.c
+++ b/src/plugins/autotools/ide-autotools-pipeline-addin.c
@@ -30,12 +30,12 @@
static gboolean
register_autoreconf_stage (IdeAutotoolsPipelineAddin *self,
- IdePipeline *pipeline,
+ IdePipeline *pipeline,
GError **error)
{
- g_autofree gchar *configure_path = NULL;
+ g_autofree char *configure_path = NULL;
g_autoptr(IdePipelineStage) stage = NULL;
- const gchar *srcdir;
+ const char *srcdir;
gboolean completed;
guint stage_id;
@@ -60,8 +60,8 @@ register_autoreconf_stage (IdeAutotoolsPipelineAddin *self,
}
static gint
-compare_mtime (const gchar *path_a,
- const gchar *path_b)
+compare_mtime (const char *path_a,
+ const char *path_b)
{
g_autoptr(GFile) file_a = g_file_new_for_path (path_a);
g_autoptr(GFile) file_b = g_file_new_for_path (path_b);
@@ -93,15 +93,15 @@ compare_mtime (const gchar *path_a,
static void
check_configure_status (IdeAutotoolsPipelineAddin *self,
- IdePipeline *pipeline,
+ IdePipeline *pipeline,
GPtrArray *targets,
GCancellable *cancellable,
- IdePipelineStage *stage)
+ IdePipelineStage *stage)
{
- g_autofree gchar *configure_ac = NULL;
- g_autofree gchar *configure = NULL;
- g_autofree gchar *config_status = NULL;
- g_autofree gchar *makefile = NULL;
+ g_autofree char *configure_ac = NULL;
+ g_autofree char *configure = NULL;
+ g_autofree char *config_status = NULL;
+ g_autofree char *makefile = NULL;
IDE_ENTRY;
@@ -158,8 +158,8 @@ check_configure_status (IdeAutotoolsPipelineAddin *self,
IDE_EXIT;
}
-static const gchar *
-compiler_environment_from_language (gchar *language)
+static const char *
+compiler_environment_from_language (const char *language)
{
if (g_strcmp0 (language, IDE_TOOLCHAIN_LANGUAGE_C) == 0)
return "CC";
@@ -187,76 +187,75 @@ add_compiler_env_variables (gpointer key,
gpointer value,
gpointer user_data)
{
- IdeSubprocessLauncher *launcher = (IdeSubprocessLauncher *)user_data;
- const gchar *env = compiler_environment_from_language (key);
- if (env == NULL)
- return;
+ IdeRunCommand *run_command = (IdeRunCommand *)user_data;
+ const char *env;
+
+ g_assert (IDE_IS_RUN_COMMAND (run_command));
- ide_subprocess_launcher_setenv (launcher, env, value, TRUE);
+ if ((env = compiler_environment_from_language (key)))
+ ide_run_command_setenv (run_command, env, value);
}
static gboolean
register_configure_stage (IdeAutotoolsPipelineAddin *self,
- IdePipeline *pipeline,
+ IdePipeline *pipeline,
GError **error)
{
- g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+ g_autoptr(IdeRunCommand) run_command = NULL;
g_autoptr(IdePipelineStage) stage = NULL;
IdeConfig *configuration;
IdeToolchain *toolchain;
- g_autofree gchar *configure_path = NULL;
- g_autofree gchar *host_arg = NULL;
+ g_autofree char *configure_path = NULL;
+ g_autofree char *host_arg = NULL;
g_autoptr(IdeTriplet) triplet = NULL;
- const gchar *config_opts;
- const gchar *prefix;
+ g_autoptr(GStrvBuilder) argv = NULL;
+ const char *config_opts;
+ const char *prefix;
+ g_auto(GStrv) strv = NULL;
guint stage_id;
g_assert (IDE_IS_AUTOTOOLS_PIPELINE_ADDIN (self));
g_assert (IDE_IS_PIPELINE (pipeline));
- if (NULL == (launcher = ide_pipeline_create_launcher (pipeline, error)))
- return FALSE;
-
- ide_subprocess_launcher_set_flags (launcher,
- G_SUBPROCESS_FLAGS_STDIN_PIPE |
- G_SUBPROCESS_FLAGS_STDOUT_PIPE |
- G_SUBPROCESS_FLAGS_STDERR_PIPE);
+ argv = g_strv_builder_new ();
+ run_command = ide_run_command_new ();
+ /* /path/to/configure */
configure_path = ide_pipeline_build_srcdir_path (pipeline, "configure", NULL);
- ide_subprocess_launcher_push_argv (launcher, configure_path);
+ g_strv_builder_add (argv, configure_path);
/* --host=triplet */
configuration = ide_pipeline_get_config (pipeline);
toolchain = ide_pipeline_get_toolchain (pipeline);
triplet = ide_toolchain_get_host_triplet (toolchain);
host_arg = g_strdup_printf ("--host=%s", ide_triplet_get_full_name (triplet));
- ide_subprocess_launcher_push_argv (launcher, host_arg);
+ g_strv_builder_add (argv, host_arg);
if (g_strcmp0 (ide_toolchain_get_id (toolchain), "default") != 0)
{
GHashTable *compilers = ide_toolchain_get_tools_for_id (toolchain,
IDE_TOOLCHAIN_TOOL_CC);
- const gchar *tool_path;
+ const char *tool_path;
- g_hash_table_foreach (compilers, add_compiler_env_variables, launcher);
+ g_hash_table_foreach (compilers, add_compiler_env_variables, run_command);
tool_path = ide_toolchain_get_tool_for_language (toolchain,
IDE_TOOLCHAIN_LANGUAGE_ANY,
IDE_TOOLCHAIN_TOOL_AR);
if (tool_path != NULL)
- ide_subprocess_launcher_setenv (launcher, "AR", tool_path, TRUE);
+ ide_run_command_setenv (run_command, "AR", tool_path);
tool_path = ide_toolchain_get_tool_for_language (toolchain,
IDE_TOOLCHAIN_LANGUAGE_ANY,
IDE_TOOLCHAIN_TOOL_STRIP);
if (tool_path != NULL)
- ide_subprocess_launcher_setenv (launcher, "STRIP", tool_path, TRUE);
+ ide_run_command_setenv (run_command, "STRIP", tool_path);
tool_path = ide_toolchain_get_tool_for_language (toolchain,
IDE_TOOLCHAIN_LANGUAGE_ANY,
IDE_TOOLCHAIN_TOOL_PKG_CONFIG);
if (tool_path != NULL)
- ide_subprocess_launcher_setenv (launcher, "PKG_CONFIG", tool_path, TRUE);
+ ide_run_command_setenv (run_command, "PKG_CONFIG", tool_path);
}
/*
@@ -269,25 +268,27 @@ register_configure_stage (IdeAutotoolsPipelineAddin *self,
if (prefix != NULL)
{
- g_autofree gchar *prefix_arg = g_strdup_printf ("--prefix=%s", prefix);
- ide_subprocess_launcher_push_argv (launcher, prefix_arg);
+ g_autofree char *prefix_arg = g_strdup_printf ("--prefix=%s", prefix);
+ g_strv_builder_add (argv, prefix_arg);
}
if (!ide_str_empty0 (config_opts))
{
- g_auto(GStrv) argv = NULL;
+ g_auto(GStrv) parsed = NULL;
gint argc = 0;
- if (!g_shell_parse_argv (config_opts, &argc, &argv, error))
+ if (!g_shell_parse_argv (config_opts, &argc, &parsed, error))
return FALSE;
- for (gint i = 0; i < argc; i++)
- ide_subprocess_launcher_push_argv (launcher, argv[i]);
+ g_strv_builder_addv (argv, (const char **)parsed);
}
- stage = g_object_new (IDE_TYPE_PIPELINE_STAGE_LAUNCHER,
+ strv = g_strv_builder_end (argv);
+ ide_run_command_set_argv (run_command, (const char * const *)strv);
+
+ stage = g_object_new (IDE_TYPE_PIPELINE_STAGE_COMMAND,
"name", _("Configuring project"),
- "launcher", launcher,
+ "build-command", run_command,
NULL);
/*
@@ -318,11 +319,11 @@ register_configure_stage (IdeAutotoolsPipelineAddin *self,
static gboolean
register_make_stage (IdeAutotoolsPipelineAddin *self,
- IdePipeline *pipeline,
- IdePipelinePhase phase,
+ IdePipeline *pipeline,
+ IdePipelinePhase phase,
GError **error,
- const gchar *target,
- const gchar *clean_target)
+ const char *target,
+ const char *clean_target)
{
g_autoptr(IdePipelineStage) stage = NULL;
IdeConfig *config;
@@ -365,9 +366,9 @@ register_makecache_stage (IdeAutotoolsPipelineAddin *self,
ide_pipeline_stage_set_name (stage, _("Caching build commands"));
stage_id = ide_pipeline_attach (pipeline,
- IDE_PIPELINE_PHASE_CONFIGURE | IDE_PIPELINE_PHASE_AFTER,
- 0,
- stage);
+ IDE_PIPELINE_PHASE_CONFIGURE | IDE_PIPELINE_PHASE_AFTER,
+ 0,
+ stage);
ide_pipeline_addin_track (IDE_PIPELINE_ADDIN (self), stage_id);
return TRUE;
@@ -403,8 +404,6 @@ ide_autotools_pipeline_addin_load (IdePipelineAddin *addin,
}
}
-/* GObject Boilerplate */
-
static void
addin_iface_init (IdePipelineAddinInterface *iface)
{
@@ -414,7 +413,7 @@ addin_iface_init (IdePipelineAddinInterface *iface)
struct _IdeAutotoolsPipelineAddin { IdeObject parent; };
G_DEFINE_FINAL_TYPE_WITH_CODE (IdeAutotoolsPipelineAddin, ide_autotools_pipeline_addin, IDE_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (IDE_TYPE_PIPELINE_ADDIN, addin_iface_init))
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_PIPELINE_ADDIN, addin_iface_init))
static void
ide_autotools_pipeline_addin_class_init (IdeAutotoolsPipelineAddinClass *klass)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]