[anjuta] build-basic-autotools, run-program: bgo #655756 - User should be notified if execution of a project



commit cad9a754a658285e5c327c6bdf1596014db0c1ef
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Sat Sep 3 16:35:23 2011 +0200

    build-basic-autotools, run-program: bgo #655756 - User should be notified if execution of a project fails

 plugins/build-basic-autotools/build.c  |   92 +++++++++++++++++++-------------
 plugins/build-basic-autotools/build.h  |   26 +++++++---
 plugins/build-basic-autotools/plugin.c |   36 ++++++------
 plugins/run-program/execute.c          |    7 ++-
 plugins/run-program/parameters.c       |    1 +
 5 files changed, 97 insertions(+), 65 deletions(-)
---
diff --git a/plugins/build-basic-autotools/build.c b/plugins/build-basic-autotools/build.c
index 4a7d5c6..85ed4f2 100644
--- a/plugins/build-basic-autotools/build.c
+++ b/plugins/build-basic-autotools/build.c
@@ -40,6 +40,8 @@ typedef struct
 	gchar *args;
 	GFile *file;
 	BuildFunc func;
+	IAnjutaBuilderCallback callback;
+	gpointer user_data;
 } BuildConfigureAndBuild;
 
 /* Constants
@@ -183,6 +185,23 @@ shell_quotef (const gchar *format,...)
 	return quoted_str;
 }
 
+/* Return FALSE if Makefile is missing and we have both a Makefile.am and a project
+ * open, meaning that we need to configure the project to get a Makefile */
+static gboolean
+is_configured (BasicAutotoolsPlugin *plugin, GFile *file)
+{
+	GFile *build_dir;
+	gboolean has_makefile;
+	gboolean has_makefile_am;
+
+	/* Get build directory and check for makefiles */
+	build_dir = build_file_from_file (plugin, file, NULL);
+	has_makefile = directory_has_makefile (build_dir);
+	has_makefile_am = directory_has_makefile_am (plugin, build_dir);
+	g_object_unref (build_dir);
+
+	return has_makefile || !has_makefile_am || (plugin->project_root_dir == NULL);
+}
 
 /* Return build path from a source directory */
 static GFile *
