Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/test1165.pl
2066 views
1
#!/usr/bin/env perl
2
#***************************************************************************
3
# _ _ ____ _
4
# Project ___| | | | _ \| |
5
# / __| | | | |_) | |
6
# | (__| |_| | _ <| |___
7
# \___|\___/|_| \_\_____|
8
#
9
# Copyright (C) Daniel Stenberg, <[email protected]>, 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
27
use strict;
28
use warnings;
29
30
# the DISABLE options that can be set by configure
31
my %disable;
32
# the DISABLE options that can be set by CMakeLists.txt
33
my %disable_cmake;
34
# the DISABLE options propagated via curl_config.h.cmake
35
my %disable_cmake_config_h;
36
# the DISABLE options that are used in C files
37
my %file;
38
# the DISABLE options that are documented
39
my %docs;
40
41
# we may get the dir root pointed out
42
my $root=$ARGV[0] || ".";
43
my $DOCS="CURL-DISABLE.md";
44
45
sub 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
57
sub 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
68
sub 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
82
sub scan_cmake {
83
scanconf_cmake(\%disable_cmake, "$root/CMakeLists.txt");
84
}
85
86
sub scan_cmake_config_h {
87
scanconf_cmake(\%disable_cmake_config_h, "$root/lib/curl_config.h.cmake");
88
}
89
90
my %whitelisted = ("CURL_DISABLE_TYPECHECK" => 1);
91
92
sub scan_file {
93
my ($source)=@_;
94
open F, "<$source";
95
while(<F>) {
96
while(s/(CURL_DISABLE_[A-Z0-9_]+)//) {
97
my ($sym)=($1);
98
99
if(!$whitelisted{$sym}) {
100
$file{$sym} = $source;
101
}
102
}
103
}
104
close F;
105
}
106
107
sub scan_dir {
108
my ($dir)=@_;
109
opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
110
my @cfiles = grep { /\.[ch]\z/ && -f "$dir/$_" } readdir($dh);
111
closedir $dh;
112
for my $f (sort @cfiles) {
113
scan_file("$dir/$f");
114
}
115
}
116
117
sub scan_sources {
118
scan_dir("$root/src");
119
scan_dir("$root/lib");
120
scan_dir("$root/lib/vtls");
121
scan_dir("$root/lib/vauth");
122
}
123
124
sub scan_docs {
125
open F, "<$root/docs/$DOCS";
126
my $line = 0;
127
while(<F>) {
128
$line++;
129
if(/^## `(CURL_DISABLE_[A-Z0-9_]+)`/g) {
130
my ($sym)=($1);
131
$docs{$sym} = $line;
132
}
133
}
134
close F;
135
}
136
137
scan_configure();
138
scan_cmake();
139
scan_cmake_config_h();
140
scan_sources();
141
scan_docs();
142
143
144
my $error = 0;
145
# Check the configure symbols for use in code
146
for my $s (sort keys %disable) {
147
if(!$file{$s}) {
148
printf "Present in configure.ac, not used by code: %s\n", $s;
149
$error++;
150
}
151
if(!$docs{$s}) {
152
printf "Present in configure.ac, not documented in $DOCS: %s\n", $s;
153
$error++;
154
}
155
}
156
157
# Check the CMakeLists.txt symbols for use in code
158
for my $s (sort keys %disable_cmake) {
159
if(!$file{$s}) {
160
printf "Present in CMakeLists.txt, not used by code: %s\n", $s;
161
$error++;
162
}
163
if(!$docs{$s}) {
164
printf "Present in CMakeLists.txt, not documented in $DOCS: %s\n", $s;
165
$error++;
166
}
167
}
168
169
# Check the CMakeLists.txt symbols for use in curl_config.h.cmake
170
for my $s (sort keys %disable_cmake) {
171
if(!$disable_cmake_config_h{$s}) {
172
printf "Present in CMakeLists.txt, not propagated via curl_config.h.cmake: %s\n", $s;
173
$error++;
174
}
175
}
176
177
# Check the code symbols for use in configure
178
for my $s (sort keys %file) {
179
if(!$disable{$s}) {
180
printf "Not set by configure: %s (%s)\n", $s, $file{$s};
181
$error++;
182
}
183
if(!$disable_cmake{$s}) {
184
printf "Not set by CMakeLists.txt: %s (%s)\n", $s, $file{$s};
185
$error++;
186
}
187
if(!$docs{$s}) {
188
printf "Used in code, not documented in $DOCS: %s\n", $s;
189
$error++;
190
}
191
}
192
193
# Check the documented symbols
194
for my $s (sort keys %docs) {
195
if(!$disable{$s}) {
196
printf "Documented but not in configure: %s\n", $s;
197
$error++;
198
}
199
if(!$disable_cmake{$s}) {
200
printf "Documented but not in CMakeLists.txt: %s\n", $s;
201
$error++;
202
}
203
if(!$file{$s}) {
204
printf "Documented, but not used by code: %s\n", $s;
205
$error++;
206
}
207
}
208
209
exit $error;
210
211