disable-scan.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2010 - 2020, 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. ###########################################################################
  23. #
  24. use strict;
  25. use warnings;
  26. # the DISABLE options that can be set by configure
  27. my %disable;
  28. # the DISABLE options that are used in C files
  29. my %file;
  30. # the DISABLE options that are documented
  31. my %docs;
  32. # we may get the dir root pointed out
  33. my $root=$ARGV[0] || ".";
  34. my $DOCS="CURL-DISABLE.md";
  35. sub scan_configure {
  36. open S, "<$root/configure.ac";
  37. while(<S>) {
  38. if(/(CURL_DISABLE_[A-Z_]+)/g) {
  39. my ($sym)=($1);
  40. $disable{$sym} = 1;
  41. }
  42. }
  43. close S;
  44. }
  45. sub scan_file {
  46. my ($source)=@_;
  47. open F, "<$source";
  48. while(<F>) {
  49. if(/(CURL_DISABLE_[A-Z_]+)/g) {
  50. my ($sym)=($1);
  51. $file{$sym} = $source;
  52. }
  53. }
  54. close F;
  55. }
  56. sub scan_dir {
  57. my ($dir)=@_;
  58. opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
  59. my @cfiles = grep { /\.c\z/ && -f "$dir/$_" } readdir($dh);
  60. closedir $dh;
  61. for my $f (sort @cfiles) {
  62. scan_file("$dir/$f");
  63. }
  64. }
  65. sub scan_sources {
  66. scan_dir("$root/src");
  67. scan_dir("$root/lib");
  68. scan_dir("$root/lib/vtls");
  69. scan_dir("$root/lib/vauth");
  70. }
  71. sub scan_docs {
  72. open F, "<$root/docs/$DOCS";
  73. my $line = 0;
  74. while(<F>) {
  75. $line++;
  76. if(/^## (CURL_DISABLE_[A-Z_]+)/g) {
  77. my ($sym)=($1);
  78. $docs{$sym} = $line;
  79. }
  80. }
  81. close F;
  82. }
  83. scan_configure();
  84. scan_sources();
  85. scan_docs();
  86. my $error = 0;
  87. # Check the configure symbols for use in code
  88. for my $s (sort keys %disable) {
  89. if(!$file{$s}) {
  90. printf "Present in configure.ac, not used by code: %s\n", $s;
  91. $error++;
  92. }
  93. if(!$docs{$s}) {
  94. printf "Present in configure.ac, not documented in $DOCS: %s\n", $s;
  95. $error++;
  96. }
  97. }
  98. # Check the code symbols for use in configure
  99. for my $s (sort keys %file) {
  100. if(!$disable{$s}) {
  101. printf "Not set by configure: %s (%s)\n", $s, $file{$s};
  102. $error++;
  103. }
  104. if(!$docs{$s}) {
  105. printf "Used in code, not documented in $DOCS: %s\n", $s;
  106. $error++;
  107. }
  108. }
  109. # Check the documented symbols
  110. for my $s (sort keys %docs) {
  111. if(!$disable{$s}) {
  112. printf "Documented but not in configure: %s\n", $s;
  113. $error++;
  114. }
  115. if(!$file{$s}) {
  116. printf "Documented, but not used by code: %s\n", $s;
  117. $error++;
  118. }
  119. }
  120. exit $error;