[anjuta/newproject] List properties in a general way, add a property test (not working)



commit fe42ff5cb7f8ea616dd92d17bfbdb43c9bbff7d7
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Thu Oct 14 19:57:40 2010 +0200

    List properties in a general way, add a property test (not working)

 plugins/am-project/am-parser.y         |    4 +
 plugins/am-project/am-properties.c     |    2 +
 plugins/am-project/am-scanner.h        |    2 +
 plugins/am-project/am-scanner.l        |    4 +
 plugins/am-project/projectparser.c     |  126 +++++++++++++++++++++-----------
 plugins/am-project/tests/Makefile.am   |    3 +-
 plugins/am-project/tests/acinit.at     |   22 +++---
 plugins/am-project/tests/anjuta.lst    |    6 +-
 plugins/am-project/tests/properties.at |   36 +++++++++
 plugins/am-project/tests/testsuite.at  |    1 +
 10 files changed, 149 insertions(+), 57 deletions(-)
---
diff --git a/plugins/am-project/am-parser.y b/plugins/am-project/am-parser.y
index 4d4bba8..a7332a9 100644
--- a/plugins/am-project/am-parser.y
+++ b/plugins/am-project/am-parser.y
@@ -86,6 +86,8 @@
 %token  TARGET_LFLAGS
 %token  TARGET_YFLAGS
 %token  TARGET_DEPENDENCIES
+%token  TARGET_LIBADD
+%token  TARGET_LDADD
 
 
 %defines
@@ -554,6 +556,8 @@ automake_token:
 	|  TARGET_LFLAGS
 	|  TARGET_YFLAGS
 	|  TARGET_DEPENDENCIES
+	|  TARGET_LIBADD
+	|  TARGET_LDADD
 	;
 
 include_token:
