[anjuta/newproject] Improve source test and fix when _SOURCES variable is already here



commit d05064091c5c77bb15b8a6468ce49f0b0e422eae
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Tue Oct 12 22:49:27 2010 +0200

    Improve source test and fix when _SOURCES variable is already here

 plugins/am-project/am-node.c            |   11 ++--
 plugins/am-project/am-node.h            |    5 +-
 plugins/am-project/am-project-private.h |    8 ++-
 plugins/am-project/am-project.c         |   27 ++-------
 plugins/am-project/am-writer.c          |   26 +++++++--
 plugins/am-project/tests/source.at      |   96 +++++++++++++++++++++++++++++++
 plugins/am-project/tests/target.at      |   12 ++++
 7 files changed, 152 insertions(+), 33 deletions(-)
---
diff --git a/plugins/am-project/am-node.c b/plugins/am-project/am-node.c
index c97e89e..ba3b116 100644
--- a/plugins/am-project/am-node.c
+++ b/plugins/am-project/am-node.c
@@ -602,17 +602,18 @@ anjuta_am_group_node_class_init (AnjutaAmGroupNodeClass *klass)
 
 
 void
-amp_target_add_token (AnjutaAmTargetNode *target, AnjutaToken *token)
+amp_target_add_token (AnjutaAmTargetNode *target, AnjutaToken *token, AmpTargetTokenCategory category)
 {
-	target->tokens = g_list_prepend (target->tokens, token);
+	target->tokens[category] = g_list_prepend (target->tokens[category], token);
 }
 
 GList *
-amp_target_get_token (AnjutaAmTargetNode *node)
+amp_target_get_token (AnjutaAmTargetNode *node, AmpTargetTokenCategory category)
 {
-	return node->tokens;
+	return node->tokens[category];
 }
 
+
 AnjutaAmTargetNode*
 amp_target_new (const gchar *name, AnjutaProjectNodeType type, const gchar *install, gint flags, GError **error)
 {
@@ -670,7 +671,7 @@ amp_target_new (const gchar *name, AnjutaProjectNodeType type, const gchar *inst
 						ANJUTA_PROJECT_CAN_REMOVE;
 	node->install = g_strdup (install);
 	node->flags = flags;
-	node->tokens = NULL;
+	memset (node->tokens, 0, sizeof (node->tokens));
 	
 	return node;
 }
diff --git a/plugins/am-project/am-node.h b/plugins/am-project/am-node.h
index 5b6c17e..3acdcb6 100644
--- a/plugins/am-project/am-node.h
+++ b/plugins/am-project/am-node.h
@@ -78,8 +78,9 @@ typedef enum _AmpTargetFlag
 	AM_TARGET_MAN_SECTION = 31 << 7
 } AmpTargetFlag;
 
-void amp_target_add_token (AnjutaAmTargetNode *node, AnjutaToken *token);
-GList * amp_target_get_token (AnjutaAmTargetNode *node);
+
+void amp_target_add_token (AnjutaAmTargetNode *group, AnjutaToken *token, AmpTargetTokenCategory category);
+GList * amp_target_get_token (AnjutaAmTargetNode *group, AmpTargetTokenCategory category);
 AnjutaAmTargetNode* amp_target_new (const gchar *name, AnjutaProjectNodeType type, const gchar *install, gint flags, GError **error);
 void amp_target_free (AnjutaAmTargetNode *node);
 
