[gxml] Improved build system



commit 22a890d512597f8dad4431e396db9e4414a15416
Author: Daniel Espinosa <esodan gmail com>
Date:   Tue Feb 9 17:45:17 2016 -0600

    Improved build system
    
    * Improved use of stamps to build, speeding up builds
    * Removed some warnings

 configure.ac                           |    2 +-
 gxml/Makefile.am                       |   24 ++++++++-
 gxml/SerializableGeeHashMap.vala       |    2 +-
 gxml/TwDocument.vala                   |    1 -
 gxml/libxml-Document.vala              |   88 --------------------------------
 test/EnumerationTest.vala              |   36 ++++---------
 test/GDocumentTest.vala                |   47 ++++++++++++-----
 test/Makefile.am                       |   31 +++++++++---
 test/SerializableGeeArrayListTest.vala |    8 ++--
 test/SerializableGeeHashMapTest.vala   |   14 +++---
 10 files changed, 105 insertions(+), 148 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 49dc542..95ee4f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -285,7 +285,7 @@ AM_CONDITIONAL(PLATFORM_WIN32, [test x$platform_win32 = xyes])
 AC_CONFIG_FILES([
 Makefile
 gxml/namespace-info.vala
-gxml/gxml-0.6.pc
+gxml/gxml-0.10.pc
 gxml/Makefile
 test/Makefile
 test/test.xml
diff --git a/gxml/Makefile.am b/gxml/Makefile.am
index b02b3c0..831036d 100644
--- a/gxml/Makefile.am
+++ b/gxml/Makefile.am
@@ -156,8 +156,29 @@ libgxml_0_10_la_LIBADD = \
 libgxml_0_10_la_LDFLAGS = \
        -version-info "$(LT_CURRENT)":"$(LT_REVISION)":"$(LT_AGE)"
 
-$(sources:.vala=.c): $(sources)
+vala-stamp: $(sources)
+       @rm -f vala-temp
+       @touch vala-temp
        $(VALAC) $(AM_VALAFLAGS) $^
+       @mv -f vala-temp $@
+
+$(sources:.vala=.c): vala-stamp
+## Recover from the removal of $@
+       @if test -f $@; then :; else \
+               trap ’rm -rf vala-lock vala-stamp’ 1 2 13 15; \
+               if mkdir vala-lock 2>/dev/null; then \
+## This code is being executed by the first process.
+                       rm -f vala-stamp; \
+                       $(MAKE) $(AM_MAKEFLAGS) vala-stamp; \
+                       rmdir vala-lock; \
+               else \
+## This code is being executed by the follower processes.
+## Wait until the first process is done.
+                       while test -d vala-lock; do sleep 1; done; \
+## Succeed if and only if the first process succeeded.
+                       test -f vala-stamp; exit $$?; \
+               fi; \
+       fi
 
 libgxml_0_10_la_SOURCES= \
   $(sources:.vala=.c) \
@@ -249,6 +270,7 @@ BUILT_SOURCES += \
 endif
 
 CLEANFILES += \
+       vala-stamp \
        $(pkgconfig_DATA) \
        namespace-info.vala \
        $(sources:.vala=.c) \
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/SerializableGeeHashMap.vala
index 952edaf..fd030cd 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/SerializableGeeHashMap.vala
@@ -138,7 +138,7 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
                                                     this.get_type ().name (), value_type.name ());
     }
     if (node is Element) {
-      foreach (GXml.Node n in node.childs) {
+      foreach (GXml.Node n in node.children) {
         if (n is Element) {
 #if DEBUG
           stdout.printf (@"Node $(node.name) for type '$(get_type ().name ())'\n");
diff --git a/gxml/TwDocument.vala b/gxml/TwDocument.vala
index 78b8287..2cd50cd 100644
--- a/gxml/TwDocument.vala
+++ b/gxml/TwDocument.vala
@@ -31,7 +31,6 @@ using Xml;
 public class GXml.TwDocument : GXml.TwNode, GXml.Document
 {
   GXml.Element _root = null;
-  Xml.Buffer _buffer;
   construct {
     _name = "#document";
   }
diff --git a/gxml/libxml-Document.vala b/gxml/libxml-Document.vala
index c84da1c..127fc7b 100644
--- a/gxml/libxml-Document.vala
+++ b/gxml/libxml-Document.vala
@@ -36,16 +36,6 @@
  * GXml provides a DOM Level 1 Core API in a GObject framework.
  */
 namespace GXml {
-       internal struct InputStreamBox {
-               public InputStream str;
-               public Cancellable can;
-       }
-
-       internal struct OutputStreamBox {
-               public OutputStream str;
-               public Cancellable can;
-       }
-
        /**
         * Represents an XML xDocument as a tree of { link GXml.xNode}s.
         *
@@ -316,84 +306,6 @@ namespace GXml {
                        this.from_libxml2 (doc);
                }
 
-               /* For { link GXml.xDocument.save_to_stream}, to write the document in chunks. */
-               internal static int _iowrite (void *ctx, char[] buf, int len) {
-                       // TODO: can we make this private?
-                       OutputStreamBox *box = (OutputStreamBox*)ctx;
-                       OutputStream outstream = box->str;
-                       int bytes_writ = -1;
-
-                       try {
-                               // TODO: want to propagate error, get cancellable
-                               // TODO: handle char[] -> uint8[] better?
-                               bytes_writ = (int)outstream.write ((uint8[])buf, box->can);
-                       } catch (GLib.IOError e) {
-                               // TODO: process
-                               bytes_writ = -1;
-                       }
-
-                       return bytes_writ;
-               }
-
-               /* For { link GXml.xDocument.from_stream}, to read the document in chunks. */
-               internal static int _iooutclose (void *ctx) {
-                       // TODO: can we make this private?
-                       OutputStreamBox *box = (OutputStreamBox*)ctx;
-                       OutputStream outstream = box->str;
-                       int success = -1;
-
-                       try {
-                               // TODO: handle, propagate? error
-                               // TODO: want ctx to include Cancellable
-                               if (outstream.close (box->can)) {
-                                       success = 0;
-                               }
-                       } catch (GLib.Error e) {
-                               // TODO: process
-                               success = -1;
-                       }
-
-                       return success;
-               }
-
-               // TODO: can we make this private?
-               internal static int _ioread (void *ctx, char[] buf, int len) {
-                       InputStreamBox *box = (InputStreamBox*)ctx;
-                       InputStream instream = box->str;
-                       int bytes_read = -1;
-
-                       try {
-                               // TODO: want to propagate error, get cancellable
-                               // TODO: handle char[] -> uint8[] better?
-                               bytes_read = (int)instream.read ((uint8[])buf, box->can);
-                       } catch (GLib.IOError e) {
-                               // TODO: process
-                               bytes_read = -1;
-                       }
-
-                       return bytes_read;
-               }
-
-               // TODO: can we make this private?
-               internal static int _ioinclose (void *ctx) {
-                       InputStreamBox *box = (InputStreamBox*)ctx;
-                       InputStream instream = box->str;
-                       int success = -1;
-
-                       try {
-                               // TODO: handle, propagate? error
-                               // TODO: want ctx to include Cancellable
-                               if (instream.close (box->can)) {
-                                       success = 0;
-                               }
-                       } catch (GLib.Error e) {
-                               // TODO: process
-                               success = -1;
-                       }
-
-                       return success;
-               }
-
                /**
                 * Creates a xDocument for the { link GLib.File} `fin`.
                 *
diff --git a/test/EnumerationTest.vala b/test/EnumerationTest.vala
index 585cc07..93b6bc5 100644
--- a/test/EnumerationTest.vala
+++ b/test/EnumerationTest.vala
@@ -117,33 +117,21 @@ class SerializableEnumerationTest : GXmlTest
                      var options = new Options ();
                      options.options = OptionsEnum.NORMAL_OPERATION;
                      try {
+                       Test.message ("Before serialize...");
                        options.serialize (doc);
-                       if (doc.document_element == null)  {
-                         stdout.printf (@"ERROR: No root node found");
-                         assert_not_reached ();
-                       }
-                       if (doc.document_element.node_name != "options") {
-                         stdout.printf (@"ERROR: bad root name:\n$(doc)");
-                         assert_not_reached ();
-                       }
-                       xElement element = doc.document_element;
-                       var op = element.get_attribute_node ("options");
-                       if (op == null) {
-                         stdout.printf (@"ERROR: attribute options not found:\n$(doc)");
-                         assert_not_reached ();
-                       }
-                       if (op.node_value != "NormalOperation") {
-                         stdout.printf (@"ERROR: attribute options value invalid: $(op.node_value)\n$(doc)");
-                         assert_not_reached ();
-                       }
+                       Test.message ("doc: "+doc.to_string ()+" Root?"+(doc.root != null).to_string ());
+                       assert (doc.root != null);
+                       assert (doc.root.name == "options");
+                       Element element = (Element) doc.root;
+                       var op = element.get_attr ("options");
+                       assert (op != null);
+                       assert (op.value == "NormalOperation");
                        options.options = (OptionsEnum) (-1); // invaliding this property. Avoids serialize 
it.
-                       var doc2 = new xDocument ();
+                       var doc2 = new GDocument ();
+                       assert (doc.root != null);
                        options.serialize (doc2);
-                       var opts = doc2.document_element.get_attribute_node ("options");
-                       if (opts != null) {
-                         stdout.printf (@"ERROR: attribute options must not be present:\n$(doc)");
-                         assert_not_reached ();
-                       }
+                       var opts = (doc2.root as Element).get_attr ("options");
+                       assert (opts == null);
                      }
                      catch (GLib.Error e) {
                        stdout.printf (@"Error: $(e.message)");
diff --git a/test/GDocumentTest.vala b/test/GDocumentTest.vala
index b004b46..d745e4f 100644
--- a/test/GDocumentTest.vala
+++ b/test/GDocumentTest.vala
@@ -90,7 +90,7 @@ class GDocumentTest : GXmlTest {
                                assert (d.root.name == "Project");
                                bool fname, fshordesc, fdescription, fhomepage;
                                fname = fshordesc = fdescription = fhomepage = false;
-                               foreach (GXml.Node n in d.root.childs) {
+                               foreach (GXml.Node n in d.root.children) {
                                        if (n.name == "name") fname = true;
                                        if (n.name == "shortdesc") fshordesc = true;
                                        if (n.name == "description") fdescription = true;
@@ -120,22 +120,24 @@ class GDocumentTest : GXmlTest {
                                        doc = new GDocument.from_stream (iostream.input_stream);
                                        GLib.message ("Passed parse error stream");
                                        assert_not_reached ();
-                               } catch  {}
+                               } catch  { assert_not_reached (); }
                        });
                Test.add_func ("/gxml/gdocument/construct_from_string", () => {
+                       try {
                                string xml;
                                GDocument doc;
                                GXml.Node root;
 
                                xml = "<Fruits><Apple></Apple><Orange></Orange></Fruits>";
                                doc = new GDocument.from_string (xml);
-
+                               assert (doc.root != null);
                                root = doc.root;
                                assert (root.name == "Fruits");
                                assert (root.children.size == 2);
                                var n1 = root.children.get (0);
                                assert (n1 != null);
                                assert (n1.name == "Apple");
+                       } catch { assert_not_reached (); }
                        });
                Test.add_func ("/gxml/gdocument/construct_from_string_no_root", () => {
                        try {
@@ -146,7 +148,7 @@ class GDocumentTest : GXmlTest {
                                xml = """<?xml version="1.0"?>""";
                                doc = new GDocument.from_string (xml);
                                assert_not_reached ();
-                       } catch {}
+                       } catch { assert_not_reached (); }
                        });
                Test.add_func ("/gxml/gdocument/construct_from_string_invalid", () => {
                        try {
@@ -156,7 +158,7 @@ class GDocumentTest : GXmlTest {
 
                                xml = "";
                                doc = new GDocument.from_string (xml);
-                       } catch {}
+                       } catch { assert_not_reached (); }
                        });
                Test.add_func ("/gxml/gdocument/save", () => {
                                GDocument doc;
@@ -180,10 +182,11 @@ class GDocumentTest : GXmlTest {
                                        doc = new GDocument.from_string ("<root />");
                                        doc.save_as (GLib.File.new_for_path ("/tmp/a/b/c/d/e/f/g/h/i"));
                                        assert_not_reached ();
-                               } catch {}
+                               } catch { assert_not_reached (); }
                        });
 
                Test.add_func ("/gxml/gdocument/create_element", () => {
+                       try {
                                GDocument doc = new GDocument.from_string ("<root />");
                                GElement elem = null;
 
@@ -192,29 +195,37 @@ class GDocumentTest : GXmlTest {
                                assert (elem.tag_name != "banana");
 
                                elem = (GElement) doc.create_element ("ØÏØÏدÏØÏ  ²øœ³¤ïØ£");
-                       });
+                       } catch { assert_not_reached (); }
+               });
                Test.add_func ("/gxml/gdocument/create_text_node", () => {
+                       try {
                                GDocument doc = new GDocument.from_string ("<root />");
                                Text text = (Text) doc.create_text ("Star of my dreams");
 
                                assert (text.name == "#text");
                                assert (text.value == "Star of my dreams");
-                       });
+                       } catch { assert_not_reached (); }
+               });
                Test.add_func ("/gxml/gdocument/create_comment", () => {
+                       try {
                                GDocument doc = new GDocument.from_string ("<root />");
                                Comment comment = (GXml.Comment) doc.create_comment ("Ever since the day we 
promised.");
 
                                assert (comment.name == "#comment");
                                assert (comment.str == "Ever since the day we promised.");
-                       });
+                       } catch { assert_not_reached (); }
+               });
                Test.add_func ("/gxml/gdocument/create_cdata_section", () => {
+                       try {
                                GDocument doc = new GDocument.from_string ("<root />");
                                CDATA cdata = (CDATA) doc.create_cdata ("put in real cdata");
 
                                assert (cdata.name == "#cdata-section");
                                assert (cdata.value == "put in real cdata");
-                       });
+                       } catch { assert_not_reached (); }
+               });
                Test.add_func ("/gxml/gdocument/create_processing_instruction", () => {
+                       try {
                                GDocument doc = new GDocument.from_string ("<root />");
                                ProcessingInstruction instruction = (ProcessingInstruction) doc.create_pi 
("target", "data");
 
@@ -222,9 +233,12 @@ class GDocumentTest : GXmlTest {
                                assert (instruction.target == "target");
                                assert (instruction.data == "data");
                                assert (instruction.value == "data");
-                       });
+                       } catch { assert_not_reached (); }
+               });
                Test.add_func ("/gxml/gdocument/create_attribute", () => {
+                       try {
                                GDocument doc = new GDocument.from_string ("<root />");
+                               assert (doc.root != null);
                                ((GElement) doc.root).set_attr ("attrname", "attrvalue");
                                Test.message ("DOC:"+doc.to_string ());
                                var attr = ((GElement) doc.root).get_attr ("attrname");
@@ -236,8 +250,10 @@ class GDocumentTest : GXmlTest {
                                assert (attr.value == "attrvalue");
                                //
                                //Test.message ("DOC libxml2:"+doc.libxml_to_string ());
-                       });
+                       } catch { assert_not_reached (); }
+               });
                Test.add_func ("/gxml/gdocument/to_string", () => {
+                       try {
                                GDocument doc = new GDocument.from_string ("<?xml version=\"1.0\"?>
 <Sentences><Sentence lang=\"en\">I like the colour blue.</Sentence><Sentence lang=\"de\">Ich liebe die 
T&#xFC;r.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co 
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co 
uk</Email></Author></Authors></Sentences>");
                                string s1 = doc.to_string ();
@@ -245,8 +261,10 @@ class GDocumentTest : GXmlTest {
                                Test.message (s1);
                                assert (cs1[0] == "<?xml version=\"1.0\"?>");
                                assert (cs1[1] == "<Sentences><Sentence lang=\"en\">I like the colour 
blue.</Sentence><Sentence lang=\"de\">Ich liebe die 
T&#xFC;r.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co 
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co 
uk</Email></Author></Authors></Sentences>");
-                       });
+                       } catch { assert_not_reached (); }
+               });
                Test.add_func ("/gxml/gdocument/libxml_to_string", () => {
+                       try {
                                GDocument doc = new GDocument.from_string ("<?xml version=\"1.0\"?>
 <Sentences><Sentence lang=\"en\">I like the colour blue.</Sentence><Sentence lang=\"de\">Ich liebe die 
T&#xFC;r.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co 
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co 
uk</Email></Author></Authors></Sentences>");
                                string s1 = doc.libxml_to_string ();
@@ -254,6 +272,7 @@ class GDocumentTest : GXmlTest {
                                Test.message (s1);
                                assert (cs1[0] == "<?xml version=\"1.0\"?>");
                                assert (cs1[1] == "<Sentences><Sentence lang=\"en\">I like the colour 
blue.</Sentence><Sentence lang=\"de\">Ich liebe die 
T&#xFC;r.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co 
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co 
uk</Email></Author></Authors></Sentences>");
-                       });
+                       } catch { assert_not_reached (); }
+               });
        }
 }
diff --git a/test/Makefile.am b/test/Makefile.am
index 6d20e1e..e9f6f06 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -66,10 +66,29 @@ sources = \
        HtmlDocumentTest.vala \
        $(NULL)
 
-gxml_test.vala.stamp: $(sources)
+vala-stamp: $(sources)
+       @rm -f vala-temp
+       @touch vala-temp
        $(VALAC) $(AM_VALAFLAGS) $^
-
-$(sources:.vala=.c): gxml_test.vala.stamp
+       @mv -f vala-temp $@
+
+$(sources:.vala=.c): vala-stamp
+## Recover from the removal of $@
+       @if test -f $@; then :; else \
+               trap ’rm -rf vala-lock vala-stamp’ 1 2 13 15; \
+               if mkdir vala-lock 2>/dev/null; then \
+## This code is being executed by the first process.
+                       rm -f vala-stamp; \
+                       $(MAKE) $(AM_MAKEFLAGS) vala-stamp; \
+                       rmdir vala-lock; \
+               else \
+## This code is being executed by the follower processes.
+## Wait until the first process is done.
+                       while test -d vala-lock; do sleep 1; done; \
+## Succeed if and only if the first process succeeded.
+                       test -f vala-stamp; exit $$?; \
+               fi; \
+       fi
 
 gxml_test_SOURCES = $(sources:.vala=.c)
 
@@ -81,7 +100,7 @@ AM_VALAFLAGS = \
        --pkg gio-2.0 \
        --pkg gee-0.8 \
        --pkg posix \
-       --pkg gxml-0.6 \
+       --pkg gxml-0.10 \
        --pkg libxml-2.0 \
        -C \
        -g \
@@ -104,7 +123,7 @@ gxml_test_LDADD = \
        $(GXML_LIBS) \
        $(LIBXML_LIBS) \
        $(GIO_LIBS) \
-       ../gxml/libgxml-0.6.la
+       ../gxml/libgxml-0.10.la
        $(NULL)
 
 gxml_test_LDFLAGS = $(AM_LDFLAGS)
@@ -117,8 +136,6 @@ gxml_test_LDFLAGS = $(AM_LDFLAGS)
 
 #...
 
-BUILT_SOURCES = gxml_test.vala.stamp
-
 CLEANFILES = $(gxml_test_SOURCES:.vala=.c) $(BUILT_SOURCES) gxml_test
 
 # TODO: should we add *.c to this list?, or is there a var of generated .c we can put in CLEANFILES?
diff --git a/test/SerializableGeeArrayListTest.vala b/test/SerializableGeeArrayListTest.vala
index a9dd146..9e14f68 100644
--- a/test/SerializableGeeArrayListTest.vala
+++ b/test/SerializableGeeArrayListTest.vala
@@ -74,12 +74,12 @@ class SerializableGeeArrayListTest : GXmlTest
         c.add (o2);
         var doc = new TwDocument ();
         var root = doc.create_element ("root");
-        doc.childs.add (root);
+        doc.children.add (root);
         c.serialize (root);
-        assert (root.childs.size == 2);
+        assert (root.children.size == 2);
         bool found1 = false;
         bool found2 = false;
-        foreach (GXml.Node n in root.childs) {
+        foreach (GXml.Node n in root.children) {
           if (n is Element && n.name == "aelement") {
             var name = n.attrs.get ("name");
             if (name != null) {
@@ -147,7 +147,7 @@ class SerializableGeeArrayListTest : GXmlTest
         ic.deserialize (iroot);
         var doc = new TwDocument ();
         var root = doc.create_element ("root");
-        doc.childs.add (root);
+        doc.children.add (root);
         ic.serialize (root);
         var c = new SerializableArrayList<AElement> ();
         c.deserialize (root);
diff --git a/test/SerializableGeeHashMapTest.vala b/test/SerializableGeeHashMapTest.vala
index a6918e5..ceb6a6b 100644
--- a/test/SerializableGeeHashMapTest.vala
+++ b/test/SerializableGeeHashMapTest.vala
@@ -113,20 +113,20 @@ class SerializableGeeHashMapTest : GXmlTest
         c.set (o2.name, o2);
         var doc = new TwDocument ();
         var root = doc.create_element ("root");
-        doc.childs.add (root);
+        doc.children.add (root);
         c.serialize (root);
-        assert (root.childs.size > 0);
+        assert (root.children.size > 0);
         bool found1 = false;
         bool found2 = false;
-        foreach (GXml.Node n in root.childs) {
+        foreach (GXml.Node n in root.children) {
           if (n is Element && n.name == "space") {
             var name = n.attrs.get ("name");
             if (name != null) {
               if (name.value == "Big") found1 = true;
               if (name.value == "Small") found2 = true;
             }
-            if (n.childs.size > 0) {
-              foreach (GXml.Node nd in n.childs) {
+            if (n.children.size > 0) {
+              foreach (GXml.Node nd in n.children) {
                 if (nd is Text) {
                   if (nd.value != "FAKE TEXT") {
                     stdout.printf (@"ERROR: node content don't much. Expected 'FAKE TEXT', got: 
$(nd.value)\n$(doc)\n");
@@ -231,10 +231,10 @@ class SerializableGeeHashMapTest : GXmlTest
         assert (doc.root != null);
         assert (doc.root.name == "spacecontainer");
         var root = doc.root;
-        assert (root.childs.size > 0);
+        assert (root.children.size > 0);
         bool found1 = false;
         bool found2 = false;
-        foreach (GXml.Node n in root.childs) {
+        foreach (GXml.Node n in root.children) {
           if (n is Element && n.name == "space") {
             var name = n.attrs.get ("name");
             if (name != null) {


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