disable-scan.pl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 are used in C files
  31. my %file;
  32. # the DISABLE options that are documented
  33. my %docs;
  34. # we may get the dir root pointed out
  35. my $root=$ARGV[0] || ".";
  36. my $DOCS="CURL-DISABLE.md";
  37. sub scanconf {
  38. my ($f)=@_;
  39. open S, "<$f";
  40. while(<S>) {
  41. if(/(CURL_DISABLE_[A-Z_]+)/g) {
  42. my ($sym)=($1);
  43. $disable{$sym} = 1;
  44. }
  45. }
  46. close S;
  47. }
  48. sub scan_configure {
  49. opendir(my $m, "$root/m4") || die "Can't opendir $root/m4: $!";
  50. my @m4 = grep { /\.m4$/ } readdir($m);
  51. closedir $m;
  52. scanconf("$root/configure.ac");
  53. # scan all m4 files too
  54. for my $e (@m4) {
  55. scanconf("$root/m4/$e");
  56. }
  57. }
  58. sub scan_file {
  59. my ($source)=@_;
  60. open F, "<$source";
  61. while(<F>) {
  62. while(s/(CURL_DISABLE_[A-Z_]+)//) {
  63. my ($sym)=($1);
  64. $file{$sym} = $source;
  65. }
  66. }
  67. close F;
  68. }
  69. sub scan_dir {
  70. my ($dir)=@_;
  71. opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
  72. my @cfiles = grep { /\.[ch]\z/ && -f "$dir/$_" } readdir($dh);
  73. closedir $dh;
  74. for my $f (sort @cfiles) {
  75. scan_file("$dir/$f");
  76. }
  77. }
  78. sub scan_sources {
  79. scan_dir("$root/src");
  80. scan_dir("$root/lib");
  81. scan_dir("$root/lib/vtls");
  82. scan_dir("$root/lib/vauth");
  83. }
  84. sub scan_docs {
  85. open F, "<$root/docs/$DOCS";
  86. my $line = 0;
  87. while(<F>) {
  88. $line++;
  89. if(/^## `(CURL_DISABLE_[A-Z_]+)/g) {
  90. my ($sym)=($1);
  91. $docs{$sym} = $line;
  92. }
  93. }
  94. close F;
  95. }
  96. scan_configure();
  97. scan_sources();
  98. scan_docs();
  99. my $error = 0;
  100. # Check the configure symbols for use in code
  101. for my $s (sort keys %disable) {
  102. if(!$file{$s}) {
  103. printf "Present in configure.ac, not used by code: %s\n", $s;
  104. $error++;
  105. }
  106. if(!$docs{$s}) {
  107. printf "Present in configure.ac, not documented in $DOCS: %s\n", $s;
  108. $error++;
  109. }
  110. }
  111. # Check the code symbols for use in configure
  112. for my $s (sort keys %file) {
  113. if(!$disable{$s}) {
  114. printf "Not set by configure: %s (%s)\n", $s, $file{$s};
  115. $error++;
  116. }
  117. if(!$docs{$s}) {
  118. printf "Used in code, not documented in $DOCS: %s\n", $s;
  119. $error++;
  120. }
  121. }
  122. # Check the documented symbols
  123. for my $s (sort keys %docs) {
  124. if(!$disable{$s}) {
  125. printf "Documented but not in configure: %s\n", $s;
  126. $error++;
  127. }
  128. if(!$file{$s}) {
  129. printf "Documented, but not used by code: %s\n", $s;
  130. $error++;
  131. }
  132. }
  133. exit $error;