1#!/usr/bin/env perl 2#*************************************************************************** 3# _ _ ____ _ 4# Project ___| | | | _ \| | 5# / __| | | | |_) | | 6# | (__| |_| | _ <| |___ 7# \___|\___/|_| \_\_____| 8# 9# Copyright (C) 2010-2011, 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 http://curl.haxx.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########################################################################### 23# 24# This script grew out of help from Przemyslaw Iskra and Balint Szilakszi 25# a late evening in the #curl IRC channel on freenode. 26# 27 28use strict; 29use warnings; 30 31# 32# configurehelp perl module is generated by configure script 33# 34use configurehelp qw( 35 $Cpreprocessor 36 ); 37 38# we may get the dir root pointed out 39my $root=$ARGV[0] || "."; 40 41# need an include directory when building out-of-tree 42my $i = ($ARGV[1]) ? "-I$ARGV[1] " : ''; 43 44my $h = "$root/include/curl/curl.h"; 45my $mh = "$root/include/curl/multi.h"; 46 47my $verbose=0; 48my $summary=0; 49my $misses=0; 50 51my @syms; 52my %doc; 53my %rem; 54 55open H_IN, "-|", "$Cpreprocessor $i$h" || die "Cannot preprocess curl.h"; 56while ( <H_IN> ) { 57 if ( /enum\s+(\S+\s+)?{/ .. /}/ ) { 58 s/^\s+//; 59 next unless /^CURL/; 60 chomp; 61 s/[,\s].*//; 62 push @syms, $_; 63 } 64} 65close H_IN || die "Error preprocessing curl.h"; 66 67sub scanheader { 68 my ($f)=@_; 69 open H, "<$f"; 70 while(<H>) { 71 if (/^#define (CURL[A-Za-z0-9_]*)/) { 72 push @syms, $1; 73 } 74 } 75 close H; 76} 77 78scanheader($h); 79scanheader($mh); 80 81open S, "<$root/docs/libcurl/symbols-in-versions"; 82while(<S>) { 83 if(/(^CURL[^ \n]*) *(.*)/) { 84 my ($sym, $rest)=($1, $2); 85 if($doc{$sym}) { 86 print "Detected duplicate symbol: $sym\n"; 87 $misses++; 88 next; 89 } 90 $doc{$sym}=$sym; 91 my @a=split(/ +/, $rest); 92 if($a[2]) { 93 # this symbol is documented to have been present the last time 94 # in this release 95 $rem{$sym}=$a[2]; 96 } 97 } 98} 99close S; 100 101my $ignored=0; 102for my $e (sort @syms) { 103 # OBSOLETE - names that are just placeholders for a position where we 104 # previously had a name, that is now removed. The OBSOLETE names should 105 # never be used for anything. 106 # 107 # CURL_EXTERN - is a define used for libcurl functions that are external, 108 # public. No app or other code should ever use it. 109 # 110 # *_LAST and *_LASTENTRY are just prefix for the placeholders used for the 111 # last entry in many enum series. 112 # 113 114 if($e =~ /(OBSOLETE|^CURL_EXTERN|_LAST\z|_LASTENTRY\z)/) { 115 $ignored++; 116 next; 117 } 118 if($doc{$e}) { 119 if($verbose) { 120 print $e."\n"; 121 } 122 $doc{$e}="used"; 123 next; 124 } 125 else { 126 print $e."\n"; 127 $misses++; 128 } 129} 130 131# 132# now scan through all symbols that were present in the symbols-in-versions 133# but not in the headers 134# 135# If the symbols were marked 'removed' in symbols-in-versions we don't output 136# anything about it since that is perfectly fine. 137# 138 139my $anyremoved; 140 141for my $e (sort keys %doc) { 142 if(($doc{$e} ne "used") && !$rem{$e}) { 143 144 if(!$anyremoved++) { 145 print "Missing symbols mentioned in symbols-in-versions\n"; 146 print "Add them to a header, or mark them as removed.\n"; 147 } 148 149 print "$e\n"; 150 $misses++; 151 } 152} 153 154if($summary) { 155 print "Summary:\n"; 156 printf "%d symbols in headers (out of which %d are ignored)\n", scalar(@syms), 157 $ignored; 158 printf "%d symbols in headers are interesting\n", 159 scalar(@syms)- $ignored; 160 printf "%d symbols are listed in symbols-in-versions\n (out of which %d are listed as removed)\n", scalar(keys %doc), scalar(keys %rem); 161 printf "%d symbols in symbols-in-versions should match the ones in headers\n", scalar(keys %doc) - scalar(keys %rem); 162 163} 164 165if($misses) { 166 exit 2; # there are stuff to attend to! 167} 168