[gnome-builder] flatpak: fix building from within flatpaks



commit 4a63cb9c0ca52c0ef721131b8e3824483d207ae3
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 28 19:28:28 2016 -0700

    flatpak: fix building from within flatpaks
    
    This ensures that we create the proper build directory in the proper
    context. We need to do this from outside the flatpak (on the host) and
    ensure it has enough environment to perform the task.
    
    Additionally, this no longer users the "flatpak" binary from within the
    application bundle, but instead relies on the host which should be
    available given that we are 1) already getting this far, or 2) running
    inside a flatpak.
    
    This also switches to IdeSubprocessLauncher from GSubprocessLauncher.

 plugins/flatpak/gbp-flatpak-runtime.c |   66 ++++++++++++++++++--------------
 1 files changed, 37 insertions(+), 29 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-runtime.c b/plugins/flatpak/gbp-flatpak-runtime.c
index c2d2211..4213ec5 100644
--- a/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/plugins/flatpak/gbp-flatpak-runtime.c
@@ -90,11 +90,10 @@ gbp_flatpak_runtime_prebuild_worker (GTask        *task,
   GbpFlatpakRuntime *self = source_object;
   g_autofree gchar *build_path = NULL;
   g_autoptr(GFile) build_dir = NULL;
-  g_autoptr(GSubprocessLauncher) launcher = NULL;
-  g_autoptr(GSubprocess) subprocess = NULL;
+  g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+  g_autoptr(IdeSubprocess) subprocess = NULL;
   g_autoptr(GFile) parent = NULL;
-  GError *error = NULL;
-  GPtrArray *args;
+  g_autoptr(GError) error = NULL;
 
   g_assert (G_IS_TASK (task));
   g_assert (GBP_IS_FLATPAK_RUNTIME (self));
@@ -115,38 +114,46 @@ gbp_flatpak_runtime_prebuild_worker (GTask        *task,
     {
       if (!g_file_make_directory_with_parents (parent, cancellable, &error))
         {
-          g_task_return_error (task, error);
+          g_task_return_error (task, g_steal_pointer (&error));
           return;
         }
     }
 
-  launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
-  args = g_ptr_array_new ();
-  g_ptr_array_add (args, "flatpak");
-  g_ptr_array_add (args, "build-init");
-  g_ptr_array_add (args, build_path);
+  launcher = IDE_RUNTIME_CLASS (gbp_flatpak_runtime_parent_class)->create_launcher (IDE_RUNTIME (self), 
&error);
+
+  if (launcher == NULL)
+    {
+      g_task_return_error (task, g_steal_pointer (&error));
+      return;
+    }
+
+  ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
+  ide_subprocess_launcher_set_clear_env (launcher, FALSE);
+
+  ide_subprocess_launcher_push_argv (launcher, "flatpak");
+  ide_subprocess_launcher_push_argv (launcher, "build-init");
+  ide_subprocess_launcher_push_argv (launcher, build_path);
   /* XXX: Fake name, probably okay, but can be proper once we get
    * IdeConfiguration in place.
    */
-  g_ptr_array_add (args, "org.gnome.Builder.FlatpakApp.Build");
-  g_ptr_array_add (args, self->sdk);
-  g_ptr_array_add (args, self->platform);
-  g_ptr_array_add (args, self->branch);
-  g_ptr_array_add (args, NULL);
-
-#ifdef IDE_ENABLE_TRACE
-  {
-    g_autofree gchar *str = NULL;
-    str = g_strjoinv (" ", (gchar **)args->pdata);
-    IDE_TRACE_MSG ("Launching '%s'", str);
-  }
-#endif
-
-  subprocess = g_subprocess_launcher_spawnv (launcher,
-                                             (const gchar * const *)args->pdata,
-                                             &error);
-
-  g_ptr_array_free (args, TRUE);
+  ide_subprocess_launcher_push_argv (launcher, "org.gnome.Builder.FlatpakApp.Build");
+  ide_subprocess_launcher_push_argv (launcher, self->sdk);
+  ide_subprocess_launcher_push_argv (launcher, self->platform);
+  ide_subprocess_launcher_push_argv (launcher, self->branch);
+
+  subprocess = ide_subprocess_launcher_spawn_sync (launcher, cancellable, &error);
+
+  if (subprocess == NULL)
+    {
+      g_task_return_error (task, g_steal_pointer (&error));
+      return;
+    }
+
+  if (!ide_subprocess_wait_check (subprocess, cancellable, &error))
+    {
+      g_task_return_error (task, g_steal_pointer (&error));
+      return;
+    }
 
   g_task_return_boolean (task, TRUE);
 }
@@ -200,6 +207,7 @@ gbp_flatpak_runtime_create_launcher (IdeRuntime  *runtime,
       ide_subprocess_launcher_push_argv (ret, build_path);
 
       ide_subprocess_launcher_set_run_on_host (ret, TRUE);
+      ide_subprocess_launcher_set_clear_env (ret, FALSE);
     }
 
   return ret;


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