test1165.pl 5.1 KB

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