[gnome-builder/wip/tintou/jhbuild: 3/3] jhbuild: make it possible to build from host inside jhbuild and the opposite



commit c5b1cceb5465041088349a0b1ac09afa281057b3
Author: Corentin Noël <corentin noel collabora co uk>
Date:   Tue Feb 13 09:40:55 2018 +0000

    jhbuild: make it possible to build from host inside jhbuild and the opposite

 src/main.c                            | 28 ++++++++++++++++++++++++++++
 src/plugins/jhbuild/jhbuild_plugin.py | 18 ++++++++++++++++--
 2 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index f3bea6db7..993a41941 100644
--- a/src/main.c
+++ b/src/main.c
@@ -104,6 +104,7 @@ main (int   argc,
 {
   IdeApplication *app;
   const gchar *desktop;
+  const gchar *jhbuild_prefix;
   int ret;
 
   /* Setup our gdb fork()/exec() helper */
@@ -119,6 +120,33 @@ main (int   argc,
       return EXIT_FAILURE;
     }
 
+
+  /*
+   * JHBuild adds its own path to the main PATH environment variable
+   * and thus prevents the use of the host sytem environment.
+   */
+  jhbuild_prefix = g_getenv ("JHBUILD_PREFIX");
+  if (jhbuild_prefix != NULL)
+    {
+      const gchar *path = g_getenv ("PATH");
+      gchar **path_parts = g_strsplit (path, ":", -1);
+      gchar **wanted_parts = g_new0 (gchar*, g_strv_length (path_parts) + 1);
+      guint index = 0;
+      for(guint i = 0; path_parts[i] != NULL; i++)
+        {
+          if (!g_str_has_prefix (path_parts[i], jhbuild_prefix))
+            {
+              wanted_parts[index] = g_strdup(path_parts[i]);
+              index++;
+            }
+        }
+
+      path = g_strjoinv (":", wanted_parts);
+      g_strfreev (wanted_parts);
+      g_strfreev (path_parts);
+      g_setenv ("PATH", path, TRUE);
+    }
+
   /* Early init of logging so that we get messages in a consistent
    * format. If we deferred this to GApplication, we'd get them in
    * multiple formats.
diff --git a/src/plugins/jhbuild/jhbuild_plugin.py b/src/plugins/jhbuild/jhbuild_plugin.py
index dc37080ba..ad10d2a54 100644
--- a/src/plugins/jhbuild/jhbuild_plugin.py
+++ b/src/plugins/jhbuild/jhbuild_plugin.py
@@ -53,14 +53,18 @@ class JhbuildRuntime(Ide.Runtime):
 
         return launcher
 
-    def do_prepare_configuration(self, configuration):
+    def _get_jhbuild_prefix_cmd(self):
+        # If we are inside a JHBuild environment, just get the variable
+        prefix = os.environ["JHBUILD_PREFIX"]
+        if prefix is not None:
+            return prefix
+
         launcher = self.create_launcher()
         launcher.push_argv('sh')
         launcher.push_argv('-c')
         launcher.push_argv('echo $JHBUILD_PREFIX')
         launcher.set_flags(Gio.SubprocessFlags.STDOUT_PIPE)
 
-        prefix = None
         try:
             # FIXME: Async
             subprocess = launcher.spawn(None)
@@ -73,7 +77,17 @@ class JhbuildRuntime(Ide.Runtime):
         if not prefix:
             prefix = os.path.join(GLib.get_home_dir(), 'jhbuild', 'install')
 
+        return prefix
+
+    def do_prepare_configuration(self, configuration):
+        prefix = self._get_jhbuild_prefix_cmd()
         configuration.set_prefix(prefix)
+        bin_path = os.path.join(prefix, 'bin')
+        path_var = os.environ['PATH']
+        if path_var:
+            os.environ['PATH'] = ':'.join((bin_path, path_var))
+        else:
+            os.environ['PATH'] = bin_path
 
     def do_contains_program_in_path(self, program, cancellable):
         launcher = self.create_launcher()


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