test1488.pl (3567B)
1 #!/usr/bin/env perl 2 #*************************************************************************** 3 # _ _ ____ _ 4 # Project ___| | | | _ \| | 5 # / __| | | | |_) | | 6 # | (__| |_| | _ <| |___ 7 # \___|\___/|_| \_\_____| 8 # 9 # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 10 # 11 # This software is licensed as described in the file COPYING, which 12 # you should have received as part of this distribution. The terms 13 # are also available at https://curl.se/docs/copyright.html. 14 # 15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell 16 # copies of the Software, and permit persons to whom the Software is 17 # furnished to do so, under the terms of the COPYING file. 18 # 19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20 # KIND, either express or implied. 21 # 22 # SPDX-License-Identifier: curl 23 # 24 ########################################################################### 25 # 26 # This script grew out of help from Przemyslaw Iskra and Balint Szilakszi 27 # a late evening in the #curl IRC channel. 28 # 29 30 use warnings; 31 use vars qw($Cpreprocessor); 32 use allversions; 33 34 # 35 # configurehelp perl module is generated by configure script 36 # 37 my $rc = eval { 38 require configurehelp; 39 configurehelp->import(qw( 40 $Cpreprocessor 41 )); 42 1; 43 }; 44 # Set default values if configure has not generated a configurehelp.pm file. 45 # This is the case with cmake. 46 if(!$rc) { 47 $Cpreprocessor = 'cpp'; 48 } 49 50 # we may get the dir root pointed out 51 my $root=$ARGV[0] || "."; 52 53 # need an include directory when building out-of-tree 54 my $i = ($ARGV[1]) ? "-I$ARGV[1] " : ''; 55 my $error; 56 57 my $versions = $ARGV[2]; 58 59 my @syms; 60 my %manpage; 61 my %symadded; 62 63 sub checkmanpage { 64 my ($m) = @_; 65 66 open(my $mh, "<", "$m"); 67 my $line = 1; 68 my $title; 69 my $addedin; 70 while(<$mh>) { 71 if(/^Title: (.*)/i) { 72 $title = $1; 73 } 74 elsif(/^Added-in: ([an0-9.\/]*)/i) { 75 $addedin = $1; 76 77 if(($addedin ne "n/a") && !$pastversion{$addedin}) { 78 print "$m: was added in a never released version: $addedin\n"; 79 $error++; 80 } 81 } 82 if($addedin && $title) { 83 if($manpage{$title}) { 84 print "$title is a duplicate symbol in file $m\n"; 85 $error++; 86 } 87 $manpage{$title} = $addedin; 88 last; 89 } 90 $line++; 91 } 92 close($mh); 93 } 94 95 sub scanman_md_dir { 96 my ($d) = @_; 97 opendir(my $dh, $d) || 98 die "Can't opendir: $!"; 99 my @mans = grep { /.md\z/ } readdir($dh); 100 closedir $dh; 101 for my $m (@mans) { 102 checkmanpage("$d/$m"); 103 } 104 } 105 106 # get all the past versions 107 allversions($versions); 108 109 scanman_md_dir("$root/docs/libcurl"); 110 scanman_md_dir("$root/docs/libcurl/opts"); 111 112 open my $s, "<", "$root/docs/libcurl/symbols-in-versions"; 113 while(<$s>) { 114 chomp; 115 if(/^(\S+) +([0-9.]*)/) { 116 my ($sym, $ver)=($1, $2); 117 push @syms, $sym; 118 119 $symadded{$sym}=$ver; 120 if(!$pastversion{$ver}) { 121 printf "SIV: says $sym was added in non-existing %s\n", $ver; 122 $error++; 123 } 124 } 125 } 126 close $s; 127 128 my $ignored=0; 129 for my $e (sort @syms) { 130 if($manpage{$e}) { 131 if($manpage{$e} ne $symadded{$e}) { 132 printf "%s.md says version %s, but SIV says %s\n", 133 $e, $manpage{$e}, $symadded{$e}; 134 $error++; 135 } 136 } 137 } 138 print "OK\n" if(!$error); 139 exit $error;