[gnome-builder] plugins/flatpak: apply prepend/append path from manifests



commit 64fe9bcd079a01d97d983e2a1040ef67274ed7c0
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 12 14:04:24 2022 -0700

    plugins/flatpak: apply prepend/append path from manifests
    
    Honestly, this really ought to be in IdePipeline, but that will require
    a new vfunc from the runtimes to get their "default path" so that the
    flatpak one can return "/app/bin:/usr/bin".
    
    Hopefully can do that as a followup. But this gets it so I can configure
    Builder from Builder again.

 src/plugins/flatpak/gbp-flatpak-runtime.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime.c b/src/plugins/flatpak/gbp-flatpak-runtime.c
index 088d6ed0a..5f5a6c2e4 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime.c
@@ -229,10 +229,7 @@ gbp_flatpak_runtime_handle_run_context_cb (IdeRunContext       *run_context,
   if (env != NULL)
     {
       for (guint i = 0; env[i]; i++)
-        {
-          g_autofree char *arg = g_strconcat ("--env=", env[i], NULL);
-          ide_run_context_append_argv (run_context, arg);
-        }
+        ide_run_context_append_formatted (run_context, "--env=%s", env[i]);
     }
 
   /* Make sure all of our finish arguments for the manifest are included */
@@ -305,6 +302,10 @@ gbp_flatpak_runtime_handle_build_context_cb (IdeRunContext       *run_context,
   GbpFlatpakRuntime *self;
   g_autofree char *staging_dir = NULL;
   g_autofree char *ccache_dir = NULL;
+  g_autofree char *new_path = NULL;
+  const char *path;
+  const char *prepend_path;
+  const char *append_path;
   const char *srcdir;
   const char *builddir;
   IdeContext *context;
@@ -378,16 +379,31 @@ gbp_flatpak_runtime_handle_build_context_cb (IdeRunContext       *run_context,
       ide_run_context_append_argv (run_context, "--share=network");
     }
 
+  /* Prepare an alternate PATH */
+  path = g_environ_getenv ((char **)env, "PATH");
+  prepend_path = ide_config_get_prepend_path (config);
+  append_path = ide_config_get_append_path (config);
+  if (path || prepend_path || append_path)
+    new_path = g_strdup_printf ("%s%s%s%s%s",
+                                prepend_path ? prepend_path : "",
+                                prepend_path ? ":" : "",
+                                path ? path : "/app/bin:/usr/bin",
+                                path ? ":" : "",
+                                append_path ? append_path : "");
+
   /* Convert environment from upper level into --env=FOO=BAR */
   if (env != NULL)
     {
       for (guint i = 0; env[i]; i++)
         {
-          g_autofree char *arg = g_strconcat ("--env=", env[i], NULL);
-          ide_run_context_append_argv (run_context, arg);
+          if (new_path == NULL || !ide_str_equal0 (env[i], "PATH"))
+            ide_run_context_append_formatted (run_context, "--env=%s", env[i]);
         }
     }
 
+  if (new_path != NULL)
+    ide_run_context_append_formatted (run_context, "--env=PATH=%s", new_path);
+
   /* And last, before our child command, is the staging directory */
   ide_run_context_append_argv (run_context, staging_dir);
 


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