symbol-scan.pl 4.4 KB

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