Commit 234948bf authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab Committed by Greg Kroah-Hartman

scripts: get_abi.pl: cleanup ABI cross-reference logic

Right now, the cross-references are generated on a single
step, when doing ReST output.

While this is nice optimization, it prevents auto-creating
cross-references for ABI symbols.

So, split it into a separate logic.

While here, turn on Perl warnings, as it helps to debug
problems inside the script.
Acked-by: default avatarJonathan Corbet <corbet@lwn.net>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/dbc97c8c2dfd877921f058134c35b2a8b1f8414b.1604042072.git.mchehab+huawei@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f82a8a74
...@@ -2,15 +2,16 @@ ...@@ -2,15 +2,16 @@
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
use strict; use strict;
use warnings;
use Pod::Usage; use Pod::Usage;
use Getopt::Long; use Getopt::Long;
use File::Find; use File::Find;
use Fcntl ':mode'; use Fcntl ':mode';
my $help; my $help = 0;
my $man; my $man = 0;
my $debug; my $debug = 0;
my $enable_lineno; my $enable_lineno = 0;
my $prefix="Documentation/ABI"; my $prefix="Documentation/ABI";
# #
...@@ -40,6 +41,7 @@ pod2usage(2) if ($cmd eq "search" && !$arg); ...@@ -40,6 +41,7 @@ pod2usage(2) if ($cmd eq "search" && !$arg);
require Data::Dumper if ($debug); require Data::Dumper if ($debug);
my %data; my %data;
my %symbols;
# #
# Displays an error message, printing file name and line # Displays an error message, printing file name and line
...@@ -76,12 +78,12 @@ sub parse_abi { ...@@ -76,12 +78,12 @@ sub parse_abi {
my $what; my $what;
my $new_what; my $new_what;
my $tag; my $tag = "";
my $ln; my $ln;
my $xrefs; my $xrefs;
my $space; my $space;
my @labels; my @labels;
my $label; my $label = "";
print STDERR "Opening $file\n" if ($debug > 1); print STDERR "Opening $file\n" if ($debug > 1);
open IN, $file; open IN, $file;
...@@ -110,10 +112,18 @@ sub parse_abi { ...@@ -110,10 +112,18 @@ sub parse_abi {
if ($new_tag =~ m/what/) { if ($new_tag =~ m/what/) {
$space = ""; $space = "";
$content =~ s/[,.;]$//;
if ($tag =~ m/what/) { if ($tag =~ m/what/) {
$what .= ", " . $content; $what .= ", " . $content;
} else { } else {
parse_error($file, $ln, "What '$what' doesn't have a description", "") if ($what && !$data{$what}->{description}); if ($what) {
parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description});
foreach my $w(split /, /, $what) {
$symbols{$w} = $what;
};
}
$what = $content; $what = $content;
$label = $content; $label = $content;
...@@ -122,7 +132,7 @@ sub parse_abi { ...@@ -122,7 +132,7 @@ sub parse_abi {
push @labels, [($content, $label)]; push @labels, [($content, $label)];
$tag = $new_tag; $tag = $new_tag;
push @{$data{$nametag}->{xrefs}}, [($content, $label)] if ($data{$nametag}->{what}); push @{$data{$nametag}->{symbols}}, $content if ($data{$nametag}->{what});
next; next;
} }
...@@ -132,7 +142,7 @@ sub parse_abi { ...@@ -132,7 +142,7 @@ sub parse_abi {
$data{$what}->{line_no} = $ln; $data{$what}->{line_no} = $ln;
if ($new_what) { if ($new_what) {
@{$data{$what}->{label}} = @labels if ($data{$nametag}->{what}); @{$data{$what}->{label_list}} = @labels if ($data{$nametag}->{what});
@labels = (); @labels = ();
$label = ""; $label = "";
$new_what = 0; $new_what = 0;
...@@ -203,36 +213,24 @@ sub parse_abi { ...@@ -203,36 +213,24 @@ sub parse_abi {
# Everything else is error # Everything else is error
parse_error($file, $ln, "Unexpected line:", $_); parse_error($file, $ln, "Unexpected line:", $_);
} }
$data{$nametag}->{description} =~ s/^\n+//; $data{$nametag}->{description} =~ s/^\n+// if ($data{$nametag}->{description});
if ($what) {
parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description});
foreach my $w(split /, /,$what) {
$symbols{$w} = $what;
};
}
close IN; close IN;
} }
# sub create_labels {
# Outputs the book on ReST format my %labels;
#
my %labels;
sub output_rest {
foreach my $what (sort {
($data{$a}->{type} eq "File") cmp ($data{$b}->{type} eq "File") ||
$a cmp $b
} keys %data) {
my $type = $data{$what}->{type};
my $file = $data{$what}->{file};
my $filepath = $data{$what}->{filepath};
if ($enable_lineno) {
printf "#define LINENO %s%s#%s\n\n",
$prefix, $data{$what}->{file},
$data{$what}->{line_no};
}
my $w = $what;
$w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g;
foreach my $what (keys %data) {
next if ($data{$what}->{file} eq "File");
foreach my $p (@{$data{$what}->{label}}) { foreach my $p (@{$data{$what}->{label_list}}) {
my ($content, $label) = @{$p}; my ($content, $label) = @{$p};
$label = "abi_" . $label . " "; $label = "abi_" . $label . " ";
$label =~ tr/A-Z/a-z/; $label =~ tr/A-Z/a-z/;
...@@ -249,16 +247,39 @@ sub output_rest { ...@@ -249,16 +247,39 @@ sub output_rest {
} }
$labels{$label} = 1; $labels{$label} = 1;
$data{$what}->{label} .= $label; $data{$what}->{label} = $label;
printf ".. _%s:\n\n", $label;
# only one label is enough # only one label is enough
last; last;
} }
}
}
#
# Outputs the book on ReST format
#
sub output_rest {
create_labels();
foreach my $what (sort {
($data{$a}->{type} eq "File") cmp ($data{$b}->{type} eq "File") ||
$a cmp $b
} keys %data) {
my $type = $data{$what}->{type};
my $file = $data{$what}->{file};
my $filepath = $data{$what}->{filepath};
if ($enable_lineno) {
printf "#define LINENO %s%s#%s\n\n",
$prefix, $data{$what}->{file},
$data{$what}->{line_no};
}
my $w = $what;
$w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g;
$filepath =~ s,.*/(.*/.*),\1,;; $filepath =~ s,.*/(.*/.*),$1,;;
$filepath =~ s,[/\-],_,g;; $filepath =~ s,[/\-],_,g;;
my $fileref = "abi_file_".$filepath; my $fileref = "abi_file_".$filepath;
...@@ -269,8 +290,9 @@ sub output_rest { ...@@ -269,8 +290,9 @@ sub output_rest {
print ".. _$fileref:\n\n"; print ".. _$fileref:\n\n";
print "$w\n$bar\n\n"; print "$w\n$bar\n\n";
} else { } else {
my @names = split /\s*,\s*/,$w; printf ".. _%s:\n\n", $data{$what}->{label};
my @names = split /, /,$w;
my $len = 0; my $len = 0;
foreach my $name (@names) { foreach my $name (@names) {
...@@ -284,12 +306,13 @@ sub output_rest { ...@@ -284,12 +306,13 @@ sub output_rest {
printf "| %s", $name . " " x ($len - length($name)) . " |\n"; printf "| %s", $name . " " x ($len - length($name)) . " |\n";
print "+-" . "-" x $len . "-+\n"; print "+-" . "-" x $len . "-+\n";
} }
print "\n";
}
print "Defined on file :ref:`$file <$fileref>`\n\n" if ($type ne "File"); print "\nDefined on file :ref:`$file <$fileref>`\n\n";
}
my $desc = $data{$what}->{description}; my $desc = "";
$desc = $data{$what}->{description} if (defined($data{$what}->{description}));
$desc =~ s/\s+$/\n/;
if (!($desc =~ /^\s*$/)) { if (!($desc =~ /^\s*$/)) {
if ($description_is_rst) { if ($description_is_rst) {
...@@ -316,18 +339,11 @@ sub output_rest { ...@@ -316,18 +339,11 @@ sub output_rest {
print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file}); print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file});
} }
if ($data{$what}->{xrefs}) { if ($data{$what}->{symbols}) {
printf "Has the following ABI:\n\n"; printf "Has the following ABI:\n\n";
foreach my $p(@{$data{$what}->{xrefs}}) { foreach my $content(@{$data{$what}->{symbols}}) {
my ($content, $label) = @{$p}; my $label = $data{$symbols{$content}}->{label};
$label = "abi_" . $label . " ";
$label =~ tr/A-Z/a-z/;
# Convert special chars to "_"
$label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g;
$label =~ s,_+,_,g;
$label =~ s,_$,,;
# Escape special chars from content # Escape special chars from content
$content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g; $content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g;
...@@ -355,17 +371,20 @@ sub search_symbols { ...@@ -355,17 +371,20 @@ sub search_symbols {
print "\n$what\n$bar\n\n"; print "\n$what\n$bar\n\n";
my $kernelversion = $data{$what}->{kernelversion}; my $kernelversion = $data{$what}->{kernelversion} if (defined($data{$what}->{kernelversion}));
my $contact = $data{$what}->{contact}; my $contact = $data{$what}->{contact} if (defined($data{$what}->{contact}));
my $users = $data{$what}->{users}; my $users = $data{$what}->{users} if (defined($data{$what}->{users}));
my $date = $data{$what}->{date}; my $date = $data{$what}->{date} if (defined($data{$what}->{date}));
my $desc = $data{$what}->{description}; my $desc = $data{$what}->{description} if (defined($data{$what}->{description}));
$kernelversion =~ s/^\s+//;
$contact =~ s/^\s+//; $kernelversion =~ s/^\s+// if ($kernelversion);
$users =~ s/^\s+//; $contact =~ s/^\s+// if ($contact);
$users =~ s/\n//g; if ($users) {
$date =~ s/^\s+//; $users =~ s/^\s+//;
$desc =~ s/^\s+//; $users =~ s/\n//g;
}
$date =~ s/^\s+// if ($date);
$desc =~ s/^\s+// if ($desc);
printf "Kernel version:\t\t%s\n", $kernelversion if ($kernelversion); printf "Kernel version:\t\t%s\n", $kernelversion if ($kernelversion);
printf "Date:\t\t\t%s\n", $date if ($date); printf "Date:\t\t\t%s\n", $date if ($date);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment