Skip to content

Commit 55e5414

Browse files
mchehabgregkh
authored andcommitted
scripts: get_abi.pl: auto-generate cross references
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>
1 parent c01d62d commit 55e5414

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

scripts/get_abi.pl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use strict;
55
use warnings;
6+
use utf8;
67
use Pod::Usage;
78
use Getopt::Long;
89
use File::Find;
@@ -272,6 +273,9 @@ sub create_labels {
272273
# Outputs the book on ReST format
273274
#
274275

276+
# \b doesn't work well with paths. So, we need to define something else
277+
my $bondary = qr { (?<![\w\/\`\{])(?=[\w\/\`\{])|(?<=[\w\/\`\{])(?![\w\/\`\{]) }x;
278+
275279
sub output_rest {
276280
create_labels();
277281

@@ -342,6 +346,33 @@ sub output_rest {
342346

343347
if (!($desc =~ /^\s*$/)) {
344348
if ($description_is_rst) {
349+
# Enrich text by creating cross-references
350+
351+
$desc =~ s,Documentation/(?!devicetree)(\S+)\.rst,:doc:`/$1`,g;
352+
353+
my @matches = $desc =~ m,Documentation/ABI/([\w\/\-]+),;
354+
foreach my $f (@matches) {
355+
my $xref = $f;
356+
my $path = $f;
357+
$path =~ s,.*/(.*/.*),$1,;;
358+
$path =~ s,[/\-],_,g;;
359+
$xref .= " <abi_file_" . $path . ">";
360+
$desc =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g;
361+
}
362+
363+
@matches = $desc =~ m,$bondary(/sys/[^\s\.\,\;\:\*\s\`\'\(\)]+)$bondary,;
364+
365+
foreach my $s (@matches) {
366+
if (defined($data{$s}) && defined($data{$s}->{label})) {
367+
my $xref = $s;
368+
369+
$xref =~ s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g;
370+
$xref = ":ref:`$xref <" . $data{$s}->{label} . ">`";
371+
372+
$desc =~ s,$bondary$s$bondary,$xref,g;
373+
}
374+
}
375+
345376
print "$desc\n\n";
346377
} else {
347378
$desc =~ s/^\s+//;

0 commit comments

Comments
 (0)