[gnome-builder] autotools: Call the runtime's postinstall hook when necessary



commit 60fa28d9c2d74e41c9c67b4f21fc9f6b72fa2914
Author: Matthew Leeds <mwl458 gmail com>
Date:   Mon Oct 10 13:23:19 2016 -0500

    autotools: Call the runtime's postinstall hook when necessary
    
    1. Add an install property to IdeAutotoolsBuildTask.
    2. Properly initialize that property in IdeAutotoolsBuilder.
    3. Call either ide_runtime_postbuild_async or
      ide_runtime_postinstall_async from the build task depending on the situation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772898

 plugins/autotools/ide-autotools-build-task.c |   69 ++++++++++++++++++++++----
 plugins/autotools/ide-autotools-builder.c    |    2 +
 2 files changed, 61 insertions(+), 10 deletions(-)
---
diff --git a/plugins/autotools/ide-autotools-build-task.c b/plugins/autotools/ide-autotools-build-task.c
index 859ecd3..6bfe51c 100644
--- a/plugins/autotools/ide-autotools-build-task.c
+++ b/plugins/autotools/ide-autotools-build-task.c
@@ -42,6 +42,7 @@ struct _IdeAutotoolsBuildTask
   guint             require_autogen : 1;
   guint             require_configure : 1;
   guint             executed : 1;
+  guint             install : 1;
 };
 
 typedef struct
@@ -74,6 +75,7 @@ enum {
   PROP_DIRECTORY,
   PROP_REQUIRE_AUTOGEN,
   PROP_REQUIRE_CONFIGURE,
+  PROP_INSTALL,
   LAST_PROP
 };
 
@@ -145,6 +147,23 @@ ide_autotools_build_task_set_require_configure (IdeAutotoolsBuildTask *self,
   self->require_autogen = !!require_configure;
 }
 
+gboolean
+ide_autotools_build_task_get_install (IdeAutotoolsBuildTask *self)
+{
+  g_return_val_if_fail (IDE_IS_AUTOTOOLS_BUILD_TASK (self), FALSE);
+
+  return self->install;
+}
+
+static void
+ide_autotools_build_task_set_install (IdeAutotoolsBuildTask *self,
+                                      gboolean               install)
+{
+  g_return_if_fail (IDE_IS_AUTOTOOLS_BUILD_TASK (self));
+
+  self->install = !!install;
+}
+
 /**
  * ide_autotools_build_task_get_directory:
  *
@@ -252,6 +271,10 @@ ide_autotools_build_task_get_property (GObject    *object,
       g_value_set_boolean (value, ide_autotools_build_task_get_require_configure (self));
       break;
 
+    case PROP_INSTALL:
+      g_value_set_boolean (value, ide_autotools_build_task_get_install (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -283,6 +306,10 @@ ide_autotools_build_task_set_property (GObject      *object,
       ide_autotools_build_task_set_require_configure (self, g_value_get_boolean (value));
       break;
 
+    case PROP_INSTALL:
+      ide_autotools_build_task_set_install (self, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -333,6 +360,15 @@ ide_autotools_build_task_class_init (IdeAutotoolsBuildTaskClass *klass)
                            G_PARAM_CONSTRUCT_ONLY |
                            G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_INSTALL] =
+    g_param_spec_boolean ("install",
+                          "Install",
+                          "If the build is an install.",
+                          FALSE,
+                          (G_PARAM_READWRITE |
+                           G_PARAM_CONSTRUCT_ONLY |
+                           G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, LAST_PROP, properties);
 }
 
@@ -737,18 +773,25 @@ ide_autotools_build_task_postbuild_runtime_cb (GObject      *object,
   IdeRuntime *runtime = (IdeRuntime *)object;
   g_autoptr(GTask) task = user_data;
   g_autoptr(GError) error = NULL;
+  IdeAutotoolsBuildTask *self;
+  gboolean ret;
 
   g_assert (IDE_IS_RUNTIME (runtime));
   g_assert (G_IS_ASYNC_RESULT (result));
   g_assert (G_IS_TASK (task));
 
-  if (!ide_runtime_postbuild_finish (runtime, result, &error))
-    {
-      g_task_return_error (task, g_steal_pointer (&error));
-      return;
-    }
+  self = g_task_get_source_object (task);
+  g_assert (IDE_IS_AUTOTOOLS_BUILD_TASK (self));
 
-  g_task_return_boolean (task, TRUE);
+  if (self->install)
+    ret = ide_runtime_postinstall_finish (runtime, result, &error);
+  else
+    ret = ide_runtime_postbuild_finish (runtime, result, &error);
+
+  if (!ret)
+    g_task_return_error (task, g_steal_pointer (&error));
+  else
+    g_task_return_boolean (task, TRUE);
 }
 
 static void
@@ -786,10 +829,16 @@ ide_autotools_build_task_execute_with_postbuild_cb (GObject      *object,
 
   cancellable = g_task_get_cancellable (task);
 
-  ide_runtime_postbuild_async (runtime,
-                               cancellable,
-                               ide_autotools_build_task_postbuild_runtime_cb,
-                               g_steal_pointer (&task));
+  if (self->install)
+    ide_runtime_postinstall_async (runtime,
+                                   cancellable,
+                                   ide_autotools_build_task_postbuild_runtime_cb,
+                                   g_steal_pointer (&task));
+  else
+    ide_runtime_postbuild_async (runtime,
+                                 cancellable,
+                                 ide_autotools_build_task_postbuild_runtime_cb,
+                                 g_steal_pointer (&task));
 }
 
 void
diff --git a/plugins/autotools/ide-autotools-builder.c b/plugins/autotools/ide-autotools-builder.c
index 2d95191..f9d4aa0 100644
--- a/plugins/autotools/ide-autotools-builder.c
+++ b/plugins/autotools/ide-autotools-builder.c
@@ -158,6 +158,7 @@ ide_autotools_builder_build_async (IdeBuilder           *builder,
                                "directory", directory,
                                "mode", _("Building…"),
                                "running", TRUE,
+                               "install", FALSE,
                                NULL);
 
   if (result != NULL)
@@ -239,6 +240,7 @@ ide_autotools_builder_install_async (IdeBuilder           *builder,
                                "directory", directory,
                                "mode", _("Building…"),
                                "running", TRUE,
+                               "install", TRUE,
                                NULL);
 
   ide_autotools_build_task_add_target (build_result, "install");


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