Changeset 3385 for branches


Ignore:
Timestamp:
May 13, 2015, 4:58:56 PM (4 years ago)
Author:
bruno
Message:
  • Fix recursivity issues for perl modules detection in mindi, including a problem in the mageia function which wasn't reporting require not starting at star t of line, even if only spaces where before
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi/mindi-get-perl-modules

    r3383 r3385  
    99use strict;
    1010
    11 use File::Find;
    1211use MondoRescue::File;
    13 
     12use Data::Dumper;
     13use File::Basename;
    1414
    1515=pod
     
    5656=cut
    5757
     58my %files;
     59my %found;
    5860
    5961my $file = mr_get_perl_modules(@ARGV) if (defined $ARGV[0]);
     
    6769sub mr_get_perl_modules {
    6870
    69 my %files;
     71my %newly_found;
    7072
    7173#print "Searching in ";
    7274#print join "\n", @INC;
    7375
    74 my $require = mr_process_file(@_);
     76my $require = mr_process_file(@_,"warnings");
     77
     78#print "Requires found:\n";
     79#print Dumper($require);
     80#print "---------------\n";
     81
     82my $cpt = keys %$require;
     83
     84# Exit recursion
     85return({}) if ($cpt == 0);
    7586
    7687my @includes;
     
    8495}
    8596
    86 find(
    87     sub {
    88         if ((-f $File::Find::name)
    89             && (/\.pm$/)
    90             && (not defined $files{$File::Find::name})) {
    91             foreach my $m (keys %$require,"warnings") {
    92                 (my $mod = $m) =~ s|::|/|g;
    93                 #print "Looking at $mod in $File::Find::name\n";
    94                 if (index($File::Find::name,"$mod.pm") ne -1) {
    95                     $files{$File::Find::name} = $mod;
    96                     #push @files, $File::Find::name;
    97                     #print "Found $mod in $File::Find::name\n";
    98                     last;
    99                 }
    100             }
    101         }
    102     },
    103     @includes);
     97foreach my $m (keys %$require) {
     98    (my $mod = $m) =~ s|::|/|g;
     99    # Already found
     100    next if (exists $found{$mod});
     101    foreach my $d (@includes) {
     102            #print "Looking at $m in $d\n";
     103        if (-f "$d/$mod.pm") {
     104            $files{"$d/$mod.pm"} = $mod;
     105            $found{$mod} = "$d/$mod.pm";
     106            $newly_found{"$d/$mod.pm"} = $mod;
     107            #print "Found $mod in $d/$mod.pm\n";
     108            last;
     109        }
     110    }
     111    print "ERROR: Unable to find $mod. Your perl setup is incorrect\n" if (not exists $found{$mod});
     112}
     113                   
     114#print "Files found:\n";
     115#print Dumper(\%files);
     116#print Dumper(\%found);
     117#print "---------------\n";
     118
     119#print "New Files found:\n";
     120#print Dumper(\%newly_found);
     121#print "---------------\n";
    104122
    105123# Recurse on what we just found
    106 my $found = mr_process_file(keys %files);
    107 find(
    108     sub {
    109         if ((-f $File::Find::name)
    110             && (/\.pm$/)
    111             && (not defined $files{$File::Find::name})) {
    112             foreach my $m (keys %$found) {
    113                 (my $mod = $m) =~ s|::|/|g;
    114                 #print "Looking at $mod in $File::Find::name\n";
    115                 if (index($File::Find::name,"$mod.pm") ne -1) {
    116                     $files{$File::Find::name} = $mod;
    117                     #push @files, $File::Find::name;
    118                     #print "Found $mod in $File::Find::name\n";
    119                     last;
    120                 }
    121             }
    122         }
    123     },
    124     @includes);
    125 
     124my $foundrec = mr_get_perl_modules(keys %newly_found);
     125
     126# Cleanup
     127foreach my $k (keys %newly_found) {
     128    delete $newly_found{$k};
     129}
     130
     131foreach my $k (sort keys %$foundrec) {
     132    if (not defined $files{$k}) {
     133        $files{$k} = $foundrec->{$k};
     134    }
     135}
    126136
    127137return(\%files);
     
    209219            # as a fallback module or a rarely used option
    210220
    211             ($whitespace ne "" && $statement eq "require") && next;
    212    
     221            ($whitespace !~ /^\s*$/ && $statement eq "require") && next;
     222   
     223            #print "*** $whitespace, $statement, $module, $version ***\n";
    213224            # if there is some interpolation of variables just skip this
    214225            # dependency, we do not want
Note: See TracChangeset for help on using the changeset viewer.