[gnome-builder/wip/libide: 44/153] libide: add "rebuild" option when building a project



commit dbb13cf3076553854e8a0c0c20feb2798932b3bb
Author: Christian Hergert <christian hergert me>
Date:   Sun Feb 8 14:26:21 2015 -0800

    libide: add "rebuild" option when building a project
    
    ./ide-build --rebuild ../my_project/configure.ac
    
    This will force a `make clean' before `make all'.

 libide/autotools/ide-autotools-build-task.c |  101 +++++++++------------------
 tools/ide-build.c                           |    9 ++-
 2 files changed, 41 insertions(+), 69 deletions(-)
---
diff --git a/libide/autotools/ide-autotools-build-task.c b/libide/autotools/ide-autotools-build-task.c
index 40e027c..ec19aa7 100644
--- a/libide/autotools/ide-autotools-build-task.c
+++ b/libide/autotools/ide-autotools-build-task.c
@@ -30,7 +30,6 @@ typedef struct
   GKeyFile  *config;
   IdeDevice *device;
   GFile     *directory;
-  gchar     *make_target;
   guint      require_autogen : 1;
   guint      require_configure : 1;
   guint      executed : 1;
@@ -41,8 +40,8 @@ typedef struct
   gchar  *directory_path;
   gchar  *project_path;
   gchar  *system_type;
-  gchar  *make_target;
   gchar **configure_argv;
+  gchar **make_targets;
   guint   require_autogen : 1;
   guint   require_configure : 1;
 } WorkerState;
