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