test1165.pl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. use strict;
  27. use warnings;
  28. # the DISABLE options that can be set by configure
  29. my %disable;
  30. # the DISABLE options that can be set by CMakeLists.txt
  31. my %disable_cmake;
  32. # the DISABLE options that are used in C files
  33. my %file;
  34. # the DISABLE options that are documented
  35. my %docs;
  36. # we may get the dir root pointed out
  37. my $root=$ARGV[0] || ".";
  38. my $DOCS="CURL-DISABLE.md";
  39. sub scanconf {
  40. my ($f)=@_;
  41. open S, "<$f";
  42. while(<S>) {
  43. if(/(CURL_DISABLE_[A-Z_]+)/g) {
  44. my ($sym)=($1);
  45. $disable{$sym} = 1;
  46. }
  47. }
  48. close S;
  49. }
  50. sub scan_configure {
  51. opendir(my $m, "$root/m4") || die "Can't opendir $root/m4: $!";
  52. my @m4 = grep { /\.m4$/ } readdir($m);
  53. closedir $m;
  54. scanconf("$root/configure.ac");
  55. # scan all m4 files too
  56. for my $e (@m4) {
  57. scanconf("$root/m4/$e");
  58. }
  59. }
  60. sub scanconf_cmake {
  61. my ($f)=@_;
  62. open S, "<$f";
  63. while(<S>) {
  64. if(/(CURL_DISABLE_[A-Z_]+)/g) {
  65. my ($sym)=($1);
  66. if(not $sym =~ /(CURL_DISABLE_INSTALL|CURL_DISABLE_TESTS|CURL_DISABLE_SRP)/) {
  67. $disable_cmake{$sym} = 1;
  68. }
  69. }
  70. }
  71. close S;
  72. }
  73. sub scan_cmake {
  74. scanconf_cmake("$root/CMakeLists.txt");
  75. }
  76. sub scan_file {
  77. my ($source)=@_;
  78. open F, "<$source";
  79. while(<F>) {
  80. while(s/(CURL_DISABLE_[A-Z_]+)//) {
  81. my ($sym)=($1);
  82. $file{$sym} = $source;
  83. }
  84. }
  85. close F;
  86. }
  87. sub scan_dir {
  88. my ($dir)=@_;
  89. opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
  90. my @cfiles = grep { /\.[ch]\z/ && -f "$dir/$_" } readdir($dh);
  91. closedir $dh;
  92. for my $f (sort @cfiles) {
  93. scan_file("$dir/$f");
  94. }
  95. }
  96. sub scan_sources {
  97. scan_dir("$root/src");
  98. scan_dir("$root/lib");
  99. scan_dir("$root/lib/vtls");
  100. scan_dir("$root/lib/vauth");
  101. }
  102. sub scan_docs {
  103. open F, "<$root/docs/$DOCS";
  104. my $line = 0;
  105. while(<F>) {
  106. $line++;
  107. if(/^## `(CURL_DISABLE_[A-Z_]+)/g) {
  108. my ($sym)=($1);
  109. $docs{$sym} = $line;
  110. }
  111. }
  112. close F;
  113. }
  114. scan_configure();
  115. scan_cmake();
  116. scan_sources();
  117. scan_docs();
  118. my $error = 0;
  119. # Check the configure symbols for use in code
  120. for my $s (sort keys %disable) {
  121. if(!$file{$s}) {
  122. printf "Present in configure.ac, not used by code: %s\n", $s;
  123. $error++;
  124. }
  125. if(!$docs{$s}) {
  126. printf "Present in configure.ac, not documented in $DOCS: %s\n", $s;
  127. $error++;
  128. }
  129. }
  130. # Check the CMakeLists.txt symbols for use in code
  131. for my $s (sort keys %disable_cmake) {
  132. if(!$file{$s}) {
  133. printf "Present in CMakeLists.txt, not used by code: %s\n", $s;
  134. $error++;
  135. }
  136. if(!$docs{$s}) {
  137. printf "Present in CMakeLists.txt, not documented in $DOCS: %s\n", $s;
  138. $error++;
  139. }
  140. }
  141. # Check the code symbols for use in configure
  142. for my $s (sort keys %file) {
  143. if(!$disable{$s}) {
  144. printf "Not set by configure: %s (%s)\n", $s, $file{$s};
  145. $error++;
  146. }
  147. if(!$disable_cmake{$s}) {
  148. printf "Not set by CMakeLists.txt: %s (%s)\n", $s, $file{$s};
  149. $error++;
  150. }
  151. if(!$docs{$s}) {
  152. printf "Used in code, not documented in $DOCS: %s\n", $s;
  153. $error++;
  154. }
  155. }
  156. # Check the documented symbols
  157. for my $s (sort keys %docs) {
  158. if(!$disable{$s}) {
  159. printf "Documented but not in configure: %s\n", $s;
  160. $error++;
  161. }
  162. if(!$disable_cmake{$s}) {
  163. printf "Documented but not in CMakeLists.txt: %s\n", $s;
  164. $error++;
  165. }
  166. if(!$file{$s}) {
  167. printf "Documented, but not used by code: %s\n", $s;
  168. $error++;
  169. }
  170. }
  171. exit $error;