@@ -60,7 +59,6 @@ enum {
   PROP_CONFIG,
   PROP_DEVICE,
   PROP_DIRECTORY,
-  PROP_MAKE_TARGET,
   PROP_REQUIRE_AUTOGEN,
   PROP_REQUIRE_CONFIGURE,
   LAST_PROP
@@ -97,35 +95,6 @@ static WorkStep gWorkSteps [] = {
   NULL
 };
 
-const gchar *
-ide_autotools_build_task_get_make_target (IdeAutotoolsBuildTask *task)
-{
-  IdeAutotoolsBuildTaskPrivate *priv;
-
-  g_return_val_if_fail (IDE_IS_AUTOTOOLS_BUILD_TASK (task), NULL);
-
-  priv = ide_autotools_build_task_get_instance_private (task);
-
-  return priv->make_target;
-}
-
-static void
-ide_autotools_build_task_set_make_target (IdeAutotoolsBuildTask *task,
-                                          const gchar           *make_target)
-{
-  IdeAutotoolsBuildTaskPrivate *priv;
-
-  g_return_if_fail (IDE_IS_AUTOTOOLS_BUILD_TASK (task));
-
-  priv = ide_autotools_build_task_get_instance_private (task);
-
-  if (priv->make_target != make_target)
-    {
-      g_free (priv->make_target);
-      priv->make_target = g_strdup (make_target);
-    }
-}
-
 gboolean
 ide_autotools_build_task_get_require_autogen (IdeAutotoolsBuildTask *task)
 {
@@ -343,11 +312,6 @@ ide_autotools_build_task_get_property (GObject    *object,
                           ide_autotools_build_task_get_directory (self));
       break;
 
-    case PROP_MAKE_TARGET:
-      g_value_set_string (value,
-                          ide_autotools_build_task_get_make_target (self));
-      break;
-
     case PROP_REQUIRE_AUTOGEN:
       g_value_set_boolean (value,
                            ide_autotools_build_task_get_require_autogen (self));
@@ -388,11 +352,6 @@ ide_autotools_build_task_set_property (GObject      *object,
                                               g_value_get_object (value));
       break;
 
-    case PROP_MAKE_TARGET:
-      ide_autotools_build_task_set_make_target (self,
-                                                g_value_get_string (value));
-      break;
-
     case PROP_REQUIRE_AUTOGEN:
       ide_autotools_build_task_set_require_autogen (self,
                                                     g_value_get_boolean (value));
@@ -450,17 +409,6 @@ ide_autotools_build_task_class_init (IdeAutotoolsBuildTaskClass *klass)
   g_object_class_install_property (object_class, PROP_DIRECTORY,
                                    gParamSpecs [PROP_DIRECTORY]);
 
-  gParamSpecs [PROP_MAKE_TARGET] =
-    g_param_spec_string ("make-target",
-                         _("Make Target"),
-                         _("The make target to execute."),
-                         "all",
-                         (G_PARAM_READWRITE |
-                          G_PARAM_CONSTRUCT_ONLY |
-                          G_PARAM_STATIC_STRINGS));
-  g_object_class_install_property (object_class, PROP_MAKE_TARGET,
-                                   gParamSpecs [PROP_MAKE_TARGET]);
-
   gParamSpecs [PROP_REQUIRE_AUTOGEN] =
     g_param_spec_boolean ("require-autogen",
                           _("Require Autogen"),
@@ -578,6 +526,7 @@ worker_state_new (IdeAutotoolsBuildTask *self)
   IdeAutotoolsBuildTaskPrivate *priv;
   g_autoptr(gchar) name = NULL;
   IdeContext *context;
+  GPtrArray *make_targets;
   GFile *project_dir;
   GFile *project_file;
   WorkerState *state;
@@ -596,15 +545,22 @@ worker_state_new (IdeAutotoolsBuildTask *self)
   else
     project_dir = g_object_ref (project_file);
 
+  make_targets = g_ptr_array_new ();
+  if (priv->config &&
+      g_key_file_get_boolean (priv->config, "autotools", "rebuild", NULL))
+    g_ptr_array_add (make_targets, g_strdup ("clean"));
+  g_ptr_array_add (make_targets, g_strdup ("all"));
+  g_ptr_array_add (make_targets, NULL);
+
   state = g_slice_new0 (WorkerState);
 
   state->directory_path = g_file_get_path (priv->directory);
   state->project_path = g_file_get_path (project_dir);
   state->system_type = g_strdup (ide_device_get_system_type (priv->device));
   state->configure_argv = gen_configure_argv (self, state);
-  state->make_target = g_strdup (priv->make_target);
   state->require_autogen = priv->require_autogen;
   state->require_configure = priv->require_configure;
+  state->make_targets = (gchar **)g_ptr_array_free (make_targets, FALSE);
 
   return state;
 }
@@ -617,7 +573,6 @@ worker_state_free (void *data)
   g_free (state->directory_path);
   g_free (state->project_path);
   g_free (state->system_type);
-  g_free (state->make_target);
   g_slice_free (WorkerState, state);
 }
 
@@ -915,8 +870,10 @@ step_make_all  (GTask                 *task,
 {
   g_autoptr(GSubprocessLauncher) launcher = NULL;
   g_autoptr(GSubprocess) process = NULL;
-  const gchar *target;
+  const gchar * const *targets;
+  gchar *default_targets[] = { "all", NULL };
   GError *error = NULL;
+  guint i;
 
   g_assert (G_IS_TASK (task));
   g_assert (IDE_IS_AUTOTOOLS_BUILD_TASK (self));
@@ -927,22 +884,30 @@ step_make_all  (GTask                 *task,
                                          G_SUBPROCESS_FLAGS_STDOUT_PIPE));
   g_subprocess_launcher_set_cwd (launcher, state->directory_path);
 
-  target = state->make_target ?: "all";
-
-  process = log_and_spawn (self, launcher, &error, "make", target, NULL);
+  if (!g_strv_length (state->make_targets))
+    targets = (const gchar * const *)default_targets;
+  else
+    targets = (const gchar * const *)state->make_targets;
 
-  if (!process)
+  for (i = 0; targets [i]; i++)
     {
-      g_task_return_error (task, error);
-      return FALSE;
-    }
+      const gchar *target = targets [i];
 
-  ide_build_result_log_subprocess (IDE_BUILD_RESULT (self), process);
+      process = log_and_spawn (self, launcher, &error, "make", target, NULL);
 
-  if (!g_subprocess_wait_check (process, cancellable, &error))
-    {
-      g_task_return_error (task, error);
-      return FALSE;
+      if (!process)
+        {
+          g_task_return_error (task, error);
+          return FALSE;
+        }
+
+      ide_build_result_log_subprocess (IDE_BUILD_RESULT (self), process);
+
+      if (!g_subprocess_wait_check (process, cancellable, &error))
+        {
+          g_task_return_error (task, error);
+          return FALSE;
+        }
     }
 
   return TRUE;
diff --git a/tools/ide-build.c b/tools/ide-build.c
index cc66a29..6dff089 100644
--- a/tools/ide-build.c
+++ b/tools/ide-build.c
@@ -32,6 +32,7 @@ static IdeContext *gContext;
 static guint gTimeout;
 static gulong gAddedHandler;
 static guint64 gBuildStart;
+static gboolean gRebuild;
 
 static void read_line_cb (GObject      *object,
                           GAsyncResult *result,
@@ -207,8 +208,12 @@ build_for_device (IdeContext *context,
 
   print_build_info (context, device);
 
-  build_system = ide_context_get_build_system (context);
   config = g_key_file_new ();
+
+  if (gRebuild)
+    g_key_file_set_boolean (config, "autotools", "rebuild", TRUE);
+
+  build_system = ide_context_get_build_system (context);
   builder = ide_build_system_get_builder (build_system, config, device, &error);
   g_key_file_unref (config);
 
@@ -337,6 +342,8 @@ main (gint   argc,
       N_("The target device we are building for."),
       N_("DEVICE_ID")
     },
+    { "rebuild", 'r', 0, G_OPTION_ARG_NONE, &gRebuild,
+      N_("Clean and rebuild the project.") },
     { NULL }
   };
   g_autoptr(GOptionContext) context = NULL;


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