[gnome-builder] flatpak: Show prebuild/postbuild output in Builder



commit c7cb656c2f26366335efd8a009f2e36dd8a45ad6
Author: Matthew Leeds <mleeds redhat com>
Date:   Mon Nov 14 23:30:17 2016 -0800

    flatpak: Show prebuild/postbuild output in Builder
    
    In case something goes wrong in one of the prebuild or postbuild steps,
    it's useful for the user to see their output in the Build Output window
    of Builder. This commit makes that happen by adding an IdeBuildResult
    parameter to the runtime's async vfuncs and using it to call
    ide_build_result_log_subprocess from the flatpak runtime.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=773764

 libide/runtimes/ide-runtime.c                |   12 ++++-
 libide/runtimes/ide-runtime.h                |    6 ++
 plugins/autotools/ide-autotools-build-task.c |    3 +
 plugins/flatpak/gbp-flatpak-runtime.c        |   64 +++++++++++++++++++++++--
 4 files changed, 76 insertions(+), 9 deletions(-)
---
diff --git a/libide/runtimes/ide-runtime.c b/libide/runtimes/ide-runtime.c
index f8f6afa..2123e19 100644
--- a/libide/runtimes/ide-runtime.c
+++ b/libide/runtimes/ide-runtime.c
@@ -45,6 +45,7 @@ static GParamSpec *properties [N_PROPS];
 
 static void
 ide_runtime_real_prebuild_async (IdeRuntime          *self,
+                                 IdeBuildResult      *build_result,
                                  GCancellable        *cancellable,
                                  GAsyncReadyCallback  callback,
                                  gpointer             user_data)
