[anjuta] build-basic-autotools: bgo #727637 - Autotools plugin should be able to find the correct executable
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] build-basic-autotools: bgo #727637 - Autotools plugin should be able to find the correct executable
- Date: Mon, 21 Apr 2014 13:21:30 +0000 (UTC)
commit 81450126a8ff0a1afac50617c08a8a8d7a7fa8d4
Author: Sébastien Granjoux <seb sfo free fr>
Date: Sun Apr 20 18:57:31 2014 +0200
build-basic-autotools: bgo #727637 - Autotools plugin should be able to find the correct executable when
the project configuration changes
plugins/build-basic-autotools/build.c | 58 ++++++++++++++++++++++++++++++++
plugins/build-basic-autotools/build.h | 3 ++
plugins/build-basic-autotools/plugin.c | 18 ++++++---
plugins/run-program/plugin.c | 33 ++++++++++++++++++
plugins/run-program/plugin.h | 3 ++
5 files changed, 109 insertions(+), 6 deletions(-)
---
diff --git a/plugins/build-basic-autotools/build.c b/plugins/build-basic-autotools/build.c
index 380a045..e7120cc 100644
--- a/plugins/build-basic-autotools/build.c
+++ b/plugins/build-basic-autotools/build.c
@@ -63,6 +63,8 @@ typedef struct
#define DEFAULT_COMMAND_CHECK "make check"
#define DEFAULT_COMMAND_AUTORECONF "autoreconf -i --force"
+#define RUN_PROGRAM_URI "run_program_uri"
+
#define CHOOSE_COMMAND(plugin,command) \
((plugin->commands[(IANJUTA_BUILDABLE_COMMAND_##command)]) ? \
(plugin->commands[(IANJUTA_BUILDABLE_COMMAND_##command)]) \
@@ -232,6 +234,55 @@ shell_quotef (const gchar *format,...)
return quoted_str;
}
+/* Get target relative to current configuration if existing or NULL if the current
+ * target is not relative to the current configuration */
+gchar *
+get_configuration_relative_target (BasicAutotoolsPlugin *plugin)
+{
+ gchar *relative_target = NULL;
+ gchar *uri;
+
+ anjuta_shell_get (ANJUTA_PLUGIN (plugin)->shell, RUN_PROGRAM_URI, G_TYPE_STRING, &uri, NULL);
+ if (uri != NULL)
+ {
+ GFile *target;
+ GFile *file;
+
+ target = g_file_new_for_uri (uri);
+ file = build_configuration_list_get_build_file (plugin->configurations,
build_configuration_list_get_selected (plugin->configurations));
+ relative_target = g_file_get_relative_path (file, target);
+ g_object_unref (file);
+ g_object_unref (target);
+ g_free (uri);
+ }
+
+ return relative_target;
+}
+
+/* Set target relative to current configuration if relative_target is not NULL*/
+void
+set_configuration_relative_target (BasicAutotoolsPlugin *plugin, const gchar* relative_target)
+{
+ if (relative_target != NULL)
+ {
+ GFile *file;
+ GFile *target;
+ gchar *uri;
+ GValue value = {0,};
+
+ file = build_configuration_list_get_build_file (plugin->configurations,
build_configuration_list_get_selected (plugin->configurations));
+ target = g_file_get_child (file, relative_target);
+ uri = g_file_get_uri (target);
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_static_string (&value, uri);
+ anjuta_shell_add_value (ANJUTA_PLUGIN (plugin)->shell, RUN_PROGRAM_URI, &value, NULL);
+ g_value_unset (&value);
+ g_object_unref (target);
+ g_object_unref (file);
+ }
+}
+
+
/* 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
@@ -1128,6 +1179,7 @@ build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *fil
const gchar *project_root;
GValue value = {0,};
const gchar *old_config_name;
+ gchar *relative_target;
BuildContext* context = NULL;
run_autogen = !directory_has_file (plugin->project_root_dir, "configure");
@@ -1141,6 +1193,7 @@ build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *fil
parent = GTK_WINDOW (ANJUTA_PLUGIN(plugin)->shell);
old_config_name = build_configuration_get_name (build_configuration_list_get_selected
(plugin->configurations));
+ relative_target = get_configuration_relative_target (plugin);
if (build_dialog_configure (parent, project_root, plugin->configurations, &run_autogen))
{
BuildConfiguration *config;
@@ -1167,7 +1220,12 @@ build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *fil
/* Restore previous configuration */
build_configuration_list_select (plugin->configurations, old_config_name);
}
+ else
+ {
+ set_configuration_relative_target (plugin, relative_target);
+ }
}
+ g_free (relative_target);
return context;
}
diff --git a/plugins/build-basic-autotools/build.h b/plugins/build-basic-autotools/build.h
index 44b20c1..ee48ec0 100644
--- a/plugins/build-basic-autotools/build.h
+++ b/plugins/build-basic-autotools/build.h
@@ -35,6 +35,9 @@ GFile * normalize_project_file (GFile *file, GFile *root);
gboolean directory_has_makefile (GFile *dir);
gboolean directory_has_makefile_am (BasicAutotoolsPlugin *bb_plugin, GFile *dir);
+gchar * get_configuration_relative_target (BasicAutotoolsPlugin *plugin);
+void set_configuration_relative_target (BasicAutotoolsPlugin *plugin, const gchar* relative_target);
+
/* Build function type */
typedef BuildContext* (*BuildFunc) (BasicAutotoolsPlugin *plugin, GFile *file,
IAnjutaBuilderCallback callback, gpointer user_data,
diff --git a/plugins/build-basic-autotools/plugin.c b/plugins/build-basic-autotools/plugin.c
index 341c6ae..98d2155 100644
--- a/plugins/build-basic-autotools/plugin.c
+++ b/plugins/build-basic-autotools/plugin.c
@@ -1542,24 +1542,30 @@ on_select_configuration (GtkRadioMenuItem *item, gpointer user_data)
{
BasicAutotoolsPlugin *plugin = ANJUTA_PLUGIN_BASIC_AUTOTOOLS (user_data);
gchar *name;
- GValue *value;
+ GValue value = {0,};
GFile *file;
gchar *uri;
+ gchar *relative_target;
name = g_object_get_data (G_OBJECT (item), "untranslated_name");
- build_configuration_list_select (plugin->configurations, name);
+ // Get URI of the current target to update it automatically if another configuration is
selected
+ relative_target = get_configuration_relative_target (plugin);
- value = g_new0 (GValue, 1);
- g_value_init (value, G_TYPE_STRING);
+ build_configuration_list_select (plugin->configurations, name);
+ g_free (name);
+ g_value_init (&value, G_TYPE_STRING);
file = build_configuration_list_get_build_file (plugin->configurations,
build_configuration_list_get_selected (plugin->configurations));
uri = g_file_get_uri (file);
- g_value_set_string (value, uri);
+ g_value_set_static_string (&value, uri);
+ anjuta_shell_add_value (ANJUTA_PLUGIN (plugin)->shell, IANJUTA_BUILDER_ROOT_URI, &value,
NULL);
g_free (uri);
g_object_unref (file);
- anjuta_shell_add_value (ANJUTA_PLUGIN (plugin)->shell, IANJUTA_BUILDER_ROOT_URI, value, NULL);
+ // Update URI of current target if it is relative to the configuration
+ set_configuration_relative_target (plugin, relative_target);
+ g_free (relative_target);
}
}
diff --git a/plugins/run-program/plugin.c b/plugins/run-program/plugin.c
index 6398f83..0b941d8 100644
--- a/plugins/run-program/plugin.c
+++ b/plugins/run-program/plugin.c
@@ -256,6 +256,30 @@ on_program_parameters_activate (GtkAction* action, RunProgramPlugin* plugin)
run_parameters_dialog_run (plugin);
}
+static void
+on_value_run_program_added (AnjutaPlugin *plugin, const gchar *name, const GValue *value, gpointer data)
+{
+ RunProgramPlugin *self = ANJUTA_PLUGIN_RUN_PROGRAM (plugin);
+ gchar *uri;
+
+ // Update last target if RUN_PROGRAM_URI is changed by another plugin
+ anjuta_shell_get (plugin->shell,
+ RUN_PROGRAM_URI, G_TYPE_STRING, &uri, NULL);
+ if (self->recent_target != NULL)
+ {
+ GFile *target = g_file_new_for_uri (uri);
+
+ if (!g_file_equal ((GFile *)self->recent_target->data, target))
+ {
+ // Update target uri
+ g_object_unref ((GObject *)self->recent_target->data);
+ self->recent_target->data = g_object_ref (target);
+ }
+ g_object_unref (target);
+ }
+ g_free (uri);
+}
+
/* Actions table
*---------------------------------------------------------------------------*/
@@ -311,6 +335,13 @@ run_plugin_activate (AnjutaPlugin *plugin)
g_signal_connect (plugin->shell, "load-session",
G_CALLBACK (on_session_load), self);
+ /* Add watches */
+ self->program_watch = anjuta_plugin_add_watch (ANJUTA_PLUGIN (self),
+ RUN_PROGRAM_URI,
+ on_value_run_program_added,
+ NULL,
+ NULL);
+
/* Add actions */
ui = anjuta_shell_get_ui (plugin->shell, NULL);
self->action_group = anjuta_ui_add_action_group_entries (ui,
@@ -338,6 +369,8 @@ run_plugin_deactivate (AnjutaPlugin *plugin)
anjuta_ui_unmerge (ui, self->uiid);
+ anjuta_plugin_remove_watch (plugin, self->program_watch, FALSE);
+
g_signal_handlers_disconnect_by_func (plugin->shell, G_CALLBACK (on_session_save), self);
g_signal_handlers_disconnect_by_func (plugin->shell, G_CALLBACK (on_session_load), self);
diff --git a/plugins/run-program/plugin.h b/plugins/run-program/plugin.h
index dc8a051..e4ab82a 100644
--- a/plugins/run-program/plugin.h
+++ b/plugins/run-program/plugin.h
@@ -69,6 +69,9 @@ struct _RunProgramPlugin
/* IAnjutaTerminal object */
IAnjutaTerminal *terminal;
+
+ /* Watch */
+ gint program_watch;
};
void run_plugin_update_shell_value (RunProgramPlugin *plugin);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]