@@ -494,7 +513,6 @@ build_build_file_or_dir (BasicAutotoolsPlugin *plugin,
 	BuildConfiguration *config;
 	GList *vars;
 
-	
 	config = build_configuration_list_get_selected (plugin->configurations);
 	vars = build_configuration_get_variables (config);
 	
@@ -647,24 +665,27 @@ BuildContext*
 build_clean_dir (BasicAutotoolsPlugin *plugin, GFile *file,
 				 GError **err)
 {
-	BuildContext *context;
+	BuildContext *context = NULL;
 	BuildProgram *prog;
 	GFile *build_dir;
 	BuildConfiguration *config;
 	GList *vars;
 
-	config = build_configuration_list_get_selected (plugin->configurations);
-	vars = build_configuration_get_variables (config);
+	if (is_configured (plugin, file))
+	{
+		config = build_configuration_list_get_selected (plugin->configurations);
+		vars = build_configuration_get_variables (config);
 	
-	build_dir = build_file_from_file (plugin, file, NULL);
+		build_dir = build_file_from_file (plugin, file, NULL);
 
-	prog = build_program_new_with_command (build_dir,
-	                                       "%s",
-	                                       CHOOSE_COMMAND (plugin, CLEAN)),
-	build_program_add_env_list (prog, vars);
+		prog = build_program_new_with_command (build_dir,
+		                                       "%s",
+		                                       CHOOSE_COMMAND (plugin, CLEAN)),
+		build_program_add_env_list (prog, vars);
 	
-	context = build_execute_command (plugin, prog, TRUE, err);
-	g_object_unref (build_dir);
+		context = build_execute_command (plugin, prog, TRUE, err);
+		g_object_unref (build_dir);
+	}
 	
 	return context;
 }
@@ -787,7 +808,7 @@ build_project_configured (GObject *sender,
 							gpointer user_data)
 {
 	BuildConfigureAndBuild *pack = (BuildConfigureAndBuild *)user_data;
-	
+
 	if (error == NULL)
 	{
 		BuildContext *context = (BuildContext *)handle;
@@ -808,7 +829,7 @@ build_project_configured (GObject *sender,
 		build_update_configuration_menu (plugin);
 
 		/* Call build function if necessary */
-		if ((pack) && (pack->func != NULL)) pack->func (plugin, pack->file, NULL, NULL, NULL);
+		if ((pack) && (pack->func != NULL)) pack->func (plugin, pack->file, pack->callback, pack->user_data, NULL);
 	}
 
 	if (pack)
@@ -821,7 +842,8 @@ build_project_configured (GObject *sender,
 
 BuildContext*
 build_configure_dir (BasicAutotoolsPlugin *plugin, GFile *dir, const gchar *args,
-                     BuildFunc func, GFile *file)
+                     BuildFunc func, GFile *file,
+                     IAnjutaBuilderCallback callback, gpointer user_data, GError **error)
 {
 	BuildContext *context;
 	BuildProgram *prog;
@@ -850,6 +872,8 @@ build_configure_dir (BasicAutotoolsPlugin *plugin, GFile *dir, const gchar *args
 	pack->args = NULL;
 	pack->func = func;
 	pack->file = (file != NULL) ? g_object_ref (file) : NULL;
+	pack->callback = callback;
+	pack->user_data = user_data;
 	build_program_set_callback (prog, build_project_configured, pack);
 	build_program_add_env_list (prog, vars);
 	
@@ -946,7 +970,8 @@ build_configure_after_autogen (GObject *sender,
 
 BuildContext*
 build_generate_dir (BasicAutotoolsPlugin *plugin, GFile *dir, const gchar *args,
-                    BuildFunc func, GFile *file)
+                    BuildFunc func, GFile *file,
+                    IAnjutaBuilderCallback callback, gpointer user_data, GError **error)
 {
 	BuildContext *context;
 	BuildProgram *prog;
@@ -984,6 +1009,8 @@ build_generate_dir (BasicAutotoolsPlugin *plugin, GFile *dir, const gchar *args,
 	pack->args = g_strdup (args);
 	pack->func = func;
 	pack->file = (file != NULL) ? g_object_ref (file) : NULL;
+	pack->callback = callback;
+	pack->user_data = user_data;
 	build_program_set_callback (prog, build_configure_after_autogen, pack);
 	build_program_add_env_list (prog, vars);
 	
@@ -992,21 +1019,22 @@ build_generate_dir (BasicAutotoolsPlugin *plugin, GFile *dir, const gchar *args,
 	return context;
 }
 
-void
-build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *file)
+BuildContext*
+build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *file, IAnjutaBuilderCallback callback, gpointer user_data, GError **error)
 {
 	GtkWindow *parent;
 	gboolean run_autogen = FALSE;
 	const gchar *project_root;
 	GValue value = {0,};
 	const gchar *old_config_name;
+	BuildContext* context = NULL;
 	
 	run_autogen = !directory_has_file (plugin->project_root_dir, "configure");
 	
 	anjuta_shell_get_value (ANJUTA_PLUGIN (plugin)->shell, IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI, &value, NULL);
 
 	/* In case, a project is not loaded */
-	if (!G_VALUE_HOLDS_STRING (&value)) return;
+	if (!G_VALUE_HOLDS_STRING (&value)) return NULL;
 
 	project_root = g_value_get_string (&value);
 	parent = GTK_WINDOW (ANJUTA_PLUGIN(plugin)->shell);
@@ -1015,7 +1043,6 @@ build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *fil
 	if (build_dialog_configure (parent, project_root, plugin->configurations, &run_autogen))
 	{
 		BuildConfiguration *config;
-		BuildContext* context;
 		GFile *build_file;
 		gchar *build_uri;
 		const gchar *args;
@@ -1029,11 +1056,11 @@ build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *fil
 
 		if (run_autogen)
 		{
-			context = build_generate_dir (plugin, build_file, args, func, file);
+			context = build_generate_dir (plugin, build_file, args, func, file, callback, user_data, error);
 		}
 		else
 		{
-			context = build_configure_dir (plugin, build_file, args, func, file);
+			context = build_configure_dir (plugin, build_file, args, func, file, callback, user_data, error);
 		}
 		g_object_unref (build_file);
 
@@ -1043,33 +1070,24 @@ build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *fil
 			build_configuration_list_select (plugin->configurations, old_config_name);
 		}
 	}
-	
+
+	return context;
 }
 
 /* Run configure if needed and then the build command */
-void
-build_configure_and_build (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *file)
+BuildContext*
+build_configure_and_build (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *file, IAnjutaBuilderCallback callback, gpointer user_data, GError **error)
 {
-	GFile *build_dir;
-	gboolean has_makefile;
-	gboolean has_makefile_am;
-
-	/* Get build directory and check for makefiles */
-	build_dir = build_file_from_file (plugin, file, NULL);
-	has_makefile = directory_has_makefile (build_dir);
-	has_makefile_am = directory_has_makefile_am (plugin, build_dir);
-	g_object_unref (build_dir);
-	
-	if (!has_makefile && has_makefile_am && (plugin->project_root_dir != NULL))
+	if (!is_configured (plugin, file))
 	{
 		/* Run configure first */
-		build_configure_dialog (plugin, func, file);
+		return build_configure_dialog (plugin, func, file, callback, user_data, error);
 	}
 	else
 	{
 		/* Some build functions have less arguments but
 		 * it is not a problem in C */
-		func (plugin, file, NULL, NULL, NULL);
+		return func (plugin, file, callback, user_data, error);
 	}
 }
 
diff --git a/plugins/build-basic-autotools/build.h b/plugins/build-basic-autotools/build.h
index be86c66..8636288 100644
--- a/plugins/build-basic-autotools/build.h
+++ b/plugins/build-basic-autotools/build.h
@@ -73,25 +73,37 @@ BuildContext* build_configure_dir (BasicAutotoolsPlugin *plugin,
                                    GFile *dir,
                                    const gchar *args,
                                    BuildFunc func,
-                                   GFile *file);
+                                   GFile *file,
+                                   IAnjutaBuilderCallback callback,
+                                   gpointer user_data,
+                                   GError **error);
 
 BuildContext* build_generate_dir (BasicAutotoolsPlugin *plugin,
                                   GFile *dir,
                                   const gchar *args,
                                   BuildFunc func,
-                                  GFile *file);
+                                  GFile *file,
+                                  IAnjutaBuilderCallback callback,
+                                  gpointer user_data,
+                                  GError **error);
 
 void build_project_configured (GObject *sender,
                                IAnjutaBuilderHandle handle,
                                GError *error,
                                gpointer user_data);
 
-void build_configure_and_build (BasicAutotoolsPlugin *plugin,
+BuildContext* build_configure_and_build (BasicAutotoolsPlugin *plugin,
                                 BuildFunc func,
-                                GFile *file);
-
-
-void build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *file);
+                                GFile *file,
+                                IAnjutaBuilderCallback callback,
+                                gpointer user_data,
+                                GError **err);
+
+BuildContext* build_configure_dialog (BasicAutotoolsPlugin *plugin,
+                             BuildFunc func, GFile *file,
+                             IAnjutaBuilderCallback callback,
+                             gpointer user_data,
+                             GError **error);
 
 
 GList* build_list_configuration (BasicAutotoolsPlugin *plugin);
diff --git a/plugins/build-basic-autotools/plugin.c b/plugins/build-basic-autotools/plugin.c
index 4491d80..ad88786 100644
--- a/plugins/build-basic-autotools/plugin.c
+++ b/plugins/build-basic-autotools/plugin.c
@@ -944,7 +944,7 @@ on_build_terminated (AnjutaLauncher *launcher,
 	if (context->program->callback != NULL)
 	{
 		GError *err = NULL;
-		
+
 		if (WIFEXITED (status))
 		{
 			if (WEXITSTATUS (status) != 0)
@@ -1257,7 +1257,7 @@ build_execute_command_in_context (BuildContext* context, GError **err)
 		build_context_destroy_command (context);
 		return FALSE;
 	}
-	
+
 	if (context->message_view)
 	{
 		gchar *command;
@@ -1415,7 +1415,7 @@ on_build_project (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
 	if (plugin->project_root_dir)
 	{
-		build_configure_and_build (plugin, build_build_file_or_dir, plugin->project_root_dir);
+		build_configure_and_build (plugin, build_build_file_or_dir, plugin->project_root_dir, NULL, NULL, NULL);
 	}
 }
 
@@ -1424,7 +1424,7 @@ on_install_project (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
 	if (plugin->project_root_dir)
 	{
-		build_configure_and_build (plugin, build_install_dir,  plugin->project_root_dir);
+		build_configure_and_build (plugin, build_install_dir,  plugin->project_root_dir, NULL, NULL, NULL);
 	}
 }
 
@@ -1440,13 +1440,13 @@ on_clean_project (GtkAction *action, BasicAutotoolsPlugin *plugin)
 static void
 on_configure_project (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
-	build_configure_dialog (plugin, NULL, NULL);
+	build_configure_dialog (plugin, NULL, NULL, NULL, NULL, NULL);
 }
 
 static void
 on_build_tarball (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
-	build_configure_and_build (plugin, (BuildFunc) build_tarball, NULL);	
+	build_configure_and_build (plugin, (BuildFunc) build_tarball, NULL, NULL, NULL, NULL);	
 }
 
 static void
@@ -1459,7 +1459,7 @@ on_build_module (GtkAction *action, BasicAutotoolsPlugin *plugin)
 	module = build_module_from_file (plugin, plugin->current_editor_file, NULL);
 	if (module != NULL)
 	{
-		build_configure_and_build (plugin, build_build_file_or_dir, module);
+		build_configure_and_build (plugin, build_build_file_or_dir, module, NULL, NULL, NULL);
 		g_object_unref (module);
 	}
 }
@@ -1469,7 +1469,7 @@ on_install_module (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
 	g_return_if_fail (plugin->current_editor_file != NULL);
 	
-	build_configure_and_build (plugin, build_install_dir,  plugin->current_editor_file);
+	build_configure_and_build (plugin, build_install_dir,  plugin->current_editor_file, NULL, NULL, NULL);
 }
 
 static void
@@ -1485,7 +1485,7 @@ on_compile_file (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
 	g_return_if_fail (plugin->current_editor_file != NULL);
 	
-	build_configure_and_build (plugin, (BuildFunc) build_compile_file, plugin->current_editor_file);
+	build_configure_and_build (plugin, (BuildFunc) build_compile_file, plugin->current_editor_file, NULL, NULL, NULL);
 }
 
 static void
@@ -1525,7 +1525,7 @@ fm_compile (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
 	g_return_if_fail (plugin->fm_current_file != NULL);
 
-	build_configure_and_build (plugin, (BuildFunc) build_compile_file, plugin->fm_current_file);
+	build_configure_and_build (plugin, (BuildFunc) build_compile_file, plugin->fm_current_file, NULL, NULL, NULL);
 }
 
 static void
@@ -1537,7 +1537,7 @@ fm_build (GtkAction *action, BasicAutotoolsPlugin *plugin)
 	module = build_module_from_file (plugin, plugin->fm_current_file, NULL);
 	if (module != NULL)
 	{
-		build_configure_and_build (plugin, build_build_file_or_dir, module);
+		build_configure_and_build (plugin, build_build_file_or_dir, module, NULL, NULL, NULL);
 		g_object_unref (module);
 	}
 }
@@ -1547,7 +1547,7 @@ fm_install (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
 	g_return_if_fail (plugin->fm_current_file != NULL);
 	
-	build_configure_and_build (plugin, build_install_dir,  plugin->fm_current_file);
+	build_configure_and_build (plugin, build_install_dir,  plugin->fm_current_file, NULL, NULL, NULL);
 }
 
 static void
@@ -1564,7 +1564,7 @@ pm_compile (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
 	g_return_if_fail (plugin->pm_current_file != NULL);
 
-	build_configure_and_build (plugin, (BuildFunc) build_compile_file, plugin->pm_current_file);
+	build_configure_and_build (plugin, (BuildFunc) build_compile_file, plugin->pm_current_file, NULL, NULL, NULL);
 }
 
 static void
@@ -1577,7 +1577,7 @@ pm_build (GtkAction *action, BasicAutotoolsPlugin *plugin)
 	module = build_module_from_file (plugin, plugin->pm_current_file, NULL);
 	if (module != NULL)
 	{
-		build_configure_and_build (plugin, build_build_file_or_dir, module);
+		build_configure_and_build (plugin, build_build_file_or_dir, module, NULL, NULL, NULL);
 		g_object_unref (module);
 	}
 }
@@ -1587,7 +1587,7 @@ pm_install (GtkAction *action, BasicAutotoolsPlugin *plugin)
 {
 	g_return_if_fail (plugin->pm_current_file != NULL);
 	
-	build_configure_and_build (plugin, build_install_dir,  plugin->pm_current_file);
+	build_configure_and_build (plugin, build_install_dir,  plugin->pm_current_file, NULL, NULL, NULL);
 }
 
 static void
@@ -2690,7 +2690,7 @@ ibuildable_configure (IAnjutaBuildable *manager, const gchar *directory,
 	file = g_file_new_for_path (directory);
 	if (file == NULL) return;
 	
-	build_configure_dir (plugin, file, NULL, NULL, NULL);
+	build_configure_dir (plugin, file, NULL, NULL, NULL, NULL, NULL, NULL);
 	
 	g_object_unref (file);
 }
@@ -2705,7 +2705,7 @@ ibuildable_generate (IAnjutaBuildable *manager, const gchar *directory,
 	file = g_file_new_for_path (directory);
 	if (file == NULL) return;
 
-	build_generate_dir (plugin, file, NULL, NULL, NULL);
+	build_generate_dir (plugin, file, NULL, NULL, NULL, NULL, NULL, NULL);
 	
 	g_object_unref (file);
 }
@@ -2798,7 +2798,7 @@ ibuilder_build (IAnjutaBuilder *builder, const gchar *uri,
 	file = g_file_new_for_uri (uri);
 	if (file == NULL) return NULL;
 	
-	context = build_build_file_or_dir (plugin, file, callback, user_data, err);
+	context = build_configure_and_build (plugin, build_build_file_or_dir, plugin->project_root_dir, callback, user_data, NULL);
 	
 	g_object_unref (file);
 	
diff --git a/plugins/run-program/execute.c b/plugins/run-program/execute.c
index 6a34749..6c0d1db 100644
--- a/plugins/run-program/execute.c
+++ b/plugins/run-program/execute.c
@@ -467,7 +467,7 @@ static void
 on_build_finished (GObject *builder, IAnjutaBuilderHandle handle, GError *err, gpointer user_data)
 {
 	RunProgramPlugin *plugin = (RunProgramPlugin *)user_data;
-	
+
 	if (err == NULL)
 	{
 		/* Up to date, run program */
@@ -484,19 +484,20 @@ static void
 on_is_built_finished (GObject *builder, IAnjutaBuilderHandle handle, GError *err, gpointer user_data)
 {
 	RunProgramPlugin *plugin = (RunProgramPlugin *)user_data;
-	
+
 	if (err == NULL)
 	{
 		/* Up to date, run program */
 		run_program (plugin);
 	}
-	else if (err->code == IANJUTA_BUILDER_FAILED)
+	else if ((err->code != IANJUTA_BUILDER_ABORTED) && (err->code != IANJUTA_BUILDER_CANCELED))
 	{
 		/* Target is not up to date */
 		plugin->build_handle = ianjuta_builder_build (IANJUTA_BUILDER (builder), plugin->build_uri, on_build_finished, plugin, NULL);
 	}
 	else
 	{
+		/* Command cancelled */
 		g_free (plugin->build_uri);
 		plugin->build_uri = NULL;
 	}
diff --git a/plugins/run-program/parameters.c b/plugins/run-program/parameters.c
index f396955..1ae7d10 100644
--- a/plugins/run-program/parameters.c
+++ b/plugins/run-program/parameters.c
@@ -786,6 +786,7 @@ run_parameters_dialog_or_try_execute (RunProgramPlugin *plugin, gboolean try_run
 	
 	run_dialog_init (&dlg, plugin);
 	const char *target = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (dlg.target))));
+
 	if (try_run && target && *target)
 	{
 		save_dialog_data (&dlg);



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