Skip to content

Commit

Permalink
scripts: get_abi.pl: auto-generate cross references
Browse files Browse the repository at this point in the history
There are several cross-references that can be automatically
generated:

	- References to .rst files inside Documentation/
	- References to other ABI files;
	- References to ABI symbols at /sys/*.

Add a logic to automatically parse them and convert into
cross references.

Acked-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/abe756d4f94fb6ffcc3dd3902a766c7c3990ea89.1604042072.git.mchehab+huawei@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
mchehab authored and gregkh committed Oct 30, 2020
1 parent c01d62d commit 55e5414
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/get_abi.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use strict;
use warnings;
use utf8;
use Pod::Usage;
use Getopt::Long;
use File::Find;
Expand Down Expand Up @@ -272,6 +273,9 @@ sub create_labels {
# Outputs the book on ReST format
#

# \b doesn't work well with paths. So, we need to define something else
my $bondary = qr { (?<![\w\/\`\{])(?=[\w\/\`\{])|(?<=[\w\/\`\{])(?![\w\/\`\{]) }x;

sub output_rest {
create_labels();

Expand Down Expand Up @@ -342,6 +346,33 @@ sub output_rest {

if (!($desc =~ /^\s*$/)) {
if ($description_is_rst) {
# Enrich text by creating cross-references

$desc =~ s,Documentation/(?!devicetree)(\S+)\.rst,:doc:`/$1`,g;

my @matches = $desc =~ m,Documentation/ABI/([\w\/\-]+),;
foreach my $f (@matches) {
my $xref = $f;
my $path = $f;
$path =~ s,.*/(.*/.*),$1,;;
$path =~ s,[/\-],_,g;;
$xref .= " <abi_file_" . $path . ">";
$desc =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g;
}

@matches = $desc =~ m,$bondary(/sys/[^\s\.\,\;\:\*\s\`\'\(\)]+)$bondary,;

foreach my $s (@matches) {
if (defined($data{$s}) && defined($data{$s}->{label})) {
my $xref = $s;

$xref =~ s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g;
$xref = ":ref:`$xref <" . $data{$s}->{label} . ">`";

$desc =~ s,$bondary$s$bondary,$xref,g;
}
}

print "$desc\n\n";
} else {
$desc =~ s/^\s+//;
Expand Down

0 comments on commit 55e5414

Please sign in to comment.