quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

test1165.pl (5307B)


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