Annotation of embedaddon/curl/tests/disable-scan.pl, revision 1.1

1.1     ! misho       1: #!/usr/bin/env perl
        !             2: #***************************************************************************
        !             3: #                                  _   _ ____  _
        !             4: #  Project                     ___| | | |  _ \| |
        !             5: #                             / __| | | | |_) | |
        !             6: #                            | (__| |_| |  _ <| |___
        !             7: #                             \___|\___/|_| \_\_____|
        !             8: #
        !             9: # Copyright (C) 2010-2019, 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.haxx.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: ###########################################################################
        !            23: #
        !            24: 
        !            25: use strict;
        !            26: use warnings;
        !            27: 
        !            28: # the DISABLE options that can be set by configure
        !            29: my %disable;
        !            30: # the DISABLE options that are used in C files
        !            31: my %file;
        !            32: # the DISABLE options that are documented
        !            33: my %docs;
        !            34: 
        !            35: # we may get the dir root pointed out
        !            36: my $root=$ARGV[0] || ".";
        !            37: my $DOCS="CURL-DISABLE.md";
        !            38: 
        !            39: sub scan_configure {
        !            40:     open S, "<$root/configure.ac";
        !            41:     while(<S>) {
        !            42:         if(/(CURL_DISABLE_[A-Z_]+)/g) {
        !            43:             my ($sym)=($1);
        !            44:             $disable{$sym} = 1;
        !            45:         }
        !            46:     }
        !            47:     close S;
        !            48: }
        !            49: 
        !            50: sub scan_file {
        !            51:     my ($source)=@_;
        !            52:     open F, "<$source";
        !            53:     while(<F>) {
        !            54:         if(/(CURL_DISABLE_[A-Z_]+)/g) {
        !            55:             my ($sym)=($1);
        !            56:             $file{$sym} = $source;
        !            57:         }
        !            58:     }
        !            59:     close F;
        !            60: }
        !            61: 
        !            62: sub scan_dir {
        !            63:     my ($dir)=@_;
        !            64:     opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
        !            65:     my @cfiles = grep { /\.c\z/ && -f "$dir/$_" } readdir($dh);
        !            66:     closedir $dh;
        !            67:     for my $f (sort @cfiles) {
        !            68:         scan_file("$dir/$f");
        !            69:     }
        !            70: }
        !            71: 
        !            72: sub scan_sources {
        !            73:     scan_dir("$root/src");
        !            74:     scan_dir("$root/lib");
        !            75:     scan_dir("$root/lib/vtls");
        !            76:     scan_dir("$root/lib/vauth");
        !            77: }
        !            78: 
        !            79: sub scan_docs {
        !            80:     open F, "<$root/docs/$DOCS";
        !            81:     my $line = 0;
        !            82:     while(<F>) {
        !            83:         $line++;
        !            84:         if(/^## (CURL_DISABLE_[A-Z_]+)/g) {
        !            85:             my ($sym)=($1);
        !            86:             $docs{$sym} = $line;
        !            87:         }
        !            88:     }
        !            89:     close F;
        !            90: }
        !            91: 
        !            92: scan_configure();
        !            93: scan_sources();
        !            94: scan_docs();
        !            95: 
        !            96: 
        !            97: my $error = 0;
        !            98: # Check the configure symbols for use in code
        !            99: for my $s (sort keys %disable) {
        !           100:     if(!$file{$s}) {
        !           101:         printf "Present in configure.ac, not used by code: %s\n", $s;
        !           102:         $error++;
        !           103:     }
        !           104:     if(!$docs{$s}) {
        !           105:         printf "Present in configure.ac, not documented in $DOCS: %s\n", $s;
        !           106:         $error++;
        !           107:     }
        !           108: }
        !           109: 
        !           110: # Check the code symbols for use in configure
        !           111: for my $s (sort keys %file) {
        !           112:     if(!$disable{$s}) {
        !           113:         printf "Not set by configure: %s (%s)\n", $s, $file{$s};
        !           114:         $error++;
        !           115:     }
        !           116:     if(!$docs{$s}) {
        !           117:         printf "Used in code, not documented in $DOCS: %s\n", $s;
        !           118:         $error++;
        !           119:     }
        !           120: }
        !           121: 
        !           122: # Check the documented symbols
        !           123: for my $s (sort keys %docs) {
        !           124:     if(!$disable{$s}) {
        !           125:         printf "Documented but not in configure: %s\n", $s;
        !           126:         $error++;
        !           127:     }
        !           128:     if(!$file{$s}) {
        !           129:         printf "Documented, but not used by code: %s\n", $s;
        !           130:         $error++;
        !           131:     }
        !           132: }
        !           133: 
        !           134: exit $error;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>