File indexing completed on 2024-04-06 12:31:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 use Getopt::Std;
0012 use File::Basename;
0013 use lib dirname($0);
0014 use SCRAMGenUtils;
0015 getopts("rv");
0016
0017 $libname = shift; chomp($libname);
0018 $tmpcache = $ENV{CMSSW_BASE}."/tmp/".$ENV{SCRAM_ARCH}."/libcheck";
0019 system("mkdir -p $tmpcache");
0020
0021
0022
0023
0024 my $LddData=&getLddData($libname,$tmpcache);
0025 foreach my $data (@$LddData) {
0026 my $AAA=$data->[0]; my $CCC=$data->[1];
0027 $ldddepmap{$AAA} = $CCC;
0028 $lddrevdepmap{$CCC} = $AAA;
0029 $lddneedmap{$AAA} = 0;
0030 $lddrevneedmap{$CCC} = 0;
0031 }
0032
0033 for my $bkey ( keys %lddrevdepmap ) {
0034 my $LddData=&getLddData($bkey,$tmpcache);
0035 foreach my $data (@$LddData) {
0036 my $AAA=$data->[0]; my $CCC=$data->[1];
0037 $lddrevneedmap{$CCC} += 1;
0038 }
0039 }
0040
0041
0042 @UNUSEDLIST = `ldd -u -r $libname`;
0043
0044
0045
0046
0047 foreach $dkey (@UNUSEDLIST) {
0048 chomp($dkey);
0049 $dkey =~ s/(^\s+|\s+$)//g;
0050 if (exists($lddrevdepmap{$dkey})) {
0051 if ($opt_v) {print "Found unneeded library => $dkey\n"};
0052 if ($lddrevneedmap{$dkey}==0) {
0053 print "Unnecessary direct dependence ".$lddrevdepmap{$dkey}."\n";
0054 }
0055 } else {
0056 if ($opt_v) {print "Reject header line => $dkey\n"};
0057 if ($opt_v) {print " With => ".$lddrevdepmap{$dkey}."\n"};
0058 }
0059 }
0060
0061 sub getLddData() {
0062 my ($lib,$cache)=@_;
0063 my $cfile=$cache."/".basename($lib);
0064 my $data=[];
0065 my $mtime=(stat($lib))[9];
0066 if ((-f $cfile) && ($mtime==(stat($cfile))[9])){$data=&SCRAMGenUtils::readHashCache($cfile);}
0067 else{
0068 my @LDDLIST = `ldd $lib`;
0069 foreach my $akey (@LDDLIST) {
0070 chomp($akey);
0071 $akey=~s/\s+\(.+\)\s*$//;
0072 if ($akey=~/^\s*\/.+/){next;}
0073 my ($AAA,$BBB,$CCC) = split(' ',$akey);
0074 if (($BBB eq "=>") && ($CCC=~/^\//) && ($AAA!~/(linux-gate\.so|linux-vdso\.so|libgcc_s.so)/)) {
0075 push @$data,[$AAA,$CCC];
0076 }
0077 }
0078 &SCRAMGenUtils::writeHashCache($data,$cfile);
0079 utime($mtime, $mtime, $cfile);
0080 }
0081 return $data;
0082 }