2
0

test1165.pl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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-Z0-9_]+)/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-Z0-9_]+)/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-Z0-9_]+)//) {
  81. my ($sym)=($1);
  82. if(not $sym =~ /^(CURL_DISABLE_SHA512_256)/) { # Skip this symbol, to be implemented
  83. $file{$sym} = $source;
  84. }
  85. }
  86. }
  87. close F;
  88. }
  89. sub scan_dir {
  90. my ($dir)=@_;
  91. opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
  92. my @cfiles = grep { /\.[ch]\z/ && -f "$dir/$_" } readdir($dh);
  93. closedir $dh;
  94. for my $f (sort @cfiles) {
  95. scan_file("$dir/$f");
  96. }
  97. }
  98. sub scan_sources {
  99. scan_dir("$root/src");
  100. scan_dir("$root/lib");
  101. scan_dir("$root/lib/vtls");
  102. scan_dir("$root/lib/vauth");
  103. }
  104. sub scan_docs {
  105. open F, "<$root/docs/$DOCS";
  106. my $line = 0;
  107. while(<F>) {
  108. $line++;
  109. if(/^## `(CURL_DISABLE_[A-Z0-9_]+)`/g) {
  110. my ($sym)=($1);
  111. $docs{$sym} = $line;
  112. }
  113. }
  114. close F;
  115. }
  116. scan_configure();
  117. scan_cmake();
  118. scan_sources();
  119. scan_docs();
  120. my $error = 0;
  121. # Check the configure symbols for use in code
  122. for my $s (sort keys %disable) {
  123. if(!$file{$s}) {
  124. printf "Present in configure.ac, not used by code: %s\n", $s;
  125. $error++;
  126. }
  127. if(!$docs{$s}) {
  128. printf "Present in configure.ac, not documented in $DOCS: %s\n", $s;
  129. $error++;
  130. }
  131. }
  132. # Check the CMakeLists.txt symbols for use in code
  133. for my $s (sort keys %disable_cmake) {
  134. if(!$file{$s}) {
  135. printf "Present in CMakeLists.txt, not used by code: %s\n", $s;
  136. $error++;
  137. }
  138. if(!$docs{$s}) {
  139. printf "Present in CMakeLists.txt, not documented in $DOCS: %s\n", $s;
  140. $error++;
  141. }
  142. }
  143. # Check the code symbols for use in configure
  144. for my $s (sort keys %file) {
  145. if(!$disable{$s}) {
  146. printf "Not set by configure: %s (%s)\n", $s, $file{$s};
  147. $error++;
  148. }
  149. if(!$disable_cmake{$s}) {
  150. printf "Not set by CMakeLists.txt: %s (%s)\n", $s, $file{$s};
  151. $error++;
  152. }
  153. if(!$docs{$s}) {
  154. printf "Used in code, not documented in $DOCS: %s\n", $s;
  155. $error++;
  156. }
  157. }
  158. # Check the documented symbols
  159. for my $s (sort keys %docs) {
  160. if(!$disable{$s}) {
  161. printf "Documented but not in configure: %s\n", $s;
  162. $error++;
  163. }
  164. if(!$disable_cmake{$s}) {
  165. printf "Documented but not in CMakeLists.txt: %s\n", $s;
  166. $error++;
  167. }
  168. if(!$file{$s}) {
  169. printf "Documented, but not used by code: %s\n", $s;
  170. $error++;
  171. }
  172. }
  173. exit $error;