• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-Z_]+)/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-Z_]+)/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-Z_]+)//) {
89            my ($sym)=($1);
90            $file{$sym} = $source;
91        }
92    }
93    close F;
94}
95
96sub scan_dir {
97    my ($dir)=@_;
98    opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
99    my @cfiles = grep { /\.[ch]\z/ && -f "$dir/$_" } readdir($dh);
100    closedir $dh;
101    for my $f (sort @cfiles) {
102        scan_file("$dir/$f");
103    }
104}
105
106sub scan_sources {
107    scan_dir("$root/src");
108    scan_dir("$root/lib");
109    scan_dir("$root/lib/vtls");
110    scan_dir("$root/lib/vauth");
111}
112
113sub scan_docs {
114    open F, "<$root/docs/$DOCS";
115    my $line = 0;
116    while(<F>) {
117        $line++;
118        if(/^## `(CURL_DISABLE_[A-Z_]+)/g) {
119            my ($sym)=($1);
120            $docs{$sym} = $line;
121        }
122    }
123    close F;
124}
125
126scan_configure();
127scan_cmake();
128scan_sources();
129scan_docs();
130
131
132my $error = 0;
133# Check the configure symbols for use in code
134for my $s (sort keys %disable) {
135    if(!$file{$s}) {
136        printf "Present in configure.ac, not used by code: %s\n", $s;
137        $error++;
138    }
139    if(!$docs{$s}) {
140        printf "Present in configure.ac, not documented in $DOCS: %s\n", $s;
141        $error++;
142    }
143}
144
145# Check the CMakeLists.txt symbols for use in code
146for my $s (sort keys %disable_cmake) {
147    if(!$file{$s}) {
148        printf "Present in CMakeLists.txt, not used by code: %s\n", $s;
149        $error++;
150    }
151    if(!$docs{$s}) {
152        printf "Present in CMakeLists.txt, not documented in $DOCS: %s\n", $s;
153        $error++;
154    }
155}
156
157# Check the code symbols for use in configure
158for my $s (sort keys %file) {
159    if(!$disable{$s}) {
160        printf "Not set by configure: %s (%s)\n", $s, $file{$s};
161        $error++;
162    }
163    if(!$disable_cmake{$s}) {
164        printf "Not set by CMakeLists.txt: %s (%s)\n", $s, $file{$s};
165        $error++;
166    }
167    if(!$docs{$s}) {
168        printf "Used in code, not documented in $DOCS: %s\n", $s;
169        $error++;
170    }
171}
172
173# Check the documented symbols
174for my $s (sort keys %docs) {
175    if(!$disable{$s}) {
176        printf "Documented but not in configure: %s\n", $s;
177        $error++;
178    }
179    if(!$disable_cmake{$s}) {
180        printf "Documented but not in CMakeLists.txt: %s\n", $s;
181        $error++;
182    }
183    if(!$file{$s}) {
184        printf "Documented, but not used by code: %s\n", $s;
185        $error++;
186    }
187}
188
189exit $error;
190