quickjs-tart

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

version-check.pl (2725B)


      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 # This script accepts a source file as input on the command line.
     27 #
     28 # It first loads the 'symbols-in-versions' document and stores a lookup
     29 # table for all known symbols for which version they were introduced.
     30 #
     31 # It then scans the given source file to dig up all symbols starting with CURL.
     32 # Finally, it sorts the internal list of found symbols (using the version
     33 # number as sort key) and then it outputs the most recent version number and
     34 # the symbols from that version that are used.
     35 #
     36 # Usage:
     37 #
     38 #    version-check.pl [source file]
     39 #
     40 
     41 open(S, "<../libcurl/symbols-in-versions") || die;
     42 
     43 my %doc;
     44 my %rem;
     45 while(<S>) {
     46     if(/(^CURL[^ \n]*) *(.*)/) {
     47         my ($sym, $rest)=($1, $2);
     48         my @a=split(/ +/, $rest);
     49 
     50         $doc{$sym}=$a[0]; # when it was introduced
     51 
     52         if($a[2]) {
     53             # this symbol is documented to have been present the last time
     54             # in this release
     55             $rem{$sym}=$a[2];
     56         }
     57     }
     58 
     59 }
     60 
     61 close(S);
     62 
     63 sub age {
     64     my ($ver)=@_;
     65 
     66     my @s=split(/\./, $ver);
     67     return $s[0]*10000+$s[1]*100+$s[2];
     68 }
     69 
     70 my %used;
     71 open(C, "<$ARGV[0]") || die;
     72 
     73 while(<C>) {
     74     if(/\W(CURL[_A-Z0-9v]+)\W/) {
     75         #print "$1\n";
     76         $used{$1}++;
     77     }
     78 }
     79 
     80 close(C);
     81 
     82 sub sortversions {
     83     my $r = age($doc{$a}) <=> age($doc{$b});
     84     if(!$r) {
     85         $r = $a cmp $b;
     86     }
     87     return $r;
     88 }
     89 
     90 my @recent = reverse sort sortversions keys %used;
     91 
     92 # the most recent symbol
     93 my $newsym = $recent[0];
     94 # the most recent version
     95 my $newver = $doc{$newsym};
     96 
     97 print "The scanned source uses these symbols introduced in $newver:\n";
     98 
     99 for my $w (@recent) {
    100     if($doc{$w} eq $newver) {
    101         printf "  $w\n";
    102         next;
    103     }
    104     last;
    105 }