[gnome-builder] autotools: Fix build target discovery for flatpak runtimes
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] autotools: Fix build target discovery for flatpak runtimes
- Date: Tue, 15 Nov 2016 07:19:12 +0000 (UTC)
commit e4e2e7580a39b9c448529626f6ba9a7e5730e05a
Author: Matthew Leeds <mleeds redhat com>
Date: Sat Nov 5 19:28:19 2016 -0500
autotools: Fix build target discovery for flatpak runtimes
ide_makecache_get_build_targets_worker() tries to find build targets by
spawning make processes in each directory with a Makefile, but since
the flatpak-build command specifies the directory it is unaffected by
the process's cwd. So finding build targets in subdirectories fails for
flatpak runtimes. This commit fixes that by using the -C option on make
to switch to the appropriate subdirectory.
https://bugzilla.gnome.org/show_bug.cgi?id=773764
libide/subprocess/ide-subprocess-launcher.c | 15 +++++++++++
libide/subprocess/ide-subprocess-launcher.h | 3 ++
plugins/autotools/ide-makecache.c | 36 ++++++++++++++++++++++++---
3 files changed, 50 insertions(+), 4 deletions(-)
---
diff --git a/libide/subprocess/ide-subprocess-launcher.c b/libide/subprocess/ide-subprocess-launcher.c
index f679317..7f04cf6 100644
--- a/libide/subprocess/ide-subprocess-launcher.c
+++ b/libide/subprocess/ide-subprocess-launcher.c
@@ -833,3 +833,18 @@ ide_subprocess_launcher_insert_argv (IdeSubprocessLauncher *self,
g_ptr_array_insert (priv->argv, index, g_strdup (arg));
}
+
+void
+ide_subprocess_launcher_replace_argv (IdeSubprocessLauncher *self,
+ guint index,
+ const gchar *arg)
+{
+ IdeSubprocessLauncherPrivate *priv = ide_subprocess_launcher_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_SUBPROCESS_LAUNCHER (self));
+ g_return_if_fail (index < priv->argv->len);
+ g_return_if_fail (arg != NULL);
+
+ g_ptr_array_remove_index (priv->argv, index);
+ g_ptr_array_insert (priv->argv, (index == priv->argv->len ? -1 : index), g_strdup (arg));
+}
diff --git a/libide/subprocess/ide-subprocess-launcher.h b/libide/subprocess/ide-subprocess-launcher.h
index bf389b8..69b5f0e 100644
--- a/libide/subprocess/ide-subprocess-launcher.h
+++ b/libide/subprocess/ide-subprocess-launcher.h
@@ -72,6 +72,9 @@ void ide_subprocess_launcher_setenv (IdeSubproces
void ide_subprocess_launcher_insert_argv (IdeSubprocessLauncher *self,
guint index,
const gchar *arg);
+void ide_subprocess_launcher_replace_argv (IdeSubprocessLauncher *self,
+ guint index,
+ const gchar *arg);
void ide_subprocess_launcher_overlay_environment (IdeSubprocessLauncher *self,
IdeEnvironment *environment);
const gchar * const *ide_subprocess_launcher_get_argv (IdeSubprocessLauncher *self);
diff --git a/plugins/autotools/ide-makecache.c b/plugins/autotools/ide-makecache.c
index 3473ea2..70e9a99 100644
--- a/plugins/autotools/ide-makecache.c
+++ b/plugins/autotools/ide-makecache.c
@@ -1872,6 +1872,9 @@ ide_makecache_get_build_targets_worker (GTask *task,
gchar *line;
gsize line_len;
IdeLineReader reader;
+ const gchar * const * partial_argv;
+ guint num_args;
+ gboolean first_subdir = TRUE;
IDE_ENTRY;
@@ -1921,6 +1924,11 @@ ide_makecache_get_build_targets_worker (GTask *task,
make_name = GNU_MAKE_NAME;
ide_subprocess_launcher_push_argv (launcher, make_name);
+
+ /* Find the argv index so we can insert arguments on each run */
+ partial_argv = ide_subprocess_launcher_get_argv (launcher);
+ for (num_args = 0; partial_argv[num_args] != NULL; num_args++) ;
+
ide_subprocess_launcher_push_argv (launcher, "-f");
ide_subprocess_launcher_push_argv (launcher, "-");
ide_subprocess_launcher_push_argv (launcher, "print-bindir");
@@ -1969,16 +1977,36 @@ ide_makecache_get_build_targets_worker (GTask *task,
{
g_autoptr(IdeSubprocess) subprocess = NULL;
g_autoptr(GHashTable) amdirs = NULL;
- g_autofree gchar *path = NULL;
+ g_autofree gchar *rel_path = NULL;
GFile *makedir;
/*
* Make sure we are running within the directory containing the
- * Makefile that we care about.
+ * Makefile that we care about. We use make's -C option because
+ * for runtimes such as flatpak make doesn't necessarily run in
+ * the same directory as the process.
*/
makedir = g_ptr_array_index (makedirs, j);
- path = g_file_get_path (makedir);
- ide_subprocess_launcher_set_cwd (launcher, path);
+ rel_path = g_file_get_relative_path (build_dir, makedir);
+ if (rel_path == NULL)
+ {
+ g_autofree gchar *path = NULL;
+ path = g_file_get_path (makedir);
+ ide_subprocess_launcher_set_cwd (launcher, path);
+ }
+ else
+ {
+ if (first_subdir)
+ {
+ ide_subprocess_launcher_insert_argv (launcher, num_args, "-C");
+ ide_subprocess_launcher_insert_argv (launcher, (num_args + 1), rel_path);
+ first_subdir = FALSE;
+ }
+ else
+ {
+ ide_subprocess_launcher_replace_argv (launcher, (num_args + 1), rel_path);
+ }
+ }
/*
* Spawn make, waiting for our stdin input which will add our debug
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]