From: Giuliano Procida <gprocida@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com,
maennich@google.com, woodard@redhat.com
Subject: [RFC PATCH 2/9] Add pass to drop empty XML elements
Date: Thu, 25 Mar 2021 21:51:39 +0000 [thread overview]
Message-ID: <20210325215146.3597963-3-gprocida@google.com> (raw)
In-Reply-To: <20210325215146.3597963-1-gprocida@google.com>
Certain elements in ABI XML are effectvely containers and can be
dropped if empty and their attributes don't carry ABI information.
- elf-variable-symbols: pure container
- elf-function-symbols: pure container
- namespace-decl: has a name
- abi-instr: compilation unit (path etc.)
- abi-corpus: binary object (architecture)
- abi-corpus-group: binary objects (architecture)
It could be argued that abi-corpus (or abi-corpus-group) should be
kept around to hold the architecture of an object or set of objects.
However, if a binary object has no symbols (say, if it is empty), it
hardly matters what the architecture is.
Note that:
- abidiff rejects XML files with an XML declaration at the top
- abidiff rejects completely empty files
Resolving the first would make the second moot. In the meantime, we
avoid dropping top-level elements.
* scripts/abitidy.pl (drop_if_empty): New variable containing
the tags of elements that can be dropped if empty.
(drop_empty): New Function that removes empty elements, except
top-level ones.
Signed-off-by: Giuliano Procida <gprocida@google.com>
---
scripts/abitidy.pl | 43 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/scripts/abitidy.pl b/scripts/abitidy.pl
index 66d636d7..1f74e267 100755
--- a/scripts/abitidy.pl
+++ b/scripts/abitidy.pl
@@ -105,20 +105,58 @@ sub indent($indent, $node) {
}
}
+# Remove an XML element and any preceeding comment.
+sub remove_node($node) {
+ my $prev = $node->previousSibling();
+ if ($prev && $prev->nodeType == XML_COMMENT_NODE) {
+ $prev->unbindNode();
+ }
+ $node->unbindNode();
+}
+
+# These container elements can be dropped if empty.
+my %drop_if_empty = map { $_ => undef } qw(
+ elf-variable-symbols
+ elf-function-symbols
+ namespace-decl
+ abi-instr
+ abi-corpus
+ abi-corpus-group
+);
+
+# This is a XML DOM traversal as we want post-order traversal so we
+# delete nodes that become empty during the process.
+sub drop_empty;
+sub drop_empty($node) {
+ my $node_name = $node->getName();
+ for my $child ($node->childNodes()) {
+ drop_empty($child);
+ }
+ if (!$node->hasChildNodes() && $node->nodeType == XML_ELEMENT_NODE && exists $drop_if_empty{$node->getName()}) {
+ # Until abidiff accepts empty ABIs, avoid dropping top-level elements.
+ if ($node->parentNode->nodeType == XML_ELEMENT_NODE) {
+ remove_node($node);
+ }
+ }
+}
+
# Parse arguments.
my $input_opt;
my $output_opt;
my $all_opt;
+my $drop_opt;
GetOptions('i|input=s' => \$input_opt,
'o|output=s' => \$output_opt,
'a|all' => sub {
- 1
+ $drop_opt = 1
},
+ 'd|drop-empty!' => \$drop_opt,
) and !@ARGV or die("usage: $0",
map { (' ', $_) } (
'[-i|--input file]',
'[-o|--output file]',
'[-a|--all]',
+ '[-d|--[no-]drop-empty]',
), "\n");
exit 0 unless defined $input_opt;
@@ -131,6 +169,9 @@ close $input;
# This simplifies DOM analysis and manipulation.
strip_text($dom);
+# Drop empty elements.
+drop_empty($dom) if $drop_opt;
+
exit 0 unless defined $output_opt;
# Reformat for human consumption.
--
2.31.0.291.g576ba9dcdaf-goog
next prev parent reply other threads:[~2021-03-25 21:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-11 11:53 [RFC PATCH] Add an experimental ABI pruning utility Giuliano Procida
2021-03-11 20:39 ` Ben Woodard
2021-03-12 16:51 ` Giuliano Procida
2021-03-12 18:41 ` Ben Woodard
2021-03-15 11:08 ` Giuliano Procida
2021-03-12 16:59 ` [RFC PATCH v2] " Giuliano Procida
2021-03-16 16:55 ` [RFC PATCH v3] " Giuliano Procida
2021-03-25 21:51 ` [RFC PATCH 0/9] Utility to manipulate ABI XML Giuliano Procida
2021-03-25 21:51 ` [RFC PATCH 1/9] Add ABI tidying utility Giuliano Procida
2021-03-25 21:51 ` Giuliano Procida [this message]
2021-03-25 21:51 ` [RFC PATCH 3/9] Add pass to prune unreachable parts of the ABI Giuliano Procida
2021-03-25 21:51 ` [RFC PATCH 4/9] Add pass to filter symbols Giuliano Procida
2021-03-25 21:51 ` [RFC PATCH 5/9] Add pass to normalise anonymous type names Giuliano Procida
2021-03-25 21:51 ` [RFC PATCH 6/9] Add pass to report duplicate type ids Giuliano Procida
2021-03-25 21:51 ` [RFC PATCH 7/9] Add pass to eliminate duplicate member-type fragments Giuliano Procida
2021-03-25 21:51 ` [RFC PATCH 8/9] Add pass to stabilise types and declarations Giuliano Procida
2021-03-25 21:51 ` [RFC PATCH 9/9] Add pass to resolve stray forward type declarations Giuliano Procida
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210325215146.3597963-3-gprocida@google.com \
--to=gprocida@google.com \
--cc=dodji@seketeli.org \
--cc=kernel-team@android.com \
--cc=libabigail@sourceware.org \
--cc=maennich@google.com \
--cc=woodard@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).