Ticket #2118: t_src_checkdepend_t.diff

File t_src_checkdepend_t.diff, 5.3 KB (added by jkeenan, 11 years ago)

patch will simply recognize when we don't need to check dependencies for a particular file

  • t/src/checkdepend.t

    diff --git a/t/src/checkdepend.t b/t/src/checkdepend.t
    index d7b2f10..0c2ef36 100644
    a b  
    11#! perl 
    2  
    3 # Copyright (C) 2009-2010, Parrot Foundation. 
     2# Copyright (C) 2009-2011, Parrot Foundation. 
    43 
    54use strict; 
    65use warnings; 
     
    109use File::Find; 
    1110use File::Spec; 
    1211use Test::More; 
     12use lib qw( lib ); 
     13use Parrot::Config; 
    1314 
    1415=head1 NAME 
    1516 
     
    4849    exit; 
    4950} 
    5051 
    51 my @incfiles = []; 
     52my @incfiles = (); 
    5253find( { wanted => \&wanted, no_chdir => 1 }, 
    5354      qw/src compilers include frontend/ ); 
    5455 
     
    5758foreach my $file (sort grep /\.[hc]$/, @incfiles) { 
    5859    # skip pmcs - we don't handle inheritance correctly 
    5960    next if $file =~ m{^src/(?:dyn)?pmc/}; 
     61    next if ($file eq 'src/nci/extra_thunks.c' and 
     62        ! defined $Parrot::Config::PConfig_Temp{PARROT_HAS_EXTRA_NCI_THUNKS}); 
    6063 
    6164    open my $fh, '<', $file; 
    6265    my $guts; 
     
    102105    } 
    103106} 
    104107 
     108our $rules = []; 
     109get_rules('Makefile', $rules); 
     110 
     111#expand all variables 
     112our %vars; 
     113foreach (@$rules) { 
     114    #expand any known variables 
     115    while ($_->{line} =~ /\$\(([A-Z_]+)\)/) { 
     116        my $var_name = $1; 
     117        if (exists $vars{$var_name}) { 
     118            $_->{line} =~ s/\$\($var_name\)/$vars{$var_name}/g; 
     119        } 
     120        else { 
     121            $_->{line} =~ s/\$\($var_name\)//g; 
     122        } 
     123    } 
     124 
     125    #store any new definitions 
     126    if ($_->{line} =~ /^(\w+)\s+=\s+(.*)$/) { 
     127        $vars{$1} = $2; 
     128    } 
     129} 
     130 
     131if (@ARGV && $ARGV[0] eq '--dump') { 
     132    print "$_->{line}\n" for (@$rules); 
     133    exit 0; 
     134} 
     135 
     136my $test_count = grep {/\.(c)$/} (keys %deps); 
     137plan( tests => $test_count ); 
     138 
     139my @files = keys %deps; 
     140@files = @ARGV if @ARGV; 
     141 
     142check_files($rules, \@files, '.c', $vars{O}); 
     143 
     144##### SUBROUTINES ##### 
     145 
     146sub wanted { 
     147    if ($File::Find::name =~ /\.(c|h)$/) { 
     148        push @incfiles, $File::Find::name; 
     149    } 
     150} 
     151 
    105152sub get_rules { 
    106153 
    107154    my ($filename, $rules) = @_; 
     
    129176 
    130177            # Convert all \-newline continuations into single lines for ease of 
    131178            # processing.  Leave blank lines to keep line numbers accurate. 
    132             if (exists $rules->[$escape_start]{line} && 
     179            if ( 
     180                exists $rules->[$escape_start]{line} && 
    133181                $rules->[$escape_start]{line}    !~ /\\$/ && 
    134                 $rules->[$global_line_num]{line} =~ /\\$/) { 
    135  
     182                $rules->[$global_line_num]{line} =~ /\\$/ 
     183            ) { 
    136184                $escape_start = $global_line_num; 
    137185            } 
    138186 
    139             if ($rules->[$escape_start]{line} && $rules->[$escape_start]{line} =~ /\\$/ && 
    140                 $escape_start != $global_line_num) { 
     187            if ( 
     188                $rules->[$escape_start]{line} && 
     189                $rules->[$escape_start]{line} =~ /\\$/ && 
     190                $escape_start != $global_line_num 
     191            ) { 
    141192 
    142193                $rules->[$escape_start]{line} =~ s/\\$//; 
    143                 $rules->[$escape_start]{line} .= $rules->[$global_line_num]{line}; 
     194                $rules->[$escape_start]{line} 
     195                    .= $rules->[$global_line_num]{line}; 
    144196                $rules->[$global_line_num]{line} = ''; 
    145197            } 
    146198 
     
    151203    close $mf; 
    152204} 
    153205 
    154 our $rules = []; 
    155 get_rules('Makefile', $rules); 
    156  
    157 #expand all variables 
    158 our %vars; 
    159 foreach (@$rules) { 
    160     #expand any known variables 
    161     while ($_->{line} =~ /\$\(([A-Z_]+)\)/) { 
    162         my $var_name = $1; 
    163         if (exists $vars{$var_name}) { 
    164             $_->{line} =~ s/\$\($var_name\)/$vars{$var_name}/g; 
    165         } 
    166         else { 
    167             $_->{line} =~ s/\$\($var_name\)//g; 
    168         } 
    169     } 
    170  
    171     #store any new definitions 
    172     if ($_->{line} =~ /^(\w+)\s+=\s+(.*)$/) { 
    173         $vars{$1} = $2; 
    174     } 
    175 } 
    176  
    177 if (@ARGV && $ARGV[0] eq '--dump') { 
    178     print "$_->{line}\n" for (@$rules); 
    179     exit 0; 
    180 } 
    181  
    182 my $test_count = grep {/\.(c)$/} (keys %deps); 
    183  
    184 plan( tests => $test_count ); 
    185  
    186 #foreach my $header (sort grep {/\.h$/} (keys %deps)) { 
    187 #    # static headers shouldn't depend on anything else. 
    188 #    if ($rules =~ /^$header\s*:\s*(.*)\s*$/m) { 
    189 #        #is("", $1, "$header should have no dependencies"); 
    190 #    } 
    191 #} 
    192  
    193 my @files = keys %deps; 
    194 @files = @ARGV if @ARGV; 
    195  
    196 check_files($rules, \@files, '.c', $vars{O}); 
    197  
    198206sub check_files { 
    199207 
    200208    my ($rules, $possible_files, $src_ext, $obj_ext) = @_; 
     
    227235    } 
    228236} 
    229237 
    230  
    231238sub collapse_path { 
    232239    my $path = shift; 
    233240    return $path unless defined $path; 
     
    260267            } 
    261268        } 
    262269    } 
    263  
    264270    return keys %all_deps; 
    265271} 
    266272 
    267273# I'd rather use Test::Differences, but this lets us skip a dependency. 
    268  
    269274sub is_list_same { 
    270275    my $got = shift; 
    271276    my $exp = shift; 
     
    273278 
    274279    # keep track of the number of times something appears to 
    275280    # avoid redundant includes) 
    276  
    277281    my(%got, %exp); 
    278282    for my $file (@$got) { $got{$file}++ }; 
    279283    for my $file (@$exp) { $exp{$file}++ }; 
     
    310314    return; 
    311315} 
    312316 
    313 sub wanted { 
    314     if ($File::Find::name =~ /\.(c|h)$/) { 
    315         push @incfiles, $File::Find::name; 
    316     } 
    317 } 
    318  
    319317# Local Variables: 
    320318#   mode: cperl 
    321319#   cperl-indent-level: 4