diff --git a/plugins/am-project/am-properties.c b/plugins/am-project/am-properties.c
index 272da29..0955279 100644
--- a/plugins/am-project/am-properties.c
+++ b/plugins/am-project/am-properties.c
@@ -72,6 +72,8 @@ static AmpProperty AmpTargetProperties[] = {
 	{{N_("Do not install:"), ANJUTA_PROJECT_PROPERTY_BOOLEAN, NULL, NULL}, AM_TOKEN__PROGRAMS, 3, NULL},
 	{{N_("Installation directory:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, AM_TOKEN__PROGRAMS, 6, NULL},
 	{{N_("Linker flags:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, AM_TOKEN_TARGET_LDFLAGS, 0, NULL},
+	{{N_("Additional libraries:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, AM_TOKEN_TARGET_LIBADD, 0, NULL},
+	{{N_("Additional objects:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, AM_TOKEN_TARGET_LDADD, 0, NULL},
 	{{N_("C preprocessor flags:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, AM_TOKEN_TARGET_CPPFLAGS, 0, NULL},
 	{{N_("C compiler flags:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, AM_TOKEN_TARGET_CFLAGS, 0, NULL},
 	{{N_("C++ compiler flags:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, AM_TOKEN_TARGET_CXXFLAGS, 0, NULL},
diff --git a/plugins/am-project/am-scanner.h b/plugins/am-project/am-scanner.h
index 5eec6e4..0fecfe4 100644
--- a/plugins/am-project/am-scanner.h
+++ b/plugins/am-project/am-scanner.h
@@ -84,6 +84,8 @@ typedef enum
 	AM_TOKEN_TARGET_LFLAGS,
 	AM_TOKEN_TARGET_YFLAGS,
 	AM_TOKEN_TARGET_DEPENDENCIES,
+	AM_TOKEN_TARGET_LIBADD,
+	AM_TOKEN_TARGET_LDADD
 } AmTokenType;
 
 G_END_DECLS
diff --git a/plugins/am-project/am-scanner.l b/plugins/am-project/am-scanner.l
index a871d96..055c3e2 100644
--- a/plugins/am-project/am-scanner.l
+++ b/plugins/am-project/am-scanner.l
@@ -194,6 +194,10 @@ NAME          [^ \t\n\r:#=$"'`&@\\]*
 
 <INITIAL>{NAME}_DEPENDENCIES		{ RETURN (TARGET_DEPENDENCIES);}
 
+<INITIAL>{NAME}_LDADD				{ RETURN (TARGET_LDADD);}
+
+<INITIAL>{NAME}_LIBADD				{ RETURN (TARGET_LIBADD);}
+
 <INITIAL>{NAME} 					{ RETURN (NAME); }
 
 <INITIAL>. 							{ RETURN (CHARACTER); }
diff --git a/plugins/am-project/projectparser.c b/plugins/am-project/projectparser.c
index 73e5d7b..1fee521 100644
--- a/plugins/am-project/projectparser.c
+++ b/plugins/am-project/projectparser.c
@@ -71,6 +71,69 @@ print (const gchar *message, ...)
 static void list_children (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode *parent, gint indent, const gchar *path);
 
 static void
+list_property (IAnjutaProject *project, AnjutaProjectNode *parent, gint indent)
+{
+	GList *item;
+	GString *value;
+
+	value = g_string_new (NULL);
+	
+	for (item = anjuta_project_node_get_custom_properties (parent); item != NULL; item = g_list_next (item))
+	{
+		AnjutaProjectProperty *prop;
+		AnjutaProjectProperty *native;
+		GList *list;
+
+		prop = (AnjutaProjectProperty *)item->data;
+		native = prop->native;
+
+		switch (prop->type)
+		{
+		case ANJUTA_PROJECT_PROPERTY_STRING:
+				g_string_assign (value, prop->value == NULL ? "" : prop->value);
+				break;
+		case ANJUTA_PROJECT_PROPERTY_BOOLEAN:
+				g_string_assign (value, (prop->value != NULL) && (*prop->value == '1') ? "true" : "false");
+				break;
+		case ANJUTA_PROJECT_PROPERTY_LIST:
+				g_string_assign (value, "");
+				for (list = anjuta_project_node_get_custom_properties (parent); list != NULL; list = g_list_next (list))
+				{
+					AnjutaProjectProperty *list_prop = (AnjutaProjectProperty *)list->data;
+
+					if (list_prop->native == native)
+					{
+						if ((value->len == 0) && (list_prop != prop))
+						{
+							/* This list has already been displayed */
+							break;
+						}
+
+						if (value->len != 0) g_string_append_c (value, ' ');
+						g_string_append_printf (value, "%s = %s", list_prop->name == NULL ? "?" : list_prop->name, list_prop->value == NULL ? "" : list_prop->value);
+					}
+				}
+				break;
+		}
+
+		if (value->len != 0)
+		{
+			gchar *name;
+			
+			name = g_strdup (native->name);
+			if (*(name + strlen (name) - 1) == ':')
+			{
+				*(name + strlen (name) - 1) = '\0';
+			}
+			print ("%*sPROPERTY (%s): %s", indent * INDENT, "", name, value->str);
+			g_free (name);
+		}
+	}
+
+	g_string_free (value, TRUE);
+}
+
+static void
 list_source (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode *source, gint indent, const gchar *path)
 {
 	GFile *file;
@@ -81,6 +144,9 @@ list_source (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode
 	file = anjuta_project_node_get_file (source);
 	rel_path = g_file_get_relative_path (anjuta_project_node_get_file (root), file);
 	print ("%*sSOURCE (%s): %s", indent * INDENT, "", path, rel_path);
+	
+	list_property (project, source, indent + 1);
+	
 	g_free (rel_path);
 }
 
@@ -89,6 +155,8 @@ list_target (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode
 {
 	print ("%*sTARGET (%s): %s", indent * INDENT, "", path, anjuta_project_node_get_name (target)); 
 
+	list_property (project, target, indent + 1);
+
 	list_children (project, root, target, indent, path);
 }
 
@@ -116,6 +184,8 @@ list_group (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode
 	print ("%*sGROUP (%s): %s", indent * INDENT, "", path, rel_path);
 	g_free (rel_path);
 
+	list_property (project, group, indent + 1);
+	
 	list_children (project, root, group, indent, path);
 }
 
@@ -123,6 +193,7 @@ static void
 list_package (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode *package, gint indent, const gchar *path)
 {
 	print ("%*sPACKAGE (%s): %s", indent * INDENT, "", path, anjuta_project_node_get_name (package)); 
+	list_property (project, package, indent + 1);
 }
 
 static void
@@ -130,46 +201,12 @@ list_module (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode
 {
 	print ("%*sMODULE (%s): %s", indent * INDENT, "", path, anjuta_project_node_get_name (module));
 
+	list_property (project, module, indent + 1);
+	
 	list_children (project, root, module, indent, path);
 }
 
 static void
-list_property (IAnjutaProject *project, AnjutaProjectNode *parent, gint indent)
-{
-	GList *item;
-
-	for (item = anjuta_project_node_get_custom_properties (parent); item != NULL; item = g_list_next (item))
-	{
-		AnjutaProjectProperty *prop;
-		const gchar *msg = NULL;
-
-		prop = (AnjutaProjectProperty *)item->data;
-		if (strcmp (prop->name, "Name:") == 0)
-		{
-			msg = "%*sNAME: %s";
-		}
-		else if (strcmp (prop->name, "Version:") == 0)
-		{
-			msg = "%*sVERSION: %s";
-		}
-		else if (strcmp (prop->name, "Bug report URL:") == 0)
-		{
-			msg = "%*sBUG_REPORT: %s";
-		}
-		else if (strcmp (prop->name, "Package name:") == 0)
-		{
-			msg = "%*sTARNAME: %s";
-		}
-		else if (strcmp (prop->name, "URL:") == 0)
-		{
-			msg = "%*sURL: %s";
-		}
-
-		if (msg && (prop->value != NULL)) print (msg, (indent + 1) * INDENT, "", prop->value);
-	}
-}
-
-static void
 list_children (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode *parent, gint indent, const gchar *path)
 {
 	AnjutaProjectNode *node;
@@ -262,6 +299,11 @@ get_node (IAnjutaProject *project, AnjutaProjectNode *root, const char *path)
 			gchar *end;
 			guint child = g_ascii_strtoull (path, &end, 10);
 
+			/* Check if the number is valid.
+			 * Use an invalid number to get the root node
+			 */
+			if (path == end) break;
+
 			if (end == path)
 			{
 				/* error */
@@ -321,7 +363,7 @@ get_target_type (IAnjutaProject *project, const char *id)
 }
 
 static AnjutaProjectProperty *
-get_project_property (AmpProject *project, AnjutaProjectNode *parent, const gchar *id)
+get_project_property (IAnjutaProject *project, AnjutaProjectNode *parent, const gchar *id)
 {
 	GList *item;
 	AnjutaProjectProperty *prop = NULL;
@@ -420,7 +462,7 @@ main(int argc, char *argv[])
 				}
 				else
 				{
-					project = amp_project_new (file, NULL);
+					project = IANJUTA_PROJECT (amp_project_new (file, NULL));
 				}
 			}
 
@@ -456,7 +498,6 @@ main(int argc, char *argv[])
 		else if (g_ascii_strcasecmp (command[0], "add") == 0)
 		{
 			node = get_node (project, root, command[2]);
-			g_message ("get parent node %p node name %s", anjuta_project_node_get_name (node));
 			if (g_ascii_strcasecmp (command[1], "group") == 0)
 			{
 				if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
@@ -532,13 +573,14 @@ main(int argc, char *argv[])
 			{
 				AnjutaProjectProperty *item;
 
-				item = get_project_property (project, root, command[1]);
+				node = get_node (project, root, command[1]);
+				item = get_project_property (project, node, command[2]);
 				if (item != NULL)
 				{
-					ianjuta_project_set_property (project, root, item, command[2], NULL);
+					ianjuta_project_set_property (project, node, item, command[3], NULL);
 				}
 			}
-			command += 2;
+			command += 3;
 		}
 		else
 		{
diff --git a/plugins/am-project/tests/Makefile.am b/plugins/am-project/tests/Makefile.am
index 680d4dd..3a55788 100644
--- a/plugins/am-project/tests/Makefile.am
+++ b/plugins/am-project/tests/Makefile.am
@@ -23,7 +23,8 @@ TESTSUITE_AT = \
 	$(srcdir)/parser.at \
 	$(srcdir)/acinit.at \
 	$(srcdir)/include.at \
-	$(srcdir)/variable.at
+	$(srcdir)/variable.at \
+	$(srcdir)/properties.at
 
 TESTSUITE = $(srcdir)/testsuite
 
diff --git a/plugins/am-project/tests/acinit.at b/plugins/am-project/tests/acinit.at
index f4de7eb..17fd03d 100644
--- a/plugins/am-project/tests/acinit.at
+++ b/plugins/am-project/tests/acinit.at
@@ -7,11 +7,11 @@ AT_DATA([empty/Makefile.am],
 [[
 ]])
 AT_DATA([expect],
-[[    NAME: empty
+[[PROPERTY (Name): empty
     GROUP (0): empty
 ]])
 AT_PARSER_CHECK([load empty \
-		 set name empty \
+		 set : name empty \
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
@@ -19,11 +19,11 @@ AT_PARSER_CHECK([load empty \
 		list])
 AT_CHECK([diff -b output expect])
 AT_DATA([expect],
-[[    NAME: empty2
+[[PROPERTY (Name): empty2
     GROUP (0): empty
 ]])
 AT_PARSER_CHECK([load empty \
-		 set name empty2 \
+		 set : name empty2 \
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
@@ -31,12 +31,12 @@ AT_PARSER_CHECK([load empty \
 		list])
 AT_CHECK([diff -b output expect])
 AT_DATA([expect],
-[[    NAME: empty2
-    VERSION: 0.1
+[[PROPERTY (Name): empty2
+PROPERTY (Version): 0.1
     GROUP (0): empty
 ]])
 AT_PARSER_CHECK([load empty \
-		 set version 0.1 \
+		 set : version 0.1 \
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
@@ -44,13 +44,13 @@ AT_PARSER_CHECK([load empty \
 		list])
 AT_CHECK([diff -b output expect])
 AT_DATA([expect],
-[[    NAME: empty2
-    VERSION: 0.1
-    TARNAME: empty3
+[[PROPERTY (Name): empty2
+PROPERTY (Version): 0.1
+PROPERTY (Package name): empty3
     GROUP (0): empty
 ]])
 AT_PARSER_CHECK([load empty \
-		 set pack empty3 \
+		 set : pack empty3 \
 		 list \
 		 save])
 AT_CHECK([diff -b output expect])
diff --git a/plugins/am-project/tests/anjuta.lst b/plugins/am-project/tests/anjuta.lst
index b39af2c..914644e 100644
--- a/plugins/am-project/tests/anjuta.lst
+++ b/plugins/am-project/tests/anjuta.lst
@@ -1,6 +1,6 @@
-    NAME: anjuta
-    VERSION: anjuta_version
-    BUG_REPORT: http://bugzilla.gnome.org/enter_bug.cgi?product=anjuta
+PROPERTY (Name): anjuta
+PROPERTY (Version): anjuta_version
+PROPERTY (Bug report URL): http://bugzilla.gnome.org/enter_bug.cgi?product=anjuta
     MODULE (0): [ANJUTA]
         PACKAGE (0:0): gthread-2.0
         PACKAGE (0:1): unique-1.0
diff --git a/plugins/am-project/tests/properties.at b/plugins/am-project/tests/properties.at
new file mode 100644
index 0000000..6bf1305
--- /dev/null
+++ b/plugins/am-project/tests/properties.at
@@ -0,0 +1,36 @@
+AT_SETUP([Set node properties])
+AS_MKDIR_P([empty])
+AT_DATA([empty/configure.ac],
+[[AC_CONFIG_FILES(Makefile)
+]])
+AT_DATA([empty/Makefile.am],
+[[
+bin_PROGRAMS = target1
+]])
+
+
+
+AT_DATA([expect],
+[[    GROUP (0): empty1
+        TARGET (0:0): target1
+]])
+AT_DATA([reference.am],
+[[
+bin_PROGRAMS = target1
+
+target1_LIBADD = \
+	$(GDL_LIBS)
+]])
+AT_PARSER_CHECK([load empty \
+		move empty1 \
+		set 0:0 addlib '$(GDL_LIBS)' \
+		list \
+		save])
+AT_CHECK([diff output expect])
+AT_CHECK([diff -b empty1/Makefile.am reference.am])
+AT_PARSER_CHECK([load empty1 \
+		 list])
+AT_CHECK([diff output expect])
+
+
+AT_CLEANUP
diff --git a/plugins/am-project/tests/testsuite.at b/plugins/am-project/tests/testsuite.at
index adb7430..cda7dc2 100644
--- a/plugins/am-project/tests/testsuite.at
+++ b/plugins/am-project/tests/testsuite.at
@@ -7,3 +7,4 @@ m4_include([parser.at])
 m4_include([acinit.at])
 m4_include([include.at])
 m4_include([variable.at])
+m4_include([properties.at])



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