Finn Behrens | c25ce58 | 2020-11-23 15:15:33 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Mauro Carvalho Chehab | ecb351f | 2019-06-20 14:23:10 -0300 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 3 | |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 4 | BEGIN { $Pod::Usage::Formatter = 'Pod::Text::Termcap'; } |
| 5 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 6 | use strict; |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 7 | use warnings; |
Mauro Carvalho Chehab | 55e5414 | 2020-10-30 08:40:29 +0100 | [diff] [blame] | 8 | use utf8; |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 9 | use Pod::Usage qw(pod2usage); |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 10 | use Getopt::Long; |
| 11 | use File::Find; |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 12 | use IO::Handle; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 13 | use Fcntl ':mode'; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 14 | use Cwd 'abs_path'; |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 15 | use Data::Dumper; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 16 | |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 17 | my $help = 0; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 18 | my $hint = 0; |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 19 | my $man = 0; |
| 20 | my $debug = 0; |
| 21 | my $enable_lineno = 0; |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 22 | my $show_warnings = 1; |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 23 | my $prefix="Documentation/ABI"; |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 24 | my $sysfs_prefix="/sys"; |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 25 | my $search_string; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 26 | |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 27 | # Debug options |
| 28 | my $dbg_what_parsing = 1; |
| 29 | my $dbg_what_open = 2; |
| 30 | my $dbg_dump_abi_structs = 4; |
Mauro Carvalho Chehab | f34f672 | 2021-09-23 17:41:18 +0200 | [diff] [blame] | 31 | my $dbg_undefined = 8; |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 32 | |
Mauro Carvalho Chehab | 3a1cc06 | 2021-09-27 15:49:49 +0200 | [diff] [blame] | 33 | $Data::Dumper::Indent = 1; |
| 34 | $Data::Dumper::Terse = 1; |
| 35 | |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 36 | # |
| 37 | # If true, assumes that the description is formatted with ReST |
| 38 | # |
Mauro Carvalho Chehab | 2fcce37 | 2020-10-30 08:40:58 +0100 | [diff] [blame] | 39 | my $description_is_rst = 1; |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 40 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 41 | GetOptions( |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 42 | "debug=i" => \$debug, |
Mauro Carvalho Chehab | 61439c4 | 2020-10-30 08:40:22 +0100 | [diff] [blame] | 43 | "enable-lineno" => \$enable_lineno, |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 44 | "rst-source!" => \$description_is_rst, |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 45 | "dir=s" => \$prefix, |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 46 | 'help|?' => \$help, |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 47 | "show-hints" => \$hint, |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 48 | "search-string=s" => \$search_string, |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 49 | man => \$man |
| 50 | ) or pod2usage(2); |
| 51 | |
| 52 | pod2usage(1) if $help; |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 53 | pod2usage(-exitstatus => 0, -noperldoc, -verbose => 2) if $man; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 54 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 55 | pod2usage(2) if (scalar @ARGV < 1 || @ARGV > 2); |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 56 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 57 | my ($cmd, $arg) = @ARGV; |
| 58 | |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 59 | pod2usage(2) if ($cmd ne "search" && $cmd ne "rest" && $cmd ne "validate" && $cmd ne "undefined"); |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 60 | pod2usage(2) if ($cmd eq "search" && !$arg); |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 61 | |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 62 | require Data::Dumper if ($debug & $dbg_dump_abi_structs); |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 63 | |
| 64 | my %data; |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 65 | my %symbols; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 66 | |
| 67 | # |
| 68 | # Displays an error message, printing file name and line |
| 69 | # |
| 70 | sub parse_error($$$$) { |
| 71 | my ($file, $ln, $msg, $data) = @_; |
| 72 | |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 73 | return if (!$show_warnings); |
| 74 | |
Mauro Carvalho Chehab | 75442fb | 2020-10-30 08:40:45 +0100 | [diff] [blame] | 75 | $data =~ s/\s+$/\n/; |
| 76 | |
| 77 | print STDERR "Warning: file $file#$ln:\n\t$msg"; |
| 78 | |
| 79 | if ($data ne "") { |
| 80 | print STDERR ". Line\n\t\t$data"; |
| 81 | } else { |
| 82 | print STDERR "\n"; |
| 83 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | # |
| 87 | # Parse an ABI file, storing its contents at %data |
| 88 | # |
| 89 | sub parse_abi { |
| 90 | my $file = $File::Find::name; |
| 91 | |
| 92 | my $mode = (stat($file))[2]; |
| 93 | return if ($mode & S_IFDIR); |
| 94 | return if ($file =~ m,/README,); |
| 95 | |
| 96 | my $name = $file; |
| 97 | $name =~ s,.*/,,; |
| 98 | |
Mauro Carvalho Chehab | a4ea67b | 2020-10-30 08:40:27 +0100 | [diff] [blame] | 99 | my $fn = $file; |
| 100 | $fn =~ s,Documentation/ABI/,,; |
| 101 | |
| 102 | my $nametag = "File $fn"; |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 103 | $data{$nametag}->{what} = "File $name"; |
| 104 | $data{$nametag}->{type} = "File"; |
| 105 | $data{$nametag}->{file} = $name; |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 106 | $data{$nametag}->{filepath} = $file; |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 107 | $data{$nametag}->{is_file} = 1; |
Mauro Carvalho Chehab | 61439c4 | 2020-10-30 08:40:22 +0100 | [diff] [blame] | 108 | $data{$nametag}->{line_no} = 1; |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 109 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 110 | my $type = $file; |
| 111 | $type =~ s,.*/(.*)/.*,$1,; |
| 112 | |
| 113 | my $what; |
| 114 | my $new_what; |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 115 | my $tag = ""; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 116 | my $ln; |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 117 | my $xrefs; |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 118 | my $space; |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 119 | my @labels; |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 120 | my $label = ""; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 121 | |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 122 | print STDERR "Opening $file\n" if ($debug & $dbg_what_open); |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 123 | open IN, $file; |
| 124 | while(<IN>) { |
| 125 | $ln++; |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 126 | if (m/^(\S+)(:\s*)(.*)/i) { |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 127 | my $new_tag = lc($1); |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 128 | my $sep = $2; |
| 129 | my $content = $3; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 130 | |
Mauro Carvalho Chehab | 7ce7b89 | 2019-06-20 14:23:04 -0300 | [diff] [blame] | 131 | if (!($new_tag =~ m/(what|where|date|kernelversion|contact|description|users)/)) { |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 132 | if ($tag eq "description") { |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 133 | # New "tag" is actually part of |
| 134 | # description. Don't consider it a tag |
| 135 | $new_tag = ""; |
Mauro Carvalho Chehab | 7d7ea8d | 2019-06-20 14:23:01 -0300 | [diff] [blame] | 136 | } elsif ($tag ne "") { |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 137 | parse_error($file, $ln, "tag '$tag' is invalid", $_); |
| 138 | } |
| 139 | } |
| 140 | |
Mauro Carvalho Chehab | 2c0700e | 2019-06-20 14:23:03 -0300 | [diff] [blame] | 141 | # Invalid, but it is a common mistake |
| 142 | if ($new_tag eq "where") { |
Mauro Carvalho Chehab | 75442fb | 2020-10-30 08:40:45 +0100 | [diff] [blame] | 143 | parse_error($file, $ln, "tag 'Where' is invalid. Should be 'What:' instead", ""); |
Mauro Carvalho Chehab | 2c0700e | 2019-06-20 14:23:03 -0300 | [diff] [blame] | 144 | $new_tag = "what"; |
| 145 | } |
| 146 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 147 | if ($new_tag =~ m/what/) { |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 148 | $space = ""; |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 149 | $content =~ s/[,.;]$//; |
| 150 | |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 151 | push @{$symbols{$content}->{file}}, " $file:" . ($ln - 1); |
| 152 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 153 | if ($tag =~ m/what/) { |
Mauro Carvalho Chehab | ab9c148 | 2021-09-18 11:52:11 +0200 | [diff] [blame] | 154 | $what .= "\xac" . $content; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 155 | } else { |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 156 | if ($what) { |
| 157 | parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description}); |
| 158 | |
Mauro Carvalho Chehab | ab9c148 | 2021-09-18 11:52:11 +0200 | [diff] [blame] | 159 | foreach my $w(split /\xac/, $what) { |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 160 | $symbols{$w}->{xref} = $what; |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 161 | }; |
| 162 | } |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 163 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 164 | $what = $content; |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 165 | $label = $content; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 166 | $new_what = 1; |
| 167 | } |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 168 | push @labels, [($content, $label)]; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 169 | $tag = $new_tag; |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 170 | |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 171 | push @{$data{$nametag}->{symbols}}, $content if ($data{$nametag}->{what}); |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 172 | next; |
| 173 | } |
| 174 | |
Mauro Carvalho Chehab | 7d7ea8d | 2019-06-20 14:23:01 -0300 | [diff] [blame] | 175 | if ($tag ne "" && $new_tag) { |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 176 | $tag = $new_tag; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 177 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 178 | if ($new_what) { |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 179 | @{$data{$what}->{label_list}} = @labels if ($data{$nametag}->{what}); |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 180 | @labels = (); |
| 181 | $label = ""; |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 182 | $new_what = 0; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 183 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 184 | $data{$what}->{type} = $type; |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 185 | if (!defined($data{$what}->{file})) { |
| 186 | $data{$what}->{file} = $name; |
| 187 | $data{$what}->{filepath} = $file; |
| 188 | } else { |
Mauro Carvalho Chehab | ff3777d | 2021-09-27 13:10:50 +0200 | [diff] [blame] | 189 | $data{$what}->{description} .= "\n\n" if (defined($data{$what}->{description})); |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 190 | if ($name ne $data{$what}->{file}) { |
| 191 | $data{$what}->{file} .= " " . $name; |
| 192 | $data{$what}->{filepath} .= " " . $file; |
| 193 | } |
| 194 | } |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 195 | print STDERR "\twhat: $what\n" if ($debug & $dbg_what_parsing); |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 196 | $data{$what}->{line_no} = $ln; |
| 197 | } else { |
| 198 | $data{$what}->{line_no} = $ln if (!defined($data{$what}->{line_no})); |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 199 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 200 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 201 | if (!$what) { |
| 202 | parse_error($file, $ln, "'What:' should come first:", $_); |
| 203 | next; |
| 204 | } |
Mauro Carvalho Chehab | f82a8a7 | 2020-10-30 08:40:23 +0100 | [diff] [blame] | 205 | if ($new_tag eq "description") { |
| 206 | $sep =~ s,:, ,; |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 207 | $content = ' ' x length($new_tag) . $sep . $content; |
Mauro Carvalho Chehab | f82a8a7 | 2020-10-30 08:40:23 +0100 | [diff] [blame] | 208 | while ($content =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {} |
| 209 | if ($content =~ m/^(\s*)(\S.*)$/) { |
| 210 | # Preserve initial spaces for the first line |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 211 | $space = $1; |
Mauro Carvalho Chehab | f82a8a7 | 2020-10-30 08:40:23 +0100 | [diff] [blame] | 212 | $content = "$2\n"; |
| 213 | $data{$what}->{$tag} .= $content; |
| 214 | } else { |
| 215 | undef($space); |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 216 | } |
Mauro Carvalho Chehab | e9bca89 | 2020-10-30 08:40:21 +0100 | [diff] [blame] | 217 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 218 | } else { |
| 219 | $data{$what}->{$tag} = $content; |
| 220 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 221 | next; |
| 222 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 223 | } |
| 224 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 225 | # Store any contents before tags at the database |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 226 | if (!$tag && $data{$nametag}->{what}) { |
| 227 | $data{$nametag}->{description} .= $_; |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 228 | next; |
| 229 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 230 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 231 | if ($tag eq "description") { |
Mauro Carvalho Chehab | e9bca89 | 2020-10-30 08:40:21 +0100 | [diff] [blame] | 232 | my $content = $_; |
| 233 | while ($content =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {} |
Mauro Carvalho Chehab | f82a8a7 | 2020-10-30 08:40:23 +0100 | [diff] [blame] | 234 | if (m/^\s*\n/) { |
| 235 | $data{$what}->{$tag} .= "\n"; |
| 236 | next; |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 237 | } |
Mauro Carvalho Chehab | f82a8a7 | 2020-10-30 08:40:23 +0100 | [diff] [blame] | 238 | |
| 239 | if (!defined($space)) { |
| 240 | # Preserve initial spaces for the first line |
| 241 | if ($content =~ m/^(\s*)(\S.*)$/) { |
| 242 | $space = $1; |
| 243 | $content = "$2\n"; |
| 244 | } |
| 245 | } else { |
| 246 | $space = "" if (!($content =~ s/^($space)//)); |
| 247 | } |
| 248 | $data{$what}->{$tag} .= $content; |
| 249 | |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 250 | next; |
| 251 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 252 | if (m/^\s*(.*)/) { |
| 253 | $data{$what}->{$tag} .= "\n$1"; |
| 254 | $data{$what}->{$tag} =~ s/\n+$//; |
| 255 | next; |
| 256 | } |
| 257 | |
| 258 | # Everything else is error |
Mauro Carvalho Chehab | 75442fb | 2020-10-30 08:40:45 +0100 | [diff] [blame] | 259 | parse_error($file, $ln, "Unexpected content", $_); |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 260 | } |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 261 | $data{$nametag}->{description} =~ s/^\n+// if ($data{$nametag}->{description}); |
| 262 | if ($what) { |
| 263 | parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description}); |
| 264 | |
Mauro Carvalho Chehab | ab9c148 | 2021-09-18 11:52:11 +0200 | [diff] [blame] | 265 | foreach my $w(split /\xac/,$what) { |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 266 | $symbols{$w}->{xref} = $what; |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 267 | }; |
| 268 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 269 | close IN; |
| 270 | } |
| 271 | |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 272 | sub create_labels { |
| 273 | my %labels; |
| 274 | |
| 275 | foreach my $what (keys %data) { |
| 276 | next if ($data{$what}->{file} eq "File"); |
| 277 | |
| 278 | foreach my $p (@{$data{$what}->{label_list}}) { |
| 279 | my ($content, $label) = @{$p}; |
| 280 | $label = "abi_" . $label . " "; |
| 281 | $label =~ tr/A-Z/a-z/; |
| 282 | |
| 283 | # Convert special chars to "_" |
| 284 | $label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g; |
| 285 | $label =~ s,_+,_,g; |
| 286 | $label =~ s,_$,,; |
| 287 | |
| 288 | # Avoid duplicated labels |
| 289 | while (defined($labels{$label})) { |
| 290 | my @chars = ("A".."Z", "a".."z"); |
| 291 | $label .= $chars[rand @chars]; |
| 292 | } |
| 293 | $labels{$label} = 1; |
| 294 | |
| 295 | $data{$what}->{label} = $label; |
| 296 | |
| 297 | # only one label is enough |
| 298 | last; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 303 | # |
| 304 | # Outputs the book on ReST format |
| 305 | # |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 306 | |
Mauro Carvalho Chehab | 50ebf8f | 2021-03-25 11:38:24 +0100 | [diff] [blame] | 307 | # \b doesn't work well with paths. So, we need to define something else: |
| 308 | # Boundaries are punct characters, spaces and end-of-line |
| 309 | my $start = qr {(^|\s|\() }x; |
| 310 | my $bondary = qr { ([,.:;\)\s]|\z) }x; |
Mauro Carvalho Chehab | 87ec9ea1 | 2021-03-25 11:38:25 +0100 | [diff] [blame] | 311 | my $xref_match = qr { $start(\/(sys|config|proc|dev|kvd)\/[^,.:;\)\s]+)$bondary }x; |
Mauro Carvalho Chehab | b0f9580 | 2021-03-25 11:38:22 +0100 | [diff] [blame] | 312 | my $symbols = qr { ([\x01-\x08\x0e-\x1f\x21-\x2f\x3a-\x40\x7b-\xff]) }x; |
Mauro Carvalho Chehab | 55e5414 | 2020-10-30 08:40:29 +0100 | [diff] [blame] | 313 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 314 | sub output_rest { |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 315 | create_labels(); |
| 316 | |
Mauro Carvalho Chehab | 9d4fdda | 2020-11-02 11:32:16 +0100 | [diff] [blame] | 317 | my $part = ""; |
| 318 | |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 319 | foreach my $what (sort { |
| 320 | ($data{$a}->{type} eq "File") cmp ($data{$b}->{type} eq "File") || |
| 321 | $a cmp $b |
| 322 | } keys %data) { |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 323 | my $type = $data{$what}->{type}; |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 324 | |
| 325 | my @file = split / /, $data{$what}->{file}; |
| 326 | my @filepath = split / /, $data{$what}->{filepath}; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 327 | |
Mauro Carvalho Chehab | 61439c4 | 2020-10-30 08:40:22 +0100 | [diff] [blame] | 328 | if ($enable_lineno) { |
| 329 | printf "#define LINENO %s%s#%s\n\n", |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 330 | $prefix, $file[0], |
Mauro Carvalho Chehab | 61439c4 | 2020-10-30 08:40:22 +0100 | [diff] [blame] | 331 | $data{$what}->{line_no}; |
| 332 | } |
| 333 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 334 | my $w = $what; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 335 | |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 336 | if ($type ne "File") { |
Mauro Carvalho Chehab | 9d4fdda | 2020-11-02 11:32:16 +0100 | [diff] [blame] | 337 | my $cur_part = $what; |
| 338 | if ($what =~ '/') { |
| 339 | if ($what =~ m#^(\/?(?:[\w\-]+\/?){1,2})#) { |
| 340 | $cur_part = "Symbols under $1"; |
| 341 | $cur_part =~ s,/$,,; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | if ($cur_part ne "" && $part ne $cur_part) { |
| 346 | $part = $cur_part; |
| 347 | my $bar = $part; |
| 348 | $bar =~ s/./-/g; |
| 349 | print "$part\n$bar\n\n"; |
| 350 | } |
| 351 | |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 352 | printf ".. _%s:\n\n", $data{$what}->{label}; |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 353 | |
Mauro Carvalho Chehab | ab9c148 | 2021-09-18 11:52:11 +0200 | [diff] [blame] | 354 | my @names = split /\xac/,$w; |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 355 | my $len = 0; |
| 356 | |
| 357 | foreach my $name (@names) { |
Mauro Carvalho Chehab | b0f9580 | 2021-03-25 11:38:22 +0100 | [diff] [blame] | 358 | $name =~ s/$symbols/\\$1/g; |
Mauro Carvalho Chehab | c01d62d | 2020-10-30 08:40:28 +0100 | [diff] [blame] | 359 | $name = "**$name**"; |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 360 | $len = length($name) if (length($name) > $len); |
| 361 | } |
| 362 | |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 363 | print "+-" . "-" x $len . "-+\n"; |
| 364 | foreach my $name (@names) { |
| 365 | printf "| %s", $name . " " x ($len - length($name)) . " |\n"; |
| 366 | print "+-" . "-" x $len . "-+\n"; |
| 367 | } |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 368 | |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 369 | print "\n"; |
| 370 | } |
| 371 | |
| 372 | for (my $i = 0; $i < scalar(@filepath); $i++) { |
| 373 | my $path = $filepath[$i]; |
| 374 | my $f = $file[$i]; |
| 375 | |
| 376 | $path =~ s,.*/(.*/.*),$1,;; |
| 377 | $path =~ s,[/\-],_,g;; |
| 378 | my $fileref = "abi_file_".$path; |
| 379 | |
| 380 | if ($type eq "File") { |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 381 | print ".. _$fileref:\n\n"; |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 382 | } else { |
| 383 | print "Defined on file :ref:`$f <$fileref>`\n\n"; |
| 384 | } |
Mauro Carvalho Chehab | 45f9651 | 2019-06-20 14:23:00 -0300 | [diff] [blame] | 385 | } |
| 386 | |
Mauro Carvalho Chehab | a4ea67b | 2020-10-30 08:40:27 +0100 | [diff] [blame] | 387 | if ($type eq "File") { |
| 388 | my $bar = $w; |
| 389 | $bar =~ s/./-/g; |
| 390 | print "$w\n$bar\n\n"; |
| 391 | } |
| 392 | |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 393 | my $desc = ""; |
| 394 | $desc = $data{$what}->{description} if (defined($data{$what}->{description})); |
| 395 | $desc =~ s/\s+$/\n/; |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 396 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 397 | if (!($desc =~ /^\s*$/)) { |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 398 | if ($description_is_rst) { |
Mauro Carvalho Chehab | daaaf58 | 2020-11-02 11:32:15 +0100 | [diff] [blame] | 399 | # Remove title markups from the description |
| 400 | # Having titles inside ABI files will only work if extra |
| 401 | # care would be taken in order to strictly follow the same |
| 402 | # level order for each markup. |
| 403 | $desc =~ s/\n[\-\*\=\^\~]+\n/\n\n/g; |
| 404 | |
Mauro Carvalho Chehab | 55e5414 | 2020-10-30 08:40:29 +0100 | [diff] [blame] | 405 | # Enrich text by creating cross-references |
| 406 | |
Mauro Carvalho Chehab | c27c2e3 | 2021-03-25 11:38:26 +0100 | [diff] [blame] | 407 | my $new_desc = ""; |
Mauro Carvalho Chehab | 2ae7bb5 | 2021-03-25 11:38:27 +0100 | [diff] [blame] | 408 | my $init_indent = -1; |
| 409 | my $literal_indent = -1; |
| 410 | |
Mauro Carvalho Chehab | c27c2e3 | 2021-03-25 11:38:26 +0100 | [diff] [blame] | 411 | open(my $fh, "+<", \$desc); |
| 412 | while (my $d = <$fh>) { |
Mauro Carvalho Chehab | 2ae7bb5 | 2021-03-25 11:38:27 +0100 | [diff] [blame] | 413 | my $indent = $d =~ m/^(\s+)/; |
| 414 | my $spaces = length($indent); |
| 415 | $init_indent = $indent if ($init_indent < 0); |
| 416 | if ($literal_indent >= 0) { |
| 417 | if ($spaces > $literal_indent) { |
| 418 | $new_desc .= $d; |
| 419 | next; |
| 420 | } else { |
| 421 | $literal_indent = -1; |
| 422 | } |
| 423 | } else { |
| 424 | if ($d =~ /()::$/ && !($d =~ /^\s*\.\./)) { |
| 425 | $literal_indent = $spaces; |
| 426 | } |
| 427 | } |
| 428 | |
Mauro Carvalho Chehab | c27c2e3 | 2021-03-25 11:38:26 +0100 | [diff] [blame] | 429 | $d =~ s,Documentation/(?!devicetree)(\S+)\.rst,:doc:`/$1`,g; |
Mauro Carvalho Chehab | 55e5414 | 2020-10-30 08:40:29 +0100 | [diff] [blame] | 430 | |
Mauro Carvalho Chehab | c27c2e3 | 2021-03-25 11:38:26 +0100 | [diff] [blame] | 431 | my @matches = $d =~ m,Documentation/ABI/([\w\/\-]+),g; |
| 432 | foreach my $f (@matches) { |
| 433 | my $xref = $f; |
| 434 | my $path = $f; |
| 435 | $path =~ s,.*/(.*/.*),$1,;; |
| 436 | $path =~ s,[/\-],_,g;; |
| 437 | $xref .= " <abi_file_" . $path . ">"; |
| 438 | $d =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g; |
Mauro Carvalho Chehab | 55e5414 | 2020-10-30 08:40:29 +0100 | [diff] [blame] | 439 | } |
Mauro Carvalho Chehab | 55e5414 | 2020-10-30 08:40:29 +0100 | [diff] [blame] | 440 | |
Mauro Carvalho Chehab | c27c2e3 | 2021-03-25 11:38:26 +0100 | [diff] [blame] | 441 | # Seek for cross reference symbols like /sys/... |
| 442 | @matches = $d =~ m/$xref_match/g; |
| 443 | |
| 444 | foreach my $s (@matches) { |
| 445 | next if (!($s =~ m,/,)); |
| 446 | if (defined($data{$s}) && defined($data{$s}->{label})) { |
| 447 | my $xref = $s; |
| 448 | |
| 449 | $xref =~ s/$symbols/\\$1/g; |
| 450 | $xref = ":ref:`$xref <" . $data{$s}->{label} . ">`"; |
| 451 | |
| 452 | $d =~ s,$start$s$bondary,$1$xref$2,g; |
| 453 | } |
| 454 | } |
| 455 | $new_desc .= $d; |
| 456 | } |
| 457 | close $fh; |
| 458 | |
| 459 | |
| 460 | print "$new_desc\n\n"; |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 461 | } else { |
| 462 | $desc =~ s/^\s+//; |
| 463 | |
| 464 | # Remove title markups from the description, as they won't work |
| 465 | $desc =~ s/\n[\-\*\=\^\~]+\n/\n\n/g; |
| 466 | |
| 467 | if ($desc =~ m/\:\n/ || $desc =~ m/\n[\t ]+/ || $desc =~ m/[\x00-\x08\x0b-\x1f\x7b-\xff]/) { |
| 468 | # put everything inside a code block |
| 469 | $desc =~ s/\n/\n /g; |
| 470 | |
| 471 | print "::\n\n"; |
| 472 | print " $desc\n\n"; |
| 473 | } else { |
| 474 | # Escape any special chars from description |
| 475 | $desc =~s/([\x00-\x08\x0b-\x1f\x21-\x2a\x2d\x2f\x3c-\x40\x5c\x5e-\x60\x7b-\xff])/\\$1/g; |
| 476 | print "$desc\n\n"; |
| 477 | } |
Mauro Carvalho Chehab | 4e6a623 | 2019-06-20 14:22:57 -0300 | [diff] [blame] | 478 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 479 | } else { |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 480 | print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file}); |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 481 | } |
Mauro Carvalho Chehab | 6619c66 | 2019-06-20 14:22:56 -0300 | [diff] [blame] | 482 | |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 483 | if ($data{$what}->{symbols}) { |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 484 | printf "Has the following ABI:\n\n"; |
| 485 | |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 486 | foreach my $content(@{$data{$what}->{symbols}}) { |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 487 | my $label = $data{$symbols{$content}->{xref}}->{label}; |
Mauro Carvalho Chehab | d0ebaf5 | 2019-06-20 14:22:58 -0300 | [diff] [blame] | 488 | |
| 489 | # Escape special chars from content |
| 490 | $content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g; |
| 491 | |
| 492 | print "- :ref:`$content <$label>`\n\n"; |
| 493 | } |
| 494 | } |
Mauro Carvalho Chehab | a16ab14 | 2020-10-30 08:40:26 +0100 | [diff] [blame] | 495 | |
| 496 | if (defined($data{$what}->{users})) { |
| 497 | my $users = $data{$what}->{users}; |
| 498 | |
| 499 | $users =~ s/\n/\n\t/g; |
| 500 | printf "Users:\n\t%s\n\n", $users if ($users ne ""); |
| 501 | } |
| 502 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | |
| 506 | # |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 507 | # Searches for ABI symbols |
| 508 | # |
| 509 | sub search_symbols { |
| 510 | foreach my $what (sort keys %data) { |
| 511 | next if (!($what =~ m/($arg)/)); |
| 512 | |
| 513 | my $type = $data{$what}->{type}; |
| 514 | next if ($type eq "File"); |
| 515 | |
| 516 | my $file = $data{$what}->{filepath}; |
| 517 | |
Mauro Carvalho Chehab | e27c42a | 2021-09-23 17:41:12 +0200 | [diff] [blame] | 518 | $what =~ s/\xac/, /g; |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 519 | my $bar = $what; |
| 520 | $bar =~ s/./-/g; |
| 521 | |
| 522 | print "\n$what\n$bar\n\n"; |
| 523 | |
Mauro Carvalho Chehab | 234948b | 2020-10-30 08:40:24 +0100 | [diff] [blame] | 524 | my $kernelversion = $data{$what}->{kernelversion} if (defined($data{$what}->{kernelversion})); |
| 525 | my $contact = $data{$what}->{contact} if (defined($data{$what}->{contact})); |
| 526 | my $users = $data{$what}->{users} if (defined($data{$what}->{users})); |
| 527 | my $date = $data{$what}->{date} if (defined($data{$what}->{date})); |
| 528 | my $desc = $data{$what}->{description} if (defined($data{$what}->{description})); |
| 529 | |
| 530 | $kernelversion =~ s/^\s+// if ($kernelversion); |
| 531 | $contact =~ s/^\s+// if ($contact); |
| 532 | if ($users) { |
| 533 | $users =~ s/^\s+//; |
| 534 | $users =~ s/\n//g; |
| 535 | } |
| 536 | $date =~ s/^\s+// if ($date); |
| 537 | $desc =~ s/^\s+// if ($desc); |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 538 | |
| 539 | printf "Kernel version:\t\t%s\n", $kernelversion if ($kernelversion); |
| 540 | printf "Date:\t\t\t%s\n", $date if ($date); |
| 541 | printf "Contact:\t\t%s\n", $contact if ($contact); |
| 542 | printf "Users:\t\t\t%s\n", $users if ($users); |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 543 | print "Defined on file(s):\t$file\n\n"; |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 544 | print "Description:\n\n$desc"; |
| 545 | } |
| 546 | } |
| 547 | |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 548 | # Exclude /sys/kernel/debug and /sys/kernel/tracing from the search path |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 549 | sub dont_parse_special_attributes { |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 550 | if (($File::Find::dir =~ m,^/sys/kernel,)) { |
| 551 | return grep {!/(debug|tracing)/ } @_; |
| 552 | } |
| 553 | |
| 554 | if (($File::Find::dir =~ m,^/sys/fs,)) { |
| 555 | return grep {!/(pstore|bpf|fuse)/ } @_; |
| 556 | } |
| 557 | |
| 558 | return @_ |
| 559 | } |
| 560 | |
| 561 | my %leaf; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 562 | my %aliases; |
| 563 | my @files; |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 564 | my %root; |
| 565 | |
| 566 | sub graph_add_file { |
| 567 | my $file = shift; |
| 568 | my $type = shift; |
| 569 | |
| 570 | my $dir = $file; |
| 571 | $dir =~ s,^(.*/).*,$1,; |
| 572 | $file =~ s,.*/,,; |
| 573 | |
| 574 | my $name; |
| 575 | my $file_ref = \%root; |
| 576 | foreach my $edge(split "/", $dir) { |
| 577 | $name .= "$edge/"; |
| 578 | if (!defined ${$file_ref}{$edge}) { |
| 579 | ${$file_ref}{$edge} = { }; |
| 580 | } |
| 581 | $file_ref = \%{$$file_ref{$edge}}; |
| 582 | ${$file_ref}{"__name"} = [ $name ]; |
| 583 | } |
| 584 | $name .= "$file"; |
| 585 | ${$file_ref}{$file} = { |
| 586 | "__name" => [ $name ] |
| 587 | }; |
| 588 | |
| 589 | return \%{$$file_ref{$file}}; |
| 590 | } |
| 591 | |
| 592 | sub graph_add_link { |
| 593 | my $file = shift; |
| 594 | my $link = shift; |
| 595 | |
| 596 | # Traverse graph to find the reference |
| 597 | my $file_ref = \%root; |
| 598 | foreach my $edge(split "/", $file) { |
| 599 | $file_ref = \%{$$file_ref{$edge}} || die "Missing node!"; |
| 600 | } |
| 601 | |
| 602 | # do a BFS |
| 603 | |
| 604 | my @queue; |
| 605 | my %seen; |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 606 | my $st; |
| 607 | |
| 608 | push @queue, $file_ref; |
| 609 | $seen{$start}++; |
| 610 | |
| 611 | while (@queue) { |
| 612 | my $v = shift @queue; |
| 613 | my @child = keys(%{$v}); |
| 614 | |
| 615 | foreach my $c(@child) { |
| 616 | next if $seen{$$v{$c}}; |
| 617 | next if ($c eq "__name"); |
| 618 | |
Mauro Carvalho Chehab | 3a1cc06 | 2021-09-27 15:49:49 +0200 | [diff] [blame] | 619 | if (!defined($$v{$c}{"__name"})) { |
| 620 | printf STDERR "Error: Couldn't find a non-empty name on a children of $file/.*: "; |
| 621 | print STDERR Dumper(%{$v}); |
| 622 | exit; |
| 623 | } |
| 624 | |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 625 | # Add new name |
| 626 | my $name = @{$$v{$c}{"__name"}}[0]; |
| 627 | if ($name =~ s#^$file/#$link/#) { |
| 628 | push @{$$v{$c}{"__name"}}, $name; |
| 629 | } |
| 630 | # Add child to the queue and mark as seen |
| 631 | push @queue, $$v{$c}; |
| 632 | $seen{$c}++; |
| 633 | } |
| 634 | } |
| 635 | } |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 636 | |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 637 | my $escape_symbols = qr { ([\x01-\x08\x0e-\x1f\x21-\x29\x2b-\x2d\x3a-\x40\x7b-\xfe]) }x; |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 638 | sub parse_existing_sysfs { |
| 639 | my $file = $File::Find::name; |
Mauro Carvalho Chehab | 0b87a1b | 2021-09-18 11:52:16 +0200 | [diff] [blame] | 640 | |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 641 | my $mode = (lstat($file))[2]; |
| 642 | my $abs_file = abs_path($file); |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 643 | |
Mauro Carvalho Chehab | 87b58c6 | 2021-09-27 15:49:50 +0200 | [diff] [blame] | 644 | my @tmp; |
| 645 | push @tmp, $file; |
| 646 | push @tmp, $abs_file if ($abs_file ne $file); |
| 647 | |
| 648 | foreach my $f(@tmp) { |
| 649 | # Ignore cgroup, as this is big and has zero docs under ABI |
| 650 | return if ($f =~ m#^/sys/fs/cgroup/#); |
| 651 | |
| 652 | # Ignore firmware as it is documented elsewhere |
| 653 | # Either ACPI or under Documentation/devicetree/bindings/ |
| 654 | return if ($f =~ m#^/sys/firmware/#); |
| 655 | |
| 656 | # Ignore some sysfs nodes that aren't actually part of ABI |
| 657 | return if ($f =~ m#/sections|notes/#); |
| 658 | |
| 659 | # Would need to check at |
| 660 | # Documentation/admin-guide/kernel-parameters.txt, but this |
| 661 | # is not easily parseable. |
| 662 | return if ($f =~ m#/parameters/#); |
| 663 | } |
| 664 | |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 665 | if (S_ISLNK($mode)) { |
| 666 | $aliases{$file} = $abs_file; |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 667 | return; |
| 668 | } |
| 669 | |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 670 | return if (S_ISDIR($mode)); |
| 671 | |
| 672 | # Trivial: file is defined exactly the same way at ABI What: |
| 673 | return if (defined($data{$file})); |
| 674 | return if (defined($data{$abs_file})); |
| 675 | |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 676 | push @files, graph_add_file($abs_file, "file"); |
| 677 | } |
| 678 | |
| 679 | sub get_leave($) |
| 680 | { |
| 681 | my $what = shift; |
| 682 | my $leave; |
| 683 | |
| 684 | my $l = $what; |
| 685 | my $stop = 1; |
| 686 | |
| 687 | $leave = $l; |
| 688 | $leave =~ s,/$,,; |
| 689 | $leave =~ s,.*/,,; |
| 690 | $leave =~ s/[\(\)]//g; |
| 691 | |
| 692 | # $leave is used to improve search performance at |
| 693 | # check_undefined_symbols, as the algorithm there can seek |
| 694 | # for a small number of "what". It also allows giving a |
| 695 | # hint about a leave with the same name somewhere else. |
| 696 | # However, there are a few occurences where the leave is |
| 697 | # either a wildcard or a number. Just group such cases |
| 698 | # altogether. |
Mauro Carvalho Chehab | 92635894 | 2021-09-23 17:41:15 +0200 | [diff] [blame] | 699 | if ($leave =~ m/\.\*/ || $leave eq "" || $leave =~ /\\d/) { |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 700 | $leave = "others"; |
| 701 | } |
| 702 | |
| 703 | return $leave; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 704 | } |
| 705 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 706 | my @not_found; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 707 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 708 | sub check_file($$) |
| 709 | { |
| 710 | my $file_ref = shift; |
| 711 | my $names_ref = shift; |
| 712 | my @names = @{$names_ref}; |
| 713 | my $file = $names[0]; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 714 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 715 | my $found_string; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 716 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 717 | my $leave = get_leave($file); |
| 718 | if (!defined($leaf{$leave})) { |
| 719 | $leave = "others"; |
| 720 | } |
| 721 | my @expr = @{$leaf{$leave}->{expr}}; |
| 722 | die ("\rmissing rules for $leave") if (!defined($leaf{$leave})); |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 723 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 724 | my $path = $file; |
| 725 | $path =~ s,(.*/).*,$1,; |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 726 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 727 | if ($search_string) { |
| 728 | return if (!($file =~ m#$search_string#)); |
| 729 | $found_string = 1; |
| 730 | } |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 731 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 732 | for (my $i = 0; $i < @names; $i++) { |
| 733 | if ($found_string && $hint) { |
| 734 | if (!$i) { |
| 735 | print STDERR "--> $names[$i]\n"; |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 736 | } else { |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 737 | print STDERR " $names[$i]\n"; |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 738 | } |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 739 | } |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 740 | foreach my $re (@expr) { |
| 741 | print STDERR "$names[$i] =~ /^$re\$/\n" if ($debug && $dbg_undefined); |
| 742 | if ($names[$i] =~ $re) { |
| 743 | return; |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | if ($leave ne "others") { |
Mauro Carvalho Chehab | 4dcce5b | 2021-09-30 11:39:59 +0200 | [diff] [blame] | 749 | my @expr = @{$leaf{"others"}->{expr}}; |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 750 | for (my $i = 0; $i < @names; $i++) { |
| 751 | foreach my $re (@expr) { |
| 752 | print STDERR "$names[$i] =~ /^$re\$/\n" if ($debug && $dbg_undefined); |
| 753 | if ($names[$i] =~ $re) { |
| 754 | return; |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | push @not_found, $file if (!$search_string || $found_string); |
| 761 | |
| 762 | if ($hint && (!$search_string || $found_string)) { |
| 763 | my $what = $leaf{$leave}->{what}; |
| 764 | $what =~ s/\xac/\n\t/g; |
| 765 | if ($leave ne "others") { |
| 766 | print STDERR "\r more likely regexes:\n\t$what\n"; |
| 767 | } else { |
| 768 | print STDERR "\r tested regexes:\n\t$what\n"; |
| 769 | } |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 770 | } |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 771 | } |
| 772 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 773 | sub check_undefined_symbols { |
| 774 | my $num_files = scalar @files; |
| 775 | my $next_i = 0; |
| 776 | my $start_time = times; |
| 777 | |
Mauro Carvalho Chehab | e5c044c | 2021-09-28 23:51:32 +0200 | [diff] [blame] | 778 | @files = sort @files; |
| 779 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 780 | my $last_time = $start_time; |
| 781 | |
| 782 | # When either debug or hint is enabled, there's no sense showing |
| 783 | # progress, as the progress will be overriden. |
| 784 | if ($hint || ($debug && $dbg_undefined)) { |
| 785 | $next_i = $num_files; |
| 786 | } |
| 787 | |
| 788 | my $is_console; |
| 789 | $is_console = 1 if (-t STDERR); |
| 790 | |
| 791 | for (my $i = 0; $i < $num_files; $i++) { |
| 792 | my $file_ref = $files[$i]; |
| 793 | my @names = @{$$file_ref{"__name"}}; |
| 794 | |
| 795 | check_file($file_ref, \@names); |
| 796 | |
| 797 | my $cur_time = times; |
| 798 | |
| 799 | if ($i == $next_i || $cur_time > $last_time + 1) { |
| 800 | my $percent = $i * 100 / $num_files; |
| 801 | |
| 802 | my $tm = $cur_time - $start_time; |
| 803 | my $time = sprintf "%d:%02d", int($tm), 60 * ($tm - int($tm)); |
| 804 | |
| 805 | printf STDERR "\33[2K\r", if ($is_console); |
| 806 | printf STDERR "%s: processing sysfs files... %i%%: $names[0]", $time, $percent; |
| 807 | printf STDERR "\n", if (!$is_console); |
| 808 | STDERR->flush(); |
| 809 | |
| 810 | $next_i = int (($percent + 1) * $num_files / 100); |
| 811 | $last_time = $cur_time; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | my $cur_time = times; |
| 816 | my $tm = $cur_time - $start_time; |
| 817 | my $time = sprintf "%d:%02d", int($tm), 60 * ($tm - int($tm)); |
| 818 | |
| 819 | printf STDERR "\33[2K\r", if ($is_console); |
| 820 | printf STDERR "%s: processing sysfs files... done\n", $time; |
| 821 | |
| 822 | foreach my $file (@not_found) { |
| 823 | print "$file not found.\n"; |
| 824 | } |
| 825 | } |
| 826 | |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 827 | sub undefined_symbols { |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 828 | print STDERR "Reading $sysfs_prefix directory contents..."; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 829 | find({ |
| 830 | wanted =>\&parse_existing_sysfs, |
| 831 | preprocess =>\&dont_parse_special_attributes, |
| 832 | no_chdir => 1 |
| 833 | }, $sysfs_prefix); |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 834 | print STDERR "done.\n"; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 835 | |
Mauro Carvalho Chehab | f34f672 | 2021-09-23 17:41:18 +0200 | [diff] [blame] | 836 | $leaf{"others"}->{what} = ""; |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 837 | |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 838 | print STDERR "Converting ABI What fields into regexes..."; |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 839 | foreach my $w (sort keys %data) { |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 840 | foreach my $what (split /\xac/,$w) { |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 841 | next if (!($what =~ m/^$sysfs_prefix/)); |
| 842 | |
| 843 | # Convert what into regular expressions |
| 844 | |
Mauro Carvalho Chehab | df2205de | 2021-09-30 11:40:00 +0200 | [diff] [blame] | 845 | # Escape dot characters |
| 846 | $what =~ s/\./\xf6/g; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 847 | |
| 848 | # Temporarily change [0-9]+ type of patterns |
| 849 | $what =~ s/\[0\-9\]\+/\xff/g; |
| 850 | |
| 851 | # Temporarily change [\d+-\d+] type of patterns |
| 852 | $what =~ s/\[0\-\d+\]/\xff/g; |
| 853 | $what =~ s/\[(\d+)\]/\xf4$1\xf5/g; |
| 854 | |
| 855 | # Temporarily change [0-9] type of patterns |
| 856 | $what =~ s/\[(\d)\-(\d)\]/\xf4$1-$2\xf5/g; |
| 857 | |
| 858 | # Handle multiple option patterns |
| 859 | $what =~ s/[\{\<\[]([\w_]+)(?:[,|]+([\w_]+)){1,}[\}\>\]]/($1|$2)/g; |
| 860 | |
| 861 | # Handle wildcards |
Mauro Carvalho Chehab | df2205de | 2021-09-30 11:40:00 +0200 | [diff] [blame] | 862 | $what =~ s,\*,.*,g; |
| 863 | $what =~ s,/\xf6..,/.*,g; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 864 | $what =~ s/\<[^\>]+\>/.*/g; |
| 865 | $what =~ s/\{[^\}]+\}/.*/g; |
| 866 | $what =~ s/\[[^\]]+\]/.*/g; |
| 867 | |
| 868 | $what =~ s/[XYZ]/.*/g; |
| 869 | |
| 870 | # Recover [0-9] type of patterns |
| 871 | $what =~ s/\xf4/[/g; |
| 872 | $what =~ s/\xf5/]/g; |
| 873 | |
| 874 | # Remove duplicated spaces |
| 875 | $what =~ s/\s+/ /g; |
| 876 | |
| 877 | # Special case: this ABI has a parenthesis on it |
| 878 | $what =~ s/sqrt\(x^2\+y^2\+z^2\)/sqrt\(x^2\+y^2\+z^2\)/; |
| 879 | |
| 880 | # Special case: drop comparition as in: |
| 881 | # What: foo = <something> |
| 882 | # (this happens on a few IIO definitions) |
| 883 | $what =~ s,\s*\=.*$,,; |
| 884 | |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 885 | # Escape all other symbols |
| 886 | $what =~ s/$escape_symbols/\\$1/g; |
| 887 | $what =~ s/\\\\/\\/g; |
| 888 | $what =~ s/\\([\[\]\(\)\|])/$1/g; |
| 889 | $what =~ s/(\d+)\\(-\d+)/$1$2/g; |
| 890 | |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 891 | $what =~ s/\xff/\\d+/g; |
| 892 | |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 893 | # Special case: IIO ABI which a parenthesis. |
| 894 | $what =~ s/sqrt(.*)/sqrt\(.*\)/; |
| 895 | |
Mauro Carvalho Chehab | df2205de | 2021-09-30 11:40:00 +0200 | [diff] [blame] | 896 | # Simplify regexes with multiple .* |
| 897 | $what =~ s#(?:\.\*){2,}##g; |
| 898 | # $what =~ s#\.\*/\.\*#.*#g; |
| 899 | |
| 900 | # Recover dot characters |
| 901 | $what =~ s/\xf6/\./g; |
| 902 | |
Mauro Carvalho Chehab | 45495db | 2021-09-23 17:41:13 +0200 | [diff] [blame] | 903 | my $leave = get_leave($what); |
Mauro Carvalho Chehab | f34f672 | 2021-09-23 17:41:18 +0200 | [diff] [blame] | 904 | |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 905 | my $added = 0; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 906 | foreach my $l (split /\|/, $leave) { |
| 907 | if (defined($leaf{$l})) { |
Mauro Carvalho Chehab | f34f672 | 2021-09-23 17:41:18 +0200 | [diff] [blame] | 908 | next if ($leaf{$l}->{what} =~ m/\b$what\b/); |
| 909 | $leaf{$l}->{what} .= "\xac" . $what; |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 910 | $added = 1; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 911 | } else { |
Mauro Carvalho Chehab | f34f672 | 2021-09-23 17:41:18 +0200 | [diff] [blame] | 912 | $leaf{$l}->{what} = $what; |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 913 | $added = 1; |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 914 | } |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 915 | } |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 916 | if ($search_string && $added) { |
Mauro Carvalho Chehab | 2833e30a | 2021-09-28 12:14:02 +0200 | [diff] [blame] | 917 | print STDERR "What: $what\n" if ($what =~ m#$search_string#); |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 918 | } |
| 919 | |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 920 | } |
| 921 | } |
Mauro Carvalho Chehab | f34f672 | 2021-09-23 17:41:18 +0200 | [diff] [blame] | 922 | # Compile regexes |
Mauro Carvalho Chehab | e5c044c | 2021-09-28 23:51:32 +0200 | [diff] [blame] | 923 | foreach my $l (sort keys %leaf) { |
Mauro Carvalho Chehab | f34f672 | 2021-09-23 17:41:18 +0200 | [diff] [blame] | 924 | my @expr; |
Mauro Carvalho Chehab | e5c044c | 2021-09-28 23:51:32 +0200 | [diff] [blame] | 925 | foreach my $w(sort split /\xac/, $leaf{$l}->{what}) { |
Mauro Carvalho Chehab | f34f672 | 2021-09-23 17:41:18 +0200 | [diff] [blame] | 926 | push @expr, qr /^$w$/; |
| 927 | } |
| 928 | $leaf{$l}->{expr} = \@expr; |
| 929 | } |
| 930 | |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 931 | # Take links into account |
Mauro Carvalho Chehab | e5c044c | 2021-09-28 23:51:32 +0200 | [diff] [blame] | 932 | foreach my $link (sort keys %aliases) { |
Mauro Carvalho Chehab | ca8e055 | 2021-09-18 11:52:17 +0200 | [diff] [blame] | 933 | my $abs_file = $aliases{$link}; |
| 934 | graph_add_link($abs_file, $link); |
| 935 | } |
Mauro Carvalho Chehab | 28331a0 | 2021-09-28 12:14:03 +0200 | [diff] [blame] | 936 | print STDERR "done.\n"; |
| 937 | |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 938 | check_undefined_symbols; |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 939 | } |
| 940 | |
Mauro Carvalho Chehab | 61439c4 | 2020-10-30 08:40:22 +0100 | [diff] [blame] | 941 | # Ensure that the prefix will always end with a slash |
| 942 | # While this is not needed for find, it makes the patch nicer |
| 943 | # with --enable-lineno |
| 944 | $prefix =~ s,/?$,/,; |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 945 | |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 946 | if ($cmd eq "undefined" || $cmd eq "search") { |
| 947 | $show_warnings = 0; |
| 948 | } |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 949 | # |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 950 | # Parses all ABI files located at $prefix dir |
| 951 | # |
| 952 | find({wanted =>\&parse_abi, no_chdir => 1}, $prefix); |
| 953 | |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 954 | print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug & $dbg_dump_abi_structs); |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 955 | |
| 956 | # |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 957 | # Handles the command |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 958 | # |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 959 | if ($cmd eq "undefined") { |
| 960 | undefined_symbols; |
| 961 | } elsif ($cmd eq "search") { |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 962 | search_symbols; |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 963 | } else { |
| 964 | if ($cmd eq "rest") { |
| 965 | output_rest; |
| 966 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 967 | |
Mauro Carvalho Chehab | c7ba333 | 2020-10-30 08:40:25 +0100 | [diff] [blame] | 968 | # Warn about duplicated ABI entries |
| 969 | foreach my $what(sort keys %symbols) { |
| 970 | my @files = @{$symbols{$what}->{file}}; |
| 971 | |
| 972 | next if (scalar(@files) == 1); |
| 973 | |
| 974 | printf STDERR "Warning: $what is defined %d times: @files\n", |
| 975 | scalar(@files); |
| 976 | } |
| 977 | } |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 978 | |
| 979 | __END__ |
| 980 | |
| 981 | =head1 NAME |
| 982 | |
| 983 | abi_book.pl - parse the Linux ABI files and produce a ReST book. |
| 984 | |
| 985 | =head1 SYNOPSIS |
| 986 | |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 987 | B<abi_book.pl> [--debug <level>] [--enable-lineno] [--man] [--help] |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 988 | [--(no-)rst-source] [--dir=<dir>] [--show-hints] |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 989 | [--search-string <regex>] |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 990 | <COMAND> [<ARGUMENT>] |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 991 | |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 992 | Where B<COMMAND> can be: |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 993 | |
| 994 | =over 8 |
| 995 | |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 996 | B<search> I<SEARCH_REGEX> - search for I<SEARCH_REGEX> inside ABI |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 997 | |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 998 | B<rest> - output the ABI in ReST markup language |
Mauro Carvalho Chehab | 7ce7b89 | 2019-06-20 14:23:04 -0300 | [diff] [blame] | 999 | |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 1000 | B<validate> - validate the ABI contents |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 1001 | |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 1002 | B<undefined> - existing symbols at the system that aren't |
| 1003 | defined at Documentation/ABI |
Mauro Carvalho Chehab | f090db4 | 2021-09-18 11:52:12 +0200 | [diff] [blame] | 1004 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 1005 | =back |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 1006 | |
| 1007 | =head1 OPTIONS |
| 1008 | |
| 1009 | =over 8 |
| 1010 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 1011 | =item B<--dir> |
| 1012 | |
| 1013 | Changes the location of the ABI search. By default, it uses |
| 1014 | the Documentation/ABI directory. |
| 1015 | |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 1016 | =item B<--rst-source> and B<--no-rst-source> |
| 1017 | |
| 1018 | The input file may be using ReST syntax or not. Those two options allow |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 1019 | selecting between a rst-compliant source ABI (B<--rst-source>), or a |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 1020 | plain text that may be violating ReST spec, so it requres some escaping |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 1021 | logic (B<--no-rst-source>). |
Mauro Carvalho Chehab | 11ce90a | 2020-10-30 08:40:20 +0100 | [diff] [blame] | 1022 | |
Mauro Carvalho Chehab | 61439c4 | 2020-10-30 08:40:22 +0100 | [diff] [blame] | 1023 | =item B<--enable-lineno> |
| 1024 | |
| 1025 | Enable output of #define LINENO lines. |
| 1026 | |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 1027 | =item B<--debug> I<debug level> |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 1028 | |
Mauro Carvalho Chehab | 46f661f | 2021-09-23 17:41:14 +0200 | [diff] [blame] | 1029 | Print debug information according with the level, which is given by the |
| 1030 | following bitmask: |
| 1031 | |
| 1032 | - 1: Debug parsing What entries from ABI files; |
| 1033 | - 2: Shows what files are opened from ABI files; |
| 1034 | - 4: Dump the structs used to store the contents of the ABI files. |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 1035 | |
Mauro Carvalho Chehab | ab02c51 | 2021-09-18 11:52:13 +0200 | [diff] [blame] | 1036 | =item B<--show-hints> |
| 1037 | |
| 1038 | Show hints about possible definitions for the missing ABI symbols. |
| 1039 | Used only when B<undefined>. |
| 1040 | |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 1041 | =item B<--search-string> I<regex string> |
Mauro Carvalho Chehab | 14c9425 | 2021-09-18 11:52:14 +0200 | [diff] [blame] | 1042 | |
| 1043 | Show only occurences that match a search string. |
| 1044 | Used only when B<undefined>. |
| 1045 | |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 1046 | =item B<--help> |
| 1047 | |
| 1048 | Prints a brief help message and exits. |
| 1049 | |
| 1050 | =item B<--man> |
| 1051 | |
| 1052 | Prints the manual page and exits. |
| 1053 | |
| 1054 | =back |
| 1055 | |
| 1056 | =head1 DESCRIPTION |
| 1057 | |
Mauro Carvalho Chehab | 33e3e99 | 2019-06-20 14:22:59 -0300 | [diff] [blame] | 1058 | Parse the Linux ABI files from ABI DIR (usually located at Documentation/ABI), |
| 1059 | allowing to search for ABI symbols or to produce a ReST book containing |
| 1060 | the Linux ABI documentation. |
| 1061 | |
| 1062 | =head1 EXAMPLES |
| 1063 | |
| 1064 | Search for all stable symbols with the word "usb": |
| 1065 | |
| 1066 | =over 8 |
| 1067 | |
| 1068 | $ scripts/get_abi.pl search usb --dir Documentation/ABI/stable |
| 1069 | |
| 1070 | =back |
| 1071 | |
| 1072 | Search for all symbols that match the regex expression "usb.*cap": |
| 1073 | |
| 1074 | =over 8 |
| 1075 | |
| 1076 | $ scripts/get_abi.pl search usb.*cap |
| 1077 | |
| 1078 | =back |
| 1079 | |
| 1080 | Output all obsoleted symbols in ReST format |
| 1081 | |
| 1082 | =over 8 |
| 1083 | |
| 1084 | $ scripts/get_abi.pl rest --dir Documentation/ABI/obsolete |
| 1085 | |
| 1086 | =back |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 1087 | |
| 1088 | =head1 BUGS |
| 1089 | |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 1090 | Report bugs to Mauro Carvalho Chehab <mchehab+huawei@kernel.org> |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 1091 | |
| 1092 | =head1 COPYRIGHT |
| 1093 | |
Mauro Carvalho Chehab | 42f0984 | 2021-09-27 15:49:51 +0200 | [diff] [blame] | 1094 | Copyright (c) 2016-2021 by Mauro Carvalho Chehab <mchehab+huawei@kernel.org>. |
Mauro Carvalho Chehab | bbc249f2 | 2019-06-20 14:22:55 -0300 | [diff] [blame] | 1095 | |
| 1096 | License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>. |
| 1097 | |
| 1098 | This is free software: you are free to change and redistribute it. |
| 1099 | There is NO WARRANTY, to the extent permitted by law. |
| 1100 | |
| 1101 | =cut |