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