@@ -71,6 +72,7 @@ ide_runtime_real_prebuild_finish (IdeRuntime    *self,
 
 static void
 ide_runtime_real_postbuild_async (IdeRuntime          *self,
+                                  IdeBuildResult      *build_result,
                                   GCancellable        *cancellable,
                                   GAsyncReadyCallback  callback,
                                   gpointer             user_data)
@@ -97,6 +99,7 @@ ide_runtime_real_postbuild_finish (IdeRuntime    *self,
 
 static void
 ide_runtime_real_postinstall_async (IdeRuntime          *self,
+                                    IdeBuildResult      *build_result,
                                     GCancellable        *cancellable,
                                     GAsyncReadyCallback  callback,
                                     gpointer             user_data)
@@ -439,6 +442,7 @@ ide_runtime_new (IdeContext  *context,
 
 void
 ide_runtime_prebuild_async (IdeRuntime          *self,
+                            IdeBuildResult      *build_result,
                             GCancellable        *cancellable,
                             GAsyncReadyCallback  callback,
                             gpointer             user_data)
@@ -446,7 +450,7 @@ ide_runtime_prebuild_async (IdeRuntime          *self,
   g_return_if_fail (IDE_IS_RUNTIME (self));
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
-  IDE_RUNTIME_GET_CLASS (self)->prebuild_async (self, cancellable, callback, user_data);
+  IDE_RUNTIME_GET_CLASS (self)->prebuild_async (self, build_result, cancellable, callback, user_data);
 }
 
 gboolean
@@ -461,6 +465,7 @@ ide_runtime_prebuild_finish (IdeRuntime    *self,
 
 void
 ide_runtime_postbuild_async (IdeRuntime          *self,
+                             IdeBuildResult      *build_result,
                              GCancellable        *cancellable,
                              GAsyncReadyCallback  callback,
                              gpointer             user_data)
@@ -468,7 +473,7 @@ ide_runtime_postbuild_async (IdeRuntime          *self,
   g_return_if_fail (IDE_IS_RUNTIME (self));
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
-  IDE_RUNTIME_GET_CLASS (self)->postbuild_async (self, cancellable, callback, user_data);
+  IDE_RUNTIME_GET_CLASS (self)->postbuild_async (self, build_result, cancellable, callback, user_data);
 }
 
 gboolean
@@ -483,6 +488,7 @@ ide_runtime_postbuild_finish (IdeRuntime    *self,
 
 void
 ide_runtime_postinstall_async (IdeRuntime          *self,
+                               IdeBuildResult      *build_result,
                                GCancellable        *cancellable,
                                GAsyncReadyCallback  callback,
                                gpointer             user_data)
@@ -490,7 +496,7 @@ ide_runtime_postinstall_async (IdeRuntime          *self,
   g_return_if_fail (IDE_IS_RUNTIME (self));
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
-  IDE_RUNTIME_GET_CLASS (self)->postinstall_async (self, cancellable, callback, user_data);
+  IDE_RUNTIME_GET_CLASS (self)->postinstall_async (self, build_result, cancellable, callback, user_data);
 }
 
 gboolean
diff --git a/libide/runtimes/ide-runtime.h b/libide/runtimes/ide-runtime.h
index d802619..988ee4f 100644
--- a/libide/runtimes/ide-runtime.h
+++ b/libide/runtimes/ide-runtime.h
@@ -44,6 +44,7 @@ struct _IdeRuntimeClass
   IdeObjectClass parent;
 
   void                   (*prebuild_async)           (IdeRuntime           *self,
+                                                      IdeBuildResult       *build_result,
                                                       GCancellable         *cancellable,
                                                       GAsyncReadyCallback   callback,
                                                       gpointer              user_data);
@@ -51,6 +52,7 @@ struct _IdeRuntimeClass
                                                       GAsyncResult         *result,
                                                       GError              **error);
   void                   (*postbuild_async)          (IdeRuntime           *self,
+                                                      IdeBuildResult       *build_result,
                                                       GCancellable         *cancellable,
                                                       GAsyncReadyCallback   callback,
                                                       gpointer              user_data);
@@ -67,6 +69,7 @@ struct _IdeRuntimeClass
   IdeRunner             *(*create_runner)            (IdeRuntime           *self,
                                                       IdeBuildTarget       *build_target);
   void                   (*postinstall_async)        (IdeRuntime           *self,
+                                                      IdeBuildResult       *build_result,
                                                       GCancellable         *cancellable,
                                                       GAsyncReadyCallback   callback,
                                                       gpointer              user_data);
@@ -92,6 +95,7 @@ struct _IdeRuntimeClass
 
 GQuark                 ide_runtime_error_quark              (void) G_GNUC_CONST;
 void                   ide_runtime_prebuild_async           (IdeRuntime           *self,
+                                                             IdeBuildResult       *build_result,
                                                              GCancellable         *cancellable,
                                                              GAsyncReadyCallback   callback,
                                                              gpointer              user_data);
@@ -99,6 +103,7 @@ gboolean               ide_runtime_prebuild_finish          (IdeRuntime
                                                              GAsyncResult         *result,
                                                              GError              **error);
 void                   ide_runtime_postbuild_async          (IdeRuntime           *self,
+                                                             IdeBuildResult       *build_result,
                                                              GCancellable         *cancellable,
                                                              GAsyncReadyCallback   callback,
                                                              gpointer              user_data);
@@ -106,6 +111,7 @@ gboolean               ide_runtime_postbuild_finish         (IdeRuntime
                                                              GAsyncResult         *result,
                                                              GError              **error);
 void                   ide_runtime_postinstall_async        (IdeRuntime           *self,
+                                                             IdeBuildResult       *build_result,
                                                              GCancellable         *cancellable,
                                                              GAsyncReadyCallback   callback,
                                                              gpointer              user_data);
diff --git a/plugins/autotools/ide-autotools-build-task.c b/plugins/autotools/ide-autotools-build-task.c
index 7f83d00..390a325 100644
--- a/plugins/autotools/ide-autotools-build-task.c
+++ b/plugins/autotools/ide-autotools-build-task.c
@@ -726,6 +726,7 @@ ide_autotools_build_task_execute_async (IdeAutotoolsBuildTask *self,
 
   /* Execute the pre-hook for the runtime before we start building. */
   ide_runtime_prebuild_async (state->runtime,
+                              IDE_BUILD_RESULT (self),
                               cancellable,
                               ide_autotools_build_task_runtime_prebuild_cb,
                               g_steal_pointer (&task));
@@ -831,11 +832,13 @@ ide_autotools_build_task_execute_with_postbuild_cb (GObject      *object,
 
   if (self->install)
     ide_runtime_postinstall_async (runtime,
+                                   IDE_BUILD_RESULT (self),
                                    cancellable,
                                    ide_autotools_build_task_postbuild_runtime_cb,
                                    g_steal_pointer (&task));
   else
     ide_runtime_postbuild_async (runtime,
+                                 IDE_BUILD_RESULT (self),
                                  cancellable,
                                  ide_autotools_build_task_postbuild_runtime_cb,
                                  g_steal_pointer (&task));
diff --git a/plugins/flatpak/gbp-flatpak-runtime.c b/plugins/flatpak/gbp-flatpak-runtime.c
index 543aa9b..7b5c94a 100644
--- a/plugins/flatpak/gbp-flatpak-runtime.c
+++ b/plugins/flatpak/gbp-flatpak-runtime.c
@@ -100,6 +100,7 @@ gbp_flatpak_runtime_prebuild_worker (GTask        *task,
                                      GCancellable *cancellable)
 {
   GbpFlatpakRuntime *self = source_object;
+  IdeBuildResult *build_result = (IdeBuildResult *)task_data;
   IdeContext *context;
   IdeConfigurationManager *config_manager;
   IdeConfiguration *configuration;
@@ -118,6 +119,7 @@ gbp_flatpak_runtime_prebuild_worker (GTask        *task,
   g_assert (G_IS_TASK (task));
   g_assert (GBP_IS_FLATPAK_RUNTIME (self));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+  g_assert (IDE_IS_BUILD_RESULT (build_result));
 
   build_path = get_build_directory (self);
   build_dir = g_file_new_for_path (build_path);
@@ -169,7 +171,13 @@ gbp_flatpak_runtime_prebuild_worker (GTask        *task,
   ide_subprocess_launcher_push_argv (launcher, flatpak_repo_path);
   process = ide_subprocess_launcher_spawn (launcher, cancellable, &error);
 
-  if (!process || !ide_subprocess_wait_check (process, cancellable, &error))
+  if (!process)
+    {
+      g_task_return_error (task, g_steal_pointer (&error));
+      return;
+    }
+  ide_build_result_log_subprocess (build_result, process);
+  if (!ide_subprocess_wait_check (process, cancellable, &error))
     {
       g_task_return_error (task, g_steal_pointer (&error));
       return;
@@ -227,7 +235,13 @@ gbp_flatpak_runtime_prebuild_worker (GTask        *task,
           ide_subprocess_launcher_push_argv (launcher3, manifest_path);
           process3 = ide_subprocess_launcher_spawn (launcher3, cancellable, &error);
 
-          if (!process3 || !ide_subprocess_wait_check (process3, cancellable, &error))
+          if (!process3)
+            {
+              g_task_return_error (task, g_steal_pointer (&error));
+              return;
+            }
+          ide_build_result_log_subprocess (build_result, process3);
+          if (!ide_subprocess_wait_check (process3, cancellable, &error))
             {
               g_task_return_error (task, g_steal_pointer (&error));
               return;
@@ -260,6 +274,12 @@ gbp_flatpak_runtime_prebuild_worker (GTask        *task,
   ide_subprocess_launcher_push_argv (launcher2, self->branch);
   process2 = ide_subprocess_launcher_spawn (launcher2, cancellable, &error);
 
+  if (!process2)
+    {
+      g_task_return_error (task, g_steal_pointer (&error));
+      return;
+    }
+  ide_build_result_log_subprocess (build_result, process2);
   /* If the directory is already initialized, don't fail */
   ide_subprocess_wait_check (process2, cancellable, NULL);
 
@@ -268,6 +288,7 @@ gbp_flatpak_runtime_prebuild_worker (GTask        *task,
 
 static void
 gbp_flatpak_runtime_prebuild_async (IdeRuntime          *runtime,
+                                    IdeBuildResult      *build_result,
                                     GCancellable        *cancellable,
                                     GAsyncReadyCallback  callback,
                                     gpointer             user_data)
@@ -276,9 +297,11 @@ gbp_flatpak_runtime_prebuild_async (IdeRuntime          *runtime,
   g_autoptr(GTask) task = NULL;
 
   g_assert (GBP_IS_FLATPAK_RUNTIME (self));
+  g_assert (IDE_IS_BUILD_RESULT (build_result));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_task_data (task, g_object_ref (build_result), (GDestroyNotify)g_object_unref);
   g_task_run_in_thread (task, gbp_flatpak_runtime_prebuild_worker);
 }
 
@@ -302,6 +325,7 @@ gbp_flatpak_runtime_postinstall_worker (GTask        *task,
                                         GCancellable *cancellable)
 {
   GbpFlatpakRuntime *self = source_object;
+  IdeBuildResult *build_result = (IdeBuildResult *)task_data;
   IdeContext *context;
   IdeConfigurationManager *config_manager;
   IdeConfiguration *configuration;
@@ -325,6 +349,7 @@ gbp_flatpak_runtime_postinstall_worker (GTask        *task,
 
   g_assert (G_IS_TASK (task));
   g_assert (GBP_IS_FLATPAK_RUNTIME (self));
+  g_assert (IDE_IS_BUILD_RESULT (build_result));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   context = ide_object_get_context (IDE_OBJECT (self));
@@ -394,7 +419,13 @@ gbp_flatpak_runtime_postinstall_worker (GTask        *task,
   process = ide_subprocess_launcher_spawn (launcher, cancellable, &error);
 
   /* Don't fail if the directory was already finished */
-  ide_subprocess_wait_check (process, cancellable, NULL);
+  if (!process)
+    {
+      g_task_return_error (task, g_steal_pointer (&error));
+      return;
+    }
+  ide_build_result_log_subprocess (build_result, process);
+  ide_subprocess_wait (process, cancellable, NULL);
 
   /* Export the build to the repo */
   launcher2 = IDE_RUNTIME_CLASS (gbp_flatpak_runtime_parent_class)->create_launcher (IDE_RUNTIME (self), 
&error);
@@ -410,7 +441,13 @@ gbp_flatpak_runtime_postinstall_worker (GTask        *task,
   ide_subprocess_launcher_push_argv (launcher2, build_path);
   process2 = ide_subprocess_launcher_spawn (launcher2, cancellable, &error);
 
-  if (!process2 || !ide_subprocess_wait_check (process2, cancellable, &error))
+  if (!process2)
+    {
+      g_task_return_error (task, g_steal_pointer (&error));
+      return;
+    }
+  ide_build_result_log_subprocess (build_result, process2);
+  if (!ide_subprocess_wait_check (process2, cancellable, &error))
     {
       g_task_return_error (task, g_steal_pointer (&error));
       return;
@@ -435,7 +472,13 @@ gbp_flatpak_runtime_postinstall_worker (GTask        *task,
   ide_subprocess_launcher_push_argv (launcher3, app_id);
   process3 = ide_subprocess_launcher_spawn (launcher3, cancellable, NULL);
 
-  ide_subprocess_wait_check (process3, cancellable, NULL);
+  if (!process3)
+    {
+      g_task_return_error (task, g_steal_pointer (&error));
+      return;
+    }
+  ide_build_result_log_subprocess (build_result, process3);
+  ide_subprocess_wait (process3, cancellable, NULL);
 
   /* Finally install the app */
   launcher4 = IDE_RUNTIME_CLASS (gbp_flatpak_runtime_parent_class)->create_launcher (IDE_RUNTIME (self), 
&error);
@@ -453,7 +496,13 @@ gbp_flatpak_runtime_postinstall_worker (GTask        *task,
 
   process4 = ide_subprocess_launcher_spawn (launcher4, cancellable, &error);
 
-  if (!process4 || !ide_subprocess_wait_check (process4, cancellable, &error))
+  if (!process4)
+    {
+      g_task_return_error (task, g_steal_pointer (&error));
+      return;
+    }
+  ide_build_result_log_subprocess (build_result, process4);
+  if (!ide_subprocess_wait_check (process4, cancellable, &error))
     {
       g_task_return_error (task, g_steal_pointer (&error));
       return;
@@ -464,6 +513,7 @@ gbp_flatpak_runtime_postinstall_worker (GTask        *task,
 
 static void
 gbp_flatpak_runtime_postinstall_async (IdeRuntime          *runtime,
+                                       IdeBuildResult      *build_result,
                                        GCancellable        *cancellable,
                                        GAsyncReadyCallback  callback,
                                        gpointer             user_data)
@@ -472,9 +522,11 @@ gbp_flatpak_runtime_postinstall_async (IdeRuntime          *runtime,
   g_autoptr(GTask) task = NULL;
 
   g_assert (GBP_IS_FLATPAK_RUNTIME (self));
+  g_assert (IDE_IS_BUILD_RESULT (build_result));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
   task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_task_data (task, g_object_ref (build_result), (GDestroyNotify)g_object_unref);
   g_task_run_in_thread (task, gbp_flatpak_runtime_postinstall_worker);
 }
 


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