d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 1) #!/usr/bin/env perl
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 2) # SPDX-License-Identifier: GPL-2.0
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 3) #
e8939222dced6 (Jani Nikula 2017-10-09 18:26:15 +0300 4) # Treewide grep for references to files under Documentation, and report
e8939222dced6 (Jani Nikula 2017-10-09 18:26:15 +0300 5) # non-existing files in stderr.
e8939222dced6 (Jani Nikula 2017-10-09 18:26:15 +0300 6)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 7) use warnings;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 8) use strict;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 9) use Getopt::Long qw(:config no_auto_abbrev);
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 10)
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 11) # NOTE: only add things here when the file was gone, but the text wants
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 12) # to mention a past documentation file, for example, to give credits for
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 13) # the original work.
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 14) my %false_positives = (
ce5c5d6503c99 (Mauro Carvalho Chehab 2020-03-02 09:16:04 +0100 15) "Documentation/scsi/scsi_mid_low_api.rst" => "Documentation/Configure.help",
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 16) "drivers/vhost/vhost.c" => "Documentation/virtual/lguest/lguest.c",
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 17) );
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 18)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 19) my $scriptname = $0;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 20) $scriptname =~ s,.*/([^/]+/),$1,;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 21)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 22) # Parse arguments
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 23) my $help = 0;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 24) my $fix = 0;
b1663d7e3a796 (Mauro Carvalho Chehab 2019-06-04 09:26:27 -0300 25) my $warn = 0;
b1663d7e3a796 (Mauro Carvalho Chehab 2019-06-04 09:26:27 -0300 26)
709dedfdf3daa (Rob Herring 2021-06-02 20:28:06 -0500 27) if (! -e ".git") {
d98dbbe0d331b (Tiezhu Yang 2020-04-14 17:41:48 +0800 28) printf "Warning: can't check if file exists, as this is not a git tree\n";
b1663d7e3a796 (Mauro Carvalho Chehab 2019-06-04 09:26:27 -0300 29) exit 0;
b1663d7e3a796 (Mauro Carvalho Chehab 2019-06-04 09:26:27 -0300 30) }
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 31)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 32) GetOptions(
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 33) 'fix' => \$fix,
b1663d7e3a796 (Mauro Carvalho Chehab 2019-06-04 09:26:27 -0300 34) 'warn' => \$warn,
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 35) 'h|help|usage' => \$help,
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 36) );
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 37)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 38) if ($help != 0) {
40fc3eb055cb3 (Mauro Carvalho Chehab 2018-06-14 07:11:02 -0300 39) print "$scriptname [--help] [--fix]\n";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 40) exit -1;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 41) }
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 42)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 43) # Step 1: find broken references
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 44) print "Finding broken references. This may take a while... " if ($fix);
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 45)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 46) my %broken_ref;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 47)
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 48) my $doc_fix = 0;
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 49)
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 50) open IN, "git grep ':doc:\`' Documentation/|"
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 51) or die "Failed to run git grep";
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 52) while (<IN>) {
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 53) next if (!m,^([^:]+):.*\:doc\:\`([^\`]+)\`,);
290d5388993eb (Mauro Carvalho Chehab 2020-02-22 10:00:01 +0100 54) next if (m,sphinx/,);
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 55)
290d5388993eb (Mauro Carvalho Chehab 2020-02-22 10:00:01 +0100 56) my $file = $1;
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 57) my $d = $1;
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 58) my $doc_ref = $2;
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 59)
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 60) my $f = $doc_ref;
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 61)
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 62) $d =~ s,(.*/).*,$1,;
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 63) $f =~ s,.*\<([^\>]+)\>,$1,;
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 64)
290d5388993eb (Mauro Carvalho Chehab 2020-02-22 10:00:01 +0100 65) if ($f =~ m,^/,) {
290d5388993eb (Mauro Carvalho Chehab 2020-02-22 10:00:01 +0100 66) $f = "$f.rst";
290d5388993eb (Mauro Carvalho Chehab 2020-02-22 10:00:01 +0100 67) $f =~ s,^/,Documentation/,;
290d5388993eb (Mauro Carvalho Chehab 2020-02-22 10:00:01 +0100 68) } else {
290d5388993eb (Mauro Carvalho Chehab 2020-02-22 10:00:01 +0100 69) $f = "$d$f.rst";
290d5388993eb (Mauro Carvalho Chehab 2020-02-22 10:00:01 +0100 70) }
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 71)
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 72) next if (grep -e, glob("$f"));
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 73)
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 74) if ($fix && !$doc_fix) {
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 75) print STDERR "\nWARNING: Currently, can't fix broken :doc:`` fields\n";
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 76) }
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 77) $doc_fix++;
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 78)
290d5388993eb (Mauro Carvalho Chehab 2020-02-22 10:00:01 +0100 79) print STDERR "$file: :doc:`$doc_ref`\n";
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 80) }
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 81) close IN;
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 82)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 83) open IN, "git grep 'Documentation/'|"
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 84) or die "Failed to run git grep";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 85) while (<IN>) {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 86) next if (!m/^([^:]+):(.*)/);
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 87)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 88) my $f = $1;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 89) my $ln = $2;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 90)
fe3e4b9c6364d (Mauro Carvalho Chehab 2019-04-22 08:42:02 -0300 91) # On linux-next, discard the Next/ directory
fe3e4b9c6364d (Mauro Carvalho Chehab 2019-04-22 08:42:02 -0300 92) next if ($f =~ m,^Next/,);
fe3e4b9c6364d (Mauro Carvalho Chehab 2019-04-22 08:42:02 -0300 93)
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 94) # Makefiles and scripts contain nasty expressions to parse docs
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 95) next if ($f =~ m/Makefile/ || $f =~ m/\.sh$/);
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 96)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 97) # Skip this script
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 98) next if ($f eq $scriptname);
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 99)
407b584d155be (Mauro Carvalho Chehab 2019-06-13 07:29:17 -0300 100) # Ignore the dir where documentation will be built
407b584d155be (Mauro Carvalho Chehab 2019-06-13 07:29:17 -0300 101) next if ($ln =~ m,\b(\S*)Documentation/output,);
407b584d155be (Mauro Carvalho Chehab 2019-06-13 07:29:17 -0300 102)
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 103) if ($ln =~ m,\b(\S*)(Documentation/[A-Za-z0-9\_\.\,\~/\*\[\]\?+-]*)(.*),) {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 104) my $prefix = $1;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 105) my $ref = $2;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 106) my $base = $2;
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 107) my $extra = $3;
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 108)
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 109) # some file references are like:
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 110) # /usr/src/linux/Documentation/DMA-{API,mapping}.txt
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 111) # For now, ignore them
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 112) next if ($extra =~ m/^{/);
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 113)
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 114) # Remove footnotes at the end like:
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 115) # Documentation/devicetree/dt-object-internal.txt[1]
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 116) $ref =~ s/(txt|rst)\[\d+]$/$1/;
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 117)
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 118) # Remove ending ']' without any '['
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 119) $ref =~ s/\].*// if (!($ref =~ m/\[/));
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 120)
2d69708f9c080 (Mauro Carvalho Chehab 2018-06-14 10:47:29 -0300 121) # Remove puntuation marks at the end
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 122) $ref =~ s/[\,\.]+$//;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 123)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 124) my $fulref = "$prefix$ref";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 125)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 126) $fulref =~ s/^(\<file|ref)://;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 127) $fulref =~ s/^[\'\`]+//;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 128) $fulref =~ s,^\$\(.*\)/,,;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 129) $base =~ s,.*/,,;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 130)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 131) # Remove URL false-positives
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 132) next if ($fulref =~ m/^http/);
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 133)
5d395fa63baa5 (Mauro Carvalho Chehab 2018-06-26 06:49:04 -0300 134) # Remove sched-pelt false-positive
5d395fa63baa5 (Mauro Carvalho Chehab 2018-06-26 06:49:04 -0300 135) next if ($fulref =~ m,^Documentation/scheduler/sched-pelt$,);
5d395fa63baa5 (Mauro Carvalho Chehab 2018-06-26 06:49:04 -0300 136)
4ca9bc225e46e (Mauro Carvalho Chehab 2019-06-12 14:52:59 -0300 137) # Discard some build examples from Documentation/target/tcm_mod_builder.rst
d25c0634441ca (Mauro Carvalho Chehab 2018-06-26 06:49:03 -0300 138) next if ($fulref =~ m,mnt/sdb/lio-core-2.6.git/Documentation/target,);
d25c0634441ca (Mauro Carvalho Chehab 2018-06-26 06:49:03 -0300 139)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 140) # Check if exists, evaluating wildcards
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 141) next if (grep -e, glob("$ref $fulref"));
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 142)
a78513c670ac5 (Mauro Carvalho Chehab 2018-06-14 11:06:08 -0300 143) # Accept relative Documentation patches for tools/
a78513c670ac5 (Mauro Carvalho Chehab 2018-06-14 11:06:08 -0300 144) if ($f =~ m/tools/) {
a78513c670ac5 (Mauro Carvalho Chehab 2018-06-14 11:06:08 -0300 145) my $path = $f;
a78513c670ac5 (Mauro Carvalho Chehab 2018-06-14 11:06:08 -0300 146) $path =~ s,(.*)/.*,$1,;
4904aeed9f686 (Mauro Carvalho Chehab 2019-05-29 20:09:29 -0300 147) next if (grep -e, glob("$path/$ref $path/../$ref $path/$fulref"));
a78513c670ac5 (Mauro Carvalho Chehab 2018-06-14 11:06:08 -0300 148) }
a78513c670ac5 (Mauro Carvalho Chehab 2018-06-14 11:06:08 -0300 149)
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 150) # Discard known false-positives
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 151) if (defined($false_positives{$f})) {
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 152) next if ($false_positives{$f} eq $fulref);
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 153) }
aeaacbfed853c (Mauro Carvalho Chehab 2019-05-29 20:09:28 -0300 154)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 155) if ($fix) {
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 156) if (!($ref =~ m/(scripts|Kconfig|Kbuild)/)) {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 157) $broken_ref{$ref}++;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 158) }
b1663d7e3a796 (Mauro Carvalho Chehab 2019-06-04 09:26:27 -0300 159) } elsif ($warn) {
b1663d7e3a796 (Mauro Carvalho Chehab 2019-06-04 09:26:27 -0300 160) print STDERR "Warning: $f references a file that doesn't exist: $fulref\n";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 161) } else {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 162) print STDERR "$f: $fulref\n";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 163) }
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 164) }
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 165) }
894ee5ff83335 (Mauro Carvalho Chehab 2019-04-24 13:25:33 -0300 166) close IN;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 167)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 168) exit 0 if (!$fix);
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 169)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 170) # Step 2: Seek for file name alternatives
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 171) print "Auto-fixing broken references. Please double-check the results\n";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 172)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 173) foreach my $ref (keys %broken_ref) {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 174) my $new =$ref;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 175)
9e78e7fc0b20b (Mauro Carvalho Chehab 2019-05-29 20:09:27 -0300 176) my $basedir = ".";
9e78e7fc0b20b (Mauro Carvalho Chehab 2019-05-29 20:09:27 -0300 177) # On translations, only seek inside the translations directory
9e78e7fc0b20b (Mauro Carvalho Chehab 2019-05-29 20:09:27 -0300 178) $basedir = $1 if ($ref =~ m,(Documentation/translations/[^/]+),);
9e78e7fc0b20b (Mauro Carvalho Chehab 2019-05-29 20:09:27 -0300 179)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 180) # get just the basename
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 181) $new =~ s,.*/,,;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 182)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 183) my $f="";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 184)
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 185) # usual reason for breakage: DT file moved around
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 186) if ($ref =~ /devicetree/) {
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 187) # usual reason for breakage: DT file renamed to .yaml
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 188) if (!$f) {
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 189) my $new_ref = $ref;
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 190) $new_ref =~ s/\.txt$/.yaml/;
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 191) $f=$new_ref if (-f $new_ref);
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 192) }
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 193)
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 194) if (!$f) {
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 195) my $search = $new;
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 196) $search =~ s,^.*/,,;
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 197) $f = qx(find Documentation/devicetree/ -iname "*$search*") if ($search);
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 198) if (!$f) {
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 199) # Manufacturer name may have changed
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 200) $search =~ s/^.*,//;
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 201) $f = qx(find Documentation/devicetree/ -iname "*$search*") if ($search);
0ca862e6f1c7e (Mauro Carvalho Chehab 2019-05-29 20:09:30 -0300 202) }
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 203) }
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 204) }
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 205)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 206) # usual reason for breakage: file renamed to .rst
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 207) if (!$f) {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 208) $new =~ s/\.txt$/.rst/;
9e78e7fc0b20b (Mauro Carvalho Chehab 2019-05-29 20:09:27 -0300 209) $f=qx(find $basedir -iname $new) if ($new);
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 210) }
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 211)
e1f319fe4d537 (Mauro Carvalho Chehab 2018-06-14 10:14:54 -0300 212) # usual reason for breakage: use dash or underline
e1f319fe4d537 (Mauro Carvalho Chehab 2018-06-14 10:14:54 -0300 213) if (!$f) {
e1f319fe4d537 (Mauro Carvalho Chehab 2018-06-14 10:14:54 -0300 214) $new =~ s/[-_]/[-_]/g;
9e78e7fc0b20b (Mauro Carvalho Chehab 2019-05-29 20:09:27 -0300 215) $f=qx(find $basedir -iname $new) if ($new);
e1f319fe4d537 (Mauro Carvalho Chehab 2018-06-14 10:14:54 -0300 216) }
e1f319fe4d537 (Mauro Carvalho Chehab 2018-06-14 10:14:54 -0300 217)
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 218) # Wild guess: seek for the same name on another place
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 219) if (!$f) {
9e78e7fc0b20b (Mauro Carvalho Chehab 2019-05-29 20:09:27 -0300 220) $f = qx(find $basedir -iname $new) if ($new);
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 221) }
be600e5ac79fb (Mauro Carvalho Chehab 2018-06-14 09:36:35 -0300 222)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 223) my @find = split /\s+/, $f;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 224)
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 225) if (!$f) {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 226) print STDERR "ERROR: Didn't find a replacement for $ref\n";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 227) } elsif (scalar(@find) > 1) {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 228) print STDERR "WARNING: Won't auto-replace, as found multiple files close to $ref:\n";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 229) foreach my $j (@find) {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 230) $j =~ s,^./,,;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 231) print STDERR " $j\n";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 232) }
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 233) } else {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 234) $f = $find[0];
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 235) $f =~ s,^./,,;
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 236) print "INFO: Replacing $ref to $f\n";
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 237) foreach my $j (qx(git grep -l $ref)) {
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 238) qx(sed "s\@$ref\@$f\@g" -i $j);
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 239) }
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 240) }
d26560950b6ba (Mauro Carvalho Chehab 2018-05-09 10:18:49 -0300 241) }