[anjuta] am-project: Add a new test and fix issue when changing several target properties at the same time
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] am-project: Add a new test and fix issue when changing several target properties at the same time
- Date: Wed, 20 Apr 2011 20:51:51 +0000 (UTC)
commit 6765569727160444134d8307d6fea64a0010fdeb
Author: Sébastien Granjoux <seb sfo free fr>
Date: Wed Apr 20 22:32:57 2011 +0200
am-project: Add a new test and fix issue when changing several target properties at the same time
plugins/am-project/am-writer.c | 46 +++++++++++++++++-------------
plugins/am-project/am-writer.h | 2 +-
plugins/am-project/amp-group.c | 11 +++++++
plugins/am-project/amp-group.h | 1 +
plugins/am-project/amp-target.c | 21 ++++++++++++-
plugins/am-project/amp-target.h | 1 +
plugins/am-project/tests/properties.at | 48 ++++++++++++++++++++++++++++++++
7 files changed, 107 insertions(+), 23 deletions(-)
---
diff --git a/plugins/am-project/am-writer.c b/plugins/am-project/am-writer.c
index 49b8a7b..a8fb3aa 100644
--- a/plugins/am-project/am-writer.c
+++ b/plugins/am-project/am-writer.c
@@ -771,7 +771,7 @@ amp_target_add_in_list (AmpProject *project, AnjutaToken *list, AnjutaProjectNod
anjuta_token_style_free (style);
amp_group_node_update_makefile (parent, token);
-
+
amp_target_node_add_token (AMP_TARGET_NODE (target), ANJUTA_TOKEN_ARGUMENT, token);
return token;
@@ -900,9 +900,8 @@ amp_target_node_create_token (AmpProject *project, AmpTargetNode *target, GErro
}
gboolean
-amp_target_node_delete_token (AmpProject *project, AmpTargetNode *target, gboolean all, GError **error)
+amp_target_node_delete_token (AmpProject *project, AmpTargetNode *target, GList *list, GError **error)
{
- GList *list;
GList *item;
GList *removed_dir = NULL;
AmpGroupNode *parent;
@@ -911,15 +910,7 @@ amp_target_node_delete_token (AmpProject *project, AmpTargetNode *target, gbool
parent = AMP_GROUP_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (target)));
/* Remove all associated token */
- if (all)
- {
- list = amp_target_node_get_all_token (target);
- }
- else
- {
- list = amp_target_node_get_token (target, ANJUTA_TOKEN_ARGUMENT);
- }
- for (item = list; item != NULL; item = g_list_next (item))
+ for (item = list; item != NULL; item = g_list_next (item))
{
AnjutaToken *token = (AnjutaToken *)item->data;
AnjutaTokenStyle *style;
@@ -946,7 +937,7 @@ amp_target_node_delete_token (AmpProject *project, AmpTargetNode *target, gbool
gchar *value;
gint flags;
gchar *install = NULL;
-
+
value = anjuta_token_evaluate (anjuta_token_first_word (variable));
split_automake_variable (value, &flags, &install, NULL);
@@ -988,8 +979,8 @@ amp_target_node_delete_token (AmpProject *project, AmpTargetNode *target, gbool
amp_group_node_update_makefile (parent, token);
break;
};
+ amp_target_node_remove_token (target, token);
}
- if (all) g_list_free (list);
/* Check if we need to remove dir variable */
for (item = removed_dir; item != NULL; item = g_list_next(item))
@@ -1384,7 +1375,7 @@ amp_property_rename_target (AmpProject *project, AnjutaProjectNode *node)
for (item = amp_group_node_get_token (AMP_GROUP_NODE (group), AM_GROUP_TARGET); item != NULL; item = g_list_next (item))
{
existing_target_list = (AnjutaToken *)item->data;
- gchar *target_name = anjuta_token_evaluate (anjuta_token_first_item (existing_target_list));
+ gchar *target_name = anjuta_token_evaluate (anjuta_token_first_word (existing_target_list));
gboolean same;
same = strcmp (target_name, new_name->str) == 0;
@@ -1424,10 +1415,17 @@ amp_property_rename_target (AmpProject *project, AnjutaProjectNode *node)
if (existing_target_list != NULL)
{
- amp_target_node_delete_token (project, AMP_TARGET_NODE (node), FALSE, NULL);
-
+ GList *token_list;
+
+ /* Get old tokens */
+ token_list = g_list_copy (amp_target_node_get_token (AMP_TARGET_NODE (node), ANJUTA_TOKEN_ARGUMENT));
+
/* Add target in already existing list */
amp_target_add_in_list (project, existing_target_list, node, after, NULL);
+
+ /* Remove old token */
+ amp_target_node_delete_token (project, AMP_TARGET_NODE (node), token_list, NULL);
+ g_list_free (token_list);
}
else
{
@@ -1455,10 +1453,9 @@ amp_property_rename_target (AmpProject *project, AnjutaProjectNode *node)
{
AnjutaToken *token;
- token = anjuta_token_new_string (ANJUTA_TOKEN_ARGUMENT | ANJUTA_TOKEN_ADDED, new_name->str);
+ token = anjuta_token_new_string (ANJUTA_TOKEN_ADDED, new_name->str);
update = anjuta_token_insert_word_after (target_variable, old_token, token);
anjuta_token_remove_word (old_token);
- item->data = token;
update = target_variable;
}
}
@@ -1528,6 +1525,15 @@ amp_property_rename_target (AmpProject *project, AnjutaProjectNode *node)
if ((prop->token_type == AM_TOKEN__PROGRAMS) && (((AmpProperty *)prop->base.native)->flags & AM_PROPERTY_DIRECTORY))
{
target_dir = prop->base.value;
+ if ((strlen (target_dir) <= 3) || (strcmp (target_dir + strlen(target_dir) - 3, "dir") != 0))
+ {
+ target_dir = g_strconcat (target_dir, "dir", NULL);
+ if ((prop->base.native != NULL) && (prop->base.value != prop->base.native->value))
+ {
+ g_free (prop->base.value);
+ prop->base.value = target_dir;
+ }
+ }
break;
}
}
@@ -1562,7 +1568,7 @@ amp_property_rename_target (AmpProject *project, AnjutaProjectNode *node)
}
}
- if (target_dir != NULL)
+ if ((update != NULL) && (target_dir != NULL))
{
update = anjuta_token_insert_token_list (FALSE, update,
AM_TOKEN_DIR, NULL,
diff --git a/plugins/am-project/am-writer.h b/plugins/am-project/am-writer.h
index 293aba7..28f1a04 100644
--- a/plugins/am-project/am-writer.h
+++ b/plugins/am-project/am-writer.h
@@ -35,7 +35,7 @@ gboolean amp_group_node_create_token (AmpProject *project, AmpGroupNode *group,
gboolean amp_group_node_delete_token (AmpProject *project, AmpGroupNode *group, GError **error);
gboolean amp_target_node_create_token (AmpProject *project, AmpTargetNode *target, GError **error);
-gboolean amp_target_node_delete_token (AmpProject *project, AmpTargetNode *target, gboolean all, GError **error);
+gboolean amp_target_node_delete_token (AmpProject *project, AmpTargetNode *target, GList *tokens, GError **error);
gboolean amp_source_node_create_token (AmpProject *project, AmpSourceNode *source, GError **error);
gboolean amp_source_node_delete_token (AmpProject *project, AmpSourceNode *source, GError **error);
diff --git a/plugins/am-project/amp-group.c b/plugins/am-project/amp-group.c
index d7d56f0..ec2fbef 100644
--- a/plugins/am-project/amp-group.c
+++ b/plugins/am-project/amp-group.c
@@ -281,6 +281,17 @@ amp_group_node_add_token (AmpGroupNode *group, AnjutaToken *token, AmpGroupNodeT
group->tokens[category] = g_list_prepend (group->tokens[category], token);
}
+void
+amp_group_node_remove_token (AmpGroupNode *group, AnjutaToken *token)
+{
+ gint i;
+
+ for (i = 0; i < AM_GROUP_TOKEN_LAST; i++)
+ {
+ group->tokens[i] = g_list_remove (group->tokens[i], token);
+ }
+}
+
GList *
amp_group_node_get_token (AmpGroupNode *group, AmpGroupNodeTokenCategory category)
{
diff --git a/plugins/am-project/amp-group.h b/plugins/am-project/amp-group.h
index 1f723d3..6b6679c 100644
--- a/plugins/am-project/amp-group.h
+++ b/plugins/am-project/amp-group.h
@@ -63,6 +63,7 @@ AmpVariable* amp_variable_new (gchar *name, AnjutaTokenType assign, AnjutaToken
void amp_group_node_add_token (AmpGroupNode *group, AnjutaToken *token, AmpGroupNodeTokenCategory category);
+void amp_group_node_remove_token (AmpGroupNode *group, AnjutaToken *token);
GList * amp_group_node_get_token (AmpGroupNode *group, AmpGroupNodeTokenCategory category);
GList * amp_group_node_get_all_token (AmpGroupNode *group);
AnjutaToken* amp_group_node_get_first_token (AmpGroupNode *group, AmpGroupNodeTokenCategory category);
diff --git a/plugins/am-project/amp-target.c b/plugins/am-project/amp-target.c
index fab6307..d6795ae 100644
--- a/plugins/am-project/amp-target.c
+++ b/plugins/am-project/amp-target.c
@@ -216,6 +216,20 @@ amp_target_node_add_token (AmpTargetNode *target, AmTokenType type, AnjutaToken
target->tokens = tagged_token_list_insert (target->tokens, type, token);
}
+void
+amp_target_node_remove_token (AmpTargetNode *target, AnjutaToken *token)
+{
+ GList *list;
+
+ g_message ("amp_target_node_remove_token token %p", token);
+ for (list = target->tokens; list != NULL; list = g_list_next (list))
+ {
+ TaggedTokenItem *tagged = (TaggedTokenItem *)list->data;
+
+ tagged->tokens = g_list_remove (tagged->tokens, token);
+ }
+}
+
GList *
amp_target_node_get_token (AmpTargetNode *target, AmTokenType type)
{
@@ -344,8 +358,11 @@ static gboolean
amp_target_node_erase (AmpNode *target, AmpNode *parent, AmpProject *project, GError **error)
{
gboolean ok;
-
- ok = amp_target_node_delete_token (project, AMP_TARGET_NODE (target), TRUE, error);
+ GList * token_list;
+
+ token_list = amp_target_node_get_all_token (AMP_TARGET_NODE (target));
+ ok = amp_target_node_delete_token (project, AMP_TARGET_NODE (target), token_list, error);
+ g_list_free (token_list);
/* Remove installation directory variable if the removed target was the
* only one using it */
diff --git a/plugins/am-project/amp-target.h b/plugins/am-project/amp-target.h
index 4f83414..644f8ec 100644
--- a/plugins/am-project/amp-target.h
+++ b/plugins/am-project/amp-target.h
@@ -62,6 +62,7 @@ typedef enum _AmpTargetNodeFlag
void amp_target_node_register (GTypeModule *module);
void amp_target_node_add_token (AmpTargetNode *target, AmTokenType type, AnjutaToken *token);
+void amp_target_node_remove_token (AmpTargetNode *target, AnjutaToken *token);
GList * amp_target_node_get_token (AmpTargetNode *target, AmTokenType type);
GList * amp_target_node_get_all_token (AmpTargetNode *target);
void amp_target_node_set_type (AmpTargetNode *target, AmTokenType type);
diff --git a/plugins/am-project/tests/properties.at b/plugins/am-project/tests/properties.at
index 8320808..735083b 100644
--- a/plugins/am-project/tests/properties.at
+++ b/plugins/am-project/tests/properties.at
@@ -666,4 +666,52 @@ AT_CHECK([diff -b output expect])
+AT_DATA([expect],
+[[ GROUP (): empty18
+ PROPERTY (Installation directories): plugindir =
+ TARGET (): target1
+ PROPERTY (Installation directory): bindir
+ PROPERTY (Libraries): $(GDL_LIBS)
+ SOURCE (): source2
+ TARGET (): target2
+ PROPERTY (Installation directory): bindir
+ PROPERTY (Libraries): $(GDL_LIBS)
+ SOURCE (): source1
+ TARGET (): library1.la
+ PROPERTY (Installation directory): plugindir
+ PROPERTY (Build for check only): true
+ PROPERTY (Libraries): $(GDL_LIBS)
+]])
+AT_DATA([reference.am],
+[[
+bin_PROGRAMS = target1 \
+ target2
+
+target1_SOURCES = \
+ source2
+
+target1_LDADD = $(GDL_LIBS)
+
+target2_SOURCES = \
+ source1
+
+target2_LDADD = $(GDL_LIBS)
+
+plugindir =
+check_plugin_LTLIBRARIES = \
+ library1.la
+
+library1_la_LIBADD = $(GDL_LIBS)
+]])
+AT_PARSER_CHECK([load empty17 \
+ move empty18 \
+ set 0:2 check 1 \
+ set 0:2 instdir 'plugin' \
+ list \
+ save])
+AT_CHECK([diff -b empty18/Makefile.am reference.am])
+AT_PARSER_CHECK([load empty18 \
+ list])
+AT_CHECK([diff -b output expect])
+
AT_CLEANUP
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]