diff mbox series

[RFC,5/9] Add pass to normalise anonymous type names

Message ID 20210325215146.3597963-6-gprocida@google.com
State New
Headers show
Series Utility to manipulate ABI XML | expand

Commit Message

Giuliano Procida March 25, 2021, 9:51 p.m. UTC
Currently libabigail exposes the internal names used for anonymous
types in ABI XML. The names are not stable - they are subject to
renumbering - and cause "harmless" diffs which in turn can contribute
to hard-to-read and verbose abidiff --harmless output.

	* scripts/abitidy.pl (normalise_anonymous_type_names): New
	function to normalise anonymous type names by stripping off
	numerical suffices.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 scripts/abitidy.pl | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/scripts/abitidy.pl b/scripts/abitidy.pl
index 468eeac4..321363d7 100755
--- a/scripts/abitidy.pl
+++ b/scripts/abitidy.pl
@@ -366,6 +366,16 @@  sub filter_symbols($symbols, $dom) {
   }
 }
 
+sub normalise_anonymous_type_names($) {
+  my ($doc) = @_;
+  my $name_path = new XML::LibXML::XPathExpression('//abi-instr//*[@name]');
+  for my $node ($doc->findnodes($name_path)) {
+    my $value = $node->getAttribute('name');
+    $value =~ s;^(__anonymous_[a-z]+__)\d*$;$1;;
+    $node->setAttribute('name', $value);
+  }
+}
+
 # Parse arguments.
 my $input_opt;
 my $output_opt;
@@ -373,14 +383,16 @@  my $symbols_opt;
 my $all_opt;
 my $drop_opt;
 my $prune_opt;
+my $normalise_opt;
 GetOptions('i|input=s' => \$input_opt,
            'o|output=s' => \$output_opt,
            's|symbols=s' => \$symbols_opt,
            'a|all' => sub {
-             $drop_opt = $prune_opt = 1
+             $drop_opt = $prune_opt = $normalise_opt = 1
            },
            'd|drop-empty!' => \$drop_opt,
            'p|prune-unreachable!' => \$prune_opt,
+           'n|normalise-anonymous!' => \$normalise_opt,
   ) and !@ARGV or die("usage: $0",
                       map { (' ', $_) } (
                         '[-i|--input file]',
@@ -389,6 +401,7 @@  GetOptions('i|input=s' => \$input_opt,
                         '[-a|--all]',
                         '[-d|--[no-]drop-empty]',
                         '[-p|--[no-]prune-unreachable]',
+                        '[-n|--[no-]normalise-anonymous]',
                       ), "\n");
 
 exit 0 unless defined $input_opt;
@@ -404,6 +417,9 @@  strip_text($dom);
 # Remove unlisted symbols.
 filter_symbols(read_symbols($symbols_opt), $dom) if defined $symbols_opt;
 
+# Normalise anonymous type names.
+normalise_anonymous_type_names($dom) if $normalise_opt;
+
 # Prune unreachable elements.
 prune_unreachable($dom) if $prune_opt;