| .. | .. |
|---|
| 8 | 8 | use strict; |
|---|
| 9 | 9 | use Getopt::Long qw(:config no_auto_abbrev); |
|---|
| 10 | 10 | |
|---|
| 11 | +# NOTE: only add things here when the file was gone, but the text wants |
|---|
| 12 | +# to mention a past documentation file, for example, to give credits for |
|---|
| 13 | +# the original work. |
|---|
| 14 | +my %false_positives = ( |
|---|
| 15 | + "Documentation/scsi/scsi_mid_low_api.rst" => "Documentation/Configure.help", |
|---|
| 16 | + "drivers/vhost/vhost.c" => "Documentation/virtual/lguest/lguest.c", |
|---|
| 17 | +); |
|---|
| 18 | + |
|---|
| 11 | 19 | my $scriptname = $0; |
|---|
| 12 | 20 | $scriptname =~ s,.*/([^/]+/),$1,; |
|---|
| 13 | 21 | |
|---|
| 14 | 22 | # Parse arguments |
|---|
| 15 | 23 | my $help = 0; |
|---|
| 16 | 24 | my $fix = 0; |
|---|
| 25 | +my $warn = 0; |
|---|
| 26 | + |
|---|
| 27 | +if (! -d ".git") { |
|---|
| 28 | + printf "Warning: can't check if file exists, as this is not a git tree\n"; |
|---|
| 29 | + exit 0; |
|---|
| 30 | +} |
|---|
| 17 | 31 | |
|---|
| 18 | 32 | GetOptions( |
|---|
| 19 | 33 | 'fix' => \$fix, |
|---|
| 34 | + 'warn' => \$warn, |
|---|
| 20 | 35 | 'h|help|usage' => \$help, |
|---|
| 21 | 36 | ); |
|---|
| 22 | 37 | |
|---|
| .. | .. |
|---|
| 30 | 45 | |
|---|
| 31 | 46 | my %broken_ref; |
|---|
| 32 | 47 | |
|---|
| 48 | +my $doc_fix = 0; |
|---|
| 49 | + |
|---|
| 50 | +open IN, "git grep ':doc:\`' Documentation/|" |
|---|
| 51 | + or die "Failed to run git grep"; |
|---|
| 52 | +while (<IN>) { |
|---|
| 53 | + next if (!m,^([^:]+):.*\:doc\:\`([^\`]+)\`,); |
|---|
| 54 | + next if (m,sphinx/,); |
|---|
| 55 | + |
|---|
| 56 | + my $file = $1; |
|---|
| 57 | + my $d = $1; |
|---|
| 58 | + my $doc_ref = $2; |
|---|
| 59 | + |
|---|
| 60 | + my $f = $doc_ref; |
|---|
| 61 | + |
|---|
| 62 | + $d =~ s,(.*/).*,$1,; |
|---|
| 63 | + $f =~ s,.*\<([^\>]+)\>,$1,; |
|---|
| 64 | + |
|---|
| 65 | + if ($f =~ m,^/,) { |
|---|
| 66 | + $f = "$f.rst"; |
|---|
| 67 | + $f =~ s,^/,Documentation/,; |
|---|
| 68 | + } else { |
|---|
| 69 | + $f = "$d$f.rst"; |
|---|
| 70 | + } |
|---|
| 71 | + |
|---|
| 72 | + next if (grep -e, glob("$f")); |
|---|
| 73 | + |
|---|
| 74 | + if ($fix && !$doc_fix) { |
|---|
| 75 | + print STDERR "\nWARNING: Currently, can't fix broken :doc:`` fields\n"; |
|---|
| 76 | + } |
|---|
| 77 | + $doc_fix++; |
|---|
| 78 | + |
|---|
| 79 | + print STDERR "$file: :doc:`$doc_ref`\n"; |
|---|
| 80 | +} |
|---|
| 81 | +close IN; |
|---|
| 82 | + |
|---|
| 33 | 83 | open IN, "git grep 'Documentation/'|" |
|---|
| 34 | 84 | or die "Failed to run git grep"; |
|---|
| 35 | 85 | while (<IN>) { |
|---|
| .. | .. |
|---|
| 38 | 88 | my $f = $1; |
|---|
| 39 | 89 | my $ln = $2; |
|---|
| 40 | 90 | |
|---|
| 91 | + # On linux-next, discard the Next/ directory |
|---|
| 92 | + next if ($f =~ m,^Next/,); |
|---|
| 93 | + |
|---|
| 41 | 94 | # Makefiles and scripts contain nasty expressions to parse docs |
|---|
| 42 | 95 | next if ($f =~ m/Makefile/ || $f =~ m/\.sh$/); |
|---|
| 43 | 96 | |
|---|
| 44 | 97 | # Skip this script |
|---|
| 45 | 98 | next if ($f eq $scriptname); |
|---|
| 99 | + |
|---|
| 100 | + # Ignore the dir where documentation will be built |
|---|
| 101 | + next if ($ln =~ m,\b(\S*)Documentation/output,); |
|---|
| 46 | 102 | |
|---|
| 47 | 103 | if ($ln =~ m,\b(\S*)(Documentation/[A-Za-z0-9\_\.\,\~/\*\[\]\?+-]*)(.*),) { |
|---|
| 48 | 104 | my $prefix = $1; |
|---|
| .. | .. |
|---|
| 78 | 134 | # Remove sched-pelt false-positive |
|---|
| 79 | 135 | next if ($fulref =~ m,^Documentation/scheduler/sched-pelt$,); |
|---|
| 80 | 136 | |
|---|
| 81 | | - # Discard some build examples from Documentation/target/tcm_mod_builder.txt |
|---|
| 137 | + # Discard some build examples from Documentation/target/tcm_mod_builder.rst |
|---|
| 82 | 138 | next if ($fulref =~ m,mnt/sdb/lio-core-2.6.git/Documentation/target,); |
|---|
| 83 | 139 | |
|---|
| 84 | 140 | # Check if exists, evaluating wildcards |
|---|
| .. | .. |
|---|
| 88 | 144 | if ($f =~ m/tools/) { |
|---|
| 89 | 145 | my $path = $f; |
|---|
| 90 | 146 | $path =~ s,(.*)/.*,$1,; |
|---|
| 91 | | - next if (grep -e, glob("$path/$ref $path/$fulref")); |
|---|
| 147 | + next if (grep -e, glob("$path/$ref $path/../$ref $path/$fulref")); |
|---|
| 148 | + } |
|---|
| 149 | + |
|---|
| 150 | + # Discard known false-positives |
|---|
| 151 | + if (defined($false_positives{$f})) { |
|---|
| 152 | + next if ($false_positives{$f} eq $fulref); |
|---|
| 92 | 153 | } |
|---|
| 93 | 154 | |
|---|
| 94 | 155 | if ($fix) { |
|---|
| 95 | 156 | if (!($ref =~ m/(scripts|Kconfig|Kbuild)/)) { |
|---|
| 96 | 157 | $broken_ref{$ref}++; |
|---|
| 97 | 158 | } |
|---|
| 159 | + } elsif ($warn) { |
|---|
| 160 | + print STDERR "Warning: $f references a file that doesn't exist: $fulref\n"; |
|---|
| 98 | 161 | } else { |
|---|
| 99 | 162 | print STDERR "$f: $fulref\n"; |
|---|
| 100 | 163 | } |
|---|
| 101 | 164 | } |
|---|
| 102 | 165 | } |
|---|
| 166 | +close IN; |
|---|
| 103 | 167 | |
|---|
| 104 | 168 | exit 0 if (!$fix); |
|---|
| 105 | 169 | |
|---|
| .. | .. |
|---|
| 109 | 173 | foreach my $ref (keys %broken_ref) { |
|---|
| 110 | 174 | my $new =$ref; |
|---|
| 111 | 175 | |
|---|
| 176 | + my $basedir = "."; |
|---|
| 177 | + # On translations, only seek inside the translations directory |
|---|
| 178 | + $basedir = $1 if ($ref =~ m,(Documentation/translations/[^/]+),); |
|---|
| 179 | + |
|---|
| 112 | 180 | # get just the basename |
|---|
| 113 | 181 | $new =~ s,.*/,,; |
|---|
| 114 | 182 | |
|---|
| .. | .. |
|---|
| 116 | 184 | |
|---|
| 117 | 185 | # usual reason for breakage: DT file moved around |
|---|
| 118 | 186 | if ($ref =~ /devicetree/) { |
|---|
| 119 | | - my $search = $new; |
|---|
| 120 | | - $search =~ s,^.*/,,; |
|---|
| 121 | | - $f = qx(find Documentation/devicetree/ -iname "*$search*") if ($search); |
|---|
| 187 | + # usual reason for breakage: DT file renamed to .yaml |
|---|
| 122 | 188 | if (!$f) { |
|---|
| 123 | | - # Manufacturer name may have changed |
|---|
| 124 | | - $search =~ s/^.*,//; |
|---|
| 189 | + my $new_ref = $ref; |
|---|
| 190 | + $new_ref =~ s/\.txt$/.yaml/; |
|---|
| 191 | + $f=$new_ref if (-f $new_ref); |
|---|
| 192 | + } |
|---|
| 193 | + |
|---|
| 194 | + if (!$f) { |
|---|
| 195 | + my $search = $new; |
|---|
| 196 | + $search =~ s,^.*/,,; |
|---|
| 125 | 197 | $f = qx(find Documentation/devicetree/ -iname "*$search*") if ($search); |
|---|
| 198 | + if (!$f) { |
|---|
| 199 | + # Manufacturer name may have changed |
|---|
| 200 | + $search =~ s/^.*,//; |
|---|
| 201 | + $f = qx(find Documentation/devicetree/ -iname "*$search*") if ($search); |
|---|
| 202 | + } |
|---|
| 126 | 203 | } |
|---|
| 127 | 204 | } |
|---|
| 128 | 205 | |
|---|
| 129 | 206 | # usual reason for breakage: file renamed to .rst |
|---|
| 130 | 207 | if (!$f) { |
|---|
| 131 | 208 | $new =~ s/\.txt$/.rst/; |
|---|
| 132 | | - $f=qx(find . -iname $new) if ($new); |
|---|
| 209 | + $f=qx(find $basedir -iname $new) if ($new); |
|---|
| 133 | 210 | } |
|---|
| 134 | 211 | |
|---|
| 135 | 212 | # usual reason for breakage: use dash or underline |
|---|
| 136 | 213 | if (!$f) { |
|---|
| 137 | 214 | $new =~ s/[-_]/[-_]/g; |
|---|
| 138 | | - $f=qx(find . -iname $new) if ($new); |
|---|
| 215 | + $f=qx(find $basedir -iname $new) if ($new); |
|---|
| 139 | 216 | } |
|---|
| 140 | 217 | |
|---|
| 141 | 218 | # Wild guess: seek for the same name on another place |
|---|
| 142 | 219 | if (!$f) { |
|---|
| 143 | | - $f = qx(find . -iname $new) if ($new); |
|---|
| 220 | + $f = qx(find $basedir -iname $new) if ($new); |
|---|
| 144 | 221 | } |
|---|
| 145 | 222 | |
|---|
| 146 | 223 | my @find = split /\s+/, $f; |
|---|