writer: completely skip over empty corpora
authorMatthias Maennich <maennich@google.com>
Mon, 13 Jan 2020 14:44:51 +0000 (14:44 +0000)
committerMatthias Maennich <maennich@google.com>
Mon, 20 Jan 2020 14:58:22 +0000 (14:58 +0000)
A corpus that has no symbols contributing to the ABI surface (e.g.
because of an exhaustive suppression), will not contribute in a later
comparison via abidiff and friends. Hence, there is no need for such
entries to appear in the ABI xml representation. This patch completely
suppresses empty corpora.

* src/abg-writer.cc (write_corpus): completely skip empty
corpora rather than creating an empty entry for them.

Reviewed-by: Dodji Seketeli <dodji@seketeli.org>
Signed-off-by: Matthias Maennich <maennich@google.com>
src/abg-writer.cc

index 78844cf..c8c0ee6 100644 (file)
@@ -4362,6 +4362,10 @@ write_corpus_to_archive(const corpus_sptr corp, const bool annotate)
 /// Serialize an ABI corpus to a single native xml document.  The root
 /// note of the resulting XML document is 'abi-corpus'.
 ///
+/// Note: If either corpus is null or corpus does not contain serializable
+///       content (i.e. corpus.is_empty()), nothing is emitted to the ctxt's
+///       output stream.
+///
 /// @param ctxt the write context to use.
 ///
 /// @param corpus the corpus to serialize.
@@ -4378,6 +4382,9 @@ write_corpus(write_context&       ctxt,
   if (!corpus)
     return false;
 
+  if (corpus->is_empty())
+    return true;
+
   do_indent_to_level(ctxt, indent, 0);
 
   std::ostream& out = ctxt.get_ostream();
@@ -4411,12 +4418,6 @@ write_corpus(write_context&      ctxt,
 
   write_tracking_non_reachable_types(corpus, out);
 
-  if (corpus->is_empty())
-    {
-      out << "/>\n";
-      return true;
-    }
-
   out << ">\n";
 
   // Write the list of needed corpora.