diff --git a/plugins/am-project/am-project-private.h b/plugins/am-project/am-project-private.h
index f520f46..1d78e8f 100644
--- a/plugins/am-project/am-project-private.h
+++ b/plugins/am-project/am-project-private.h
@@ -145,11 +145,17 @@ struct _AnjutaAmGroupNode {
 
 GType anjuta_am_target_node_get_type (void) G_GNUC_CONST;
 
+typedef enum {
+	AM_TARGET_TOKEN_TARGET,
+	AM_TARGET_TOKEN_SOURCES,
+	AM_TARGET_TOKEN_LAST
+} AmpTargetTokenCategory;
+
 struct _AnjutaAmTargetNode {
 	AnjutaProjectNode base;
 	gchar *install;
 	gint flags;
-	GList* tokens;	
+	GList* tokens[AM_TARGET_TOKEN_LAST];	
 };
 
 
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index bca8337..b93d9a4 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -997,7 +997,7 @@ project_load_target (AmpProject *project, AnjutaToken *name, AnjutaTokenType tok
 		//fprintf(stderr, "create target %p\n", target);
 		if (target != NULL)
 		{
-			amp_target_add_token (target, arg);
+			amp_target_add_token (target, arg, AM_TARGET_TOKEN_TARGET);
 			anjuta_project_node_append (parent, target);
 			DEBUG_PRINT ("create target %p name %s", target, value);
 
@@ -1101,7 +1101,11 @@ project_load_sources (AmpProject *project, AnjutaToken *name, AnjutaToken *list,
 				orphan = amp_target_property_buffer_new ();
 			}
 		}
-
+		else
+		{
+			amp_target_add_token (parent, name, AM_TARGET_TOKEN_SOURCES);
+		}
+		
 		for (arg = anjuta_token_first_word (list); arg != NULL; arg = anjuta_token_next_word (arg))
 		{
 			gchar *value;
@@ -1186,7 +1190,7 @@ project_load_data (AmpProject *project, AnjutaToken *name, AnjutaToken *list, An
 	{
 		/* Create target */
 		target = amp_target_new (target_id, info->base.type, install, flags, NULL);
-		amp_target_add_token (target, arg);
+		amp_target_add_token (target, arg, AM_TARGET_TOKEN_TARGET);
 		anjuta_project_node_append (parent, target);
 		DEBUG_PRINT ("create target %p name %s", target, target_id);
 	}
@@ -1823,23 +1827,6 @@ amp_project_remove_group (AmpProject  *project,
 }
 
 void 
-amp_project_remove_target (AmpProject  *project,
-		    AnjutaAmTargetNode *target,
-		    GError     **error)
-{
-	GList *token_list;
-
-	if (anjuta_project_node_get_node_type (target) != ANJUTA_PROJECT_TARGET) return;
-	
-	for (token_list = amp_target_get_token (target); token_list != NULL; token_list = g_list_next (token_list))
-	{
-		anjuta_token_remove_word ((AnjutaToken *)token_list->data);
-	}
-
-	amp_target_free (target);
-}
-
-void 
 amp_project_remove_source (AmpProject  *project,
 		    AnjutaAmSourceNode *source,
 		    GError     **error)
diff --git a/plugins/am-project/am-writer.c b/plugins/am-project/am-writer.c
index ed56d3f..1c99adb 100644
--- a/plugins/am-project/am-writer.c
+++ b/plugins/am-project/am-writer.c
@@ -467,7 +467,7 @@ amp_target_create_token (AmpProject  *project, AnjutaAmTargetNode *target, GErro
 	prev = NULL;
 	if (sibling != NULL)
 	{
-		last = amp_target_get_token (sibling);
+		last = amp_target_get_token (sibling, AM_TARGET_TOKEN_TARGET);
 
 		if (last != NULL) 
 		{
@@ -548,7 +548,7 @@ amp_target_create_token (AmpProject  *project, AnjutaAmTargetNode *target, GErro
 		
 		amp_group_update_makefile (parent, token);
 		
-		amp_target_add_token (target, token);
+		amp_target_add_token (target, token, AM_TARGET_TOKEN_TARGET);
 	}
 	g_free (name);
 
@@ -564,7 +564,7 @@ amp_target_delete_token (AmpProject  *project, AnjutaAmTargetNode *target, GErro
 	/* Get parent target */
 	parent = ANJUTA_AM_GROUP_NODE (anjuta_project_node_parent (ANJUTA_PROJECT_NODE (target)));
 
-	for (item = amp_target_get_token (target); item != NULL; item = g_list_next (item))
+	for (item = amp_target_get_token (target, AM_TARGET_TOKEN_TARGET); item != NULL; item = g_list_next (item))
 	{
 		AnjutaToken *token = (AnjutaToken *)item->data;
 		AnjutaToken *args;
@@ -627,13 +627,18 @@ amp_project_write_source_list (AnjutaAmGroupNode *group, const gchar *name, gboo
 		}
 	}
 	
+	pos = anjuta_token_insert_token_list (after, pos,
+		    ANJUTA_TOKEN_EOL, "\n",
+		    NULL);
+	amp_group_update_makefile (group, pos);
+	
 	token = anjuta_token_insert_token_list (after, pos,
 	    		ANJUTA_TOKEN_LIST, NULL,
 	    		ANJUTA_TOKEN_NAME, name,
 	    		ANJUTA_TOKEN_SPACE, " ",
 	    		ANJUTA_TOKEN_OPERATOR, "=",
 	    		ANJUTA_TOKEN_LIST, NULL,
-	    		ANJUTA_TOKEN_START, NULL,
+	            ANJUTA_TOKEN_SPACE, " ",
 	    		NULL);
 
 	return anjuta_token_last_item (token);
@@ -680,6 +685,17 @@ amp_source_create_token (AmpProject  *project, AnjutaAmSourceNode *source, GErro
 		prev = NULL;
 		args = NULL;
 	}
+
+	/* Check if a valid source variable is already defined */
+	if (args == NULL)
+	{
+		GList *last;
+		for (last = amp_target_get_token (target, AM_TARGET_TOKEN_SOURCES); last != NULL; last = g_list_next (last))
+		{
+			args = anjuta_token_last_item (anjuta_token_list ((AnjutaToken *)last->data));
+			break;
+		}
+	}
 	
 	if (args == NULL)
 	{
@@ -693,7 +709,7 @@ amp_source_create_token (AmpProject  *project, AnjutaAmSourceNode *source, GErro
 
 		/* Search where the target is declared */
 		var = NULL;
-		list = amp_target_get_token (target);
+		list = amp_target_get_token (target, AM_TARGET_TOKEN_TARGET);
 		if (list != NULL)
 		{
 			var = (AnjutaToken *)list->data;
diff --git a/plugins/am-project/tests/source.at b/plugins/am-project/tests/source.at
index ac8f10c..6d012ec 100644
--- a/plugins/am-project/tests/source.at
+++ b/plugins/am-project/tests/source.at
@@ -7,33 +7,129 @@ AT_DATA([empty/Makefile.am],
 [[
 bin_PROGRAMS = target1
 ]])
+
+
+
 AT_DATA([expect],
 [[    GROUP (0): empty1
         TARGET (0:0): target1
           SOURCE (0:0:0): source1
 ]])
+AT_DATA([reference],
+[[
+bin_PROGRAMS = target1
+
+target1_SOURCES = source1
+]])
 AT_PARSER_CHECK([load empty \
 		 move empty1 \
 		 add source 0:0 source1 \
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty1/Makefile.am reference])
 AT_PARSER_CHECK([load empty1 \
 		 list])
 AT_CHECK([diff -b output expect])
+
+
+
 AT_DATA([expect],
 [[    GROUP (0): empty2
         TARGET (0:0): target1
           SOURCE (0:0:0): source1
           SOURCE (0:0:1): source2
 ]])
+AT_DATA([reference],
+[[
+bin_PROGRAMS = target1
+
+target1_SOURCES = source1 \
+	source2
+]])
 AT_PARSER_CHECK([load empty1 \
 		 move empty2 \
 		 add source 0:0 source2 after 0:0:0\
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty2/Makefile.am reference])
 AT_PARSER_CHECK([load empty2 \
 		 list])
 AT_CHECK([diff -b output expect])
+
+
+
+AT_DATA([expect],
+[[    GROUP (0): empty3
+        TARGET (0:0): target1
+          SOURCE (0:0:0): source2
+]])
+AT_DATA([reference],
+[[
+bin_PROGRAMS = target1
+
+target1_SOURCES =	source2
+]])
+AT_PARSER_CHECK([load empty2 \
+		 move empty3 \
+		remove 0:0:0\
+		 list \
+		 save])
+AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty3/Makefile.am reference])
+AT_PARSER_CHECK([load empty3 \
+		 list])
+AT_CHECK([diff -b output expect])
+
+
+
+
+AT_DATA([expect],
+[[    GROUP (0): empty4
+        TARGET (0:0): target1
+]])
+AT_DATA([reference],
+[[
+bin_PROGRAMS = target1
+
+target1_SOURCES =
+]])
+AT_PARSER_CHECK([load empty3 \
+		 move empty4 \
+		remove 0:0:0\
+		 list \
+		 save])
+AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty4/Makefile.am reference])
+AT_PARSER_CHECK([load empty4 \
+		 list])
+AT_CHECK([diff -b output expect])
+
+
+
+AT_DATA([expect],
+[[    GROUP (0): empty5
+        TARGET (0:0): target1
+          SOURCE (0:0:0): source1
+]])
+AT_DATA([reference],
+[[
+bin_PROGRAMS = target1
+
+target1_SOURCES = source1
+]])
+AT_PARSER_CHECK([load empty4 \
+		 move empty5 \
+		 add source 0:0 source1 \
+		 list \
+		 save])
+AT_CHECK([diff -b output expect])
+AT_CHECK([diff -b empty5/Makefile.am reference])
+AT_PARSER_CHECK([load empty5 \
+		 list])
+AT_CHECK([diff -b output expect])
+
+
+
 AT_CLEANUP
diff --git a/plugins/am-project/tests/target.at b/plugins/am-project/tests/target.at
index ee56652..3bd9dd8 100644
--- a/plugins/am-project/tests/target.at
+++ b/plugins/am-project/tests/target.at
@@ -6,6 +6,8 @@ AT_DATA([empty/configure.ac],
 AT_DATA([empty/Makefile.am],
 [[]])
 
+
+
 AT_DATA([expect],
 [[    GROUP (0): empty1
         TARGET (0:0): target1
@@ -26,6 +28,8 @@ AT_PARSER_CHECK([load empty1 \
 		 list])
 AT_CHECK([diff output expect])
 
+
+
 AT_DATA([expect],
 [[    GROUP (0): empty2
         TARGET (0:0): target1
@@ -48,6 +52,8 @@ AT_PARSER_CHECK([load empty2 \
 		 list])
 AT_CHECK([diff -b output expect])
 
+
+
 AT_DATA([expect],
 [[    GROUP (0): empty3
         TARGET (0:0): target2
@@ -68,6 +74,8 @@ AT_PARSER_CHECK([load empty3 \
 		 list])
 AT_CHECK([diff -b output expect])
 
+
+
 AT_DATA([expect],
 [[    GROUP (0): empty4
 ]])
@@ -87,6 +95,8 @@ AT_PARSER_CHECK([load empty4 \
 		 list])
 AT_CHECK([diff -b output expect])
 
+
+
 AT_DATA([expect],
 [[    GROUP (0): empty5
         TARGET (0:0): target1
@@ -107,4 +117,6 @@ AT_PARSER_CHECK([load empty5 \
 		 list])
 AT_CHECK([diff -b output expect])
 
+
+
 AT_CLEANUP



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