Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:01

0001 #!/usr/bin/env perl
0002 use File::Basename;
0003 use lib dirname($0);
0004 use Getopt::Long;
0005 use SCRAMGenUtils;
0006 
0007 $|=1;
0008 if(&GetOptions(
0009            "--dir=s",\$dir,
0010            "--release=s",\$rel,
0011            "--common",\$common,
0012            "--help",\$help,
0013           ) eq ""){print STDERR "#Wrong arguments.\n"; &usage_msg();}
0014 if(defined $help){&usage_msg();}
0015 if((!defined $dir) || ($dir=~/^\s*$/) || (!-d $dir)){print STDERR "Missing directory path where the newly auto generated BuildFiles exist.\n"; &usage_msg();}
0016 if((!defined $rel) || ($rel=~/^\s*$/) || (!-d $rel)){print STDERR "Missing Project release base.\n"; &usage_msg();}
0017 if(defined $common){$common=1;}
0018 else{$common=0;}
0019 $dir=&SCRAMGenUtils::fixPath($dir);
0020 my $release=&SCRAMGenUtils::scramReleaseTop(&SCRAMGenUtils::fixPath($rel));
0021 if(!-d "${release}/.SCRAM"){print STDERR "ERROR: $rel is not under a SCRAM-based project.\n"; exit 1;}
0022 &SCRAMGenUtils::init ($release);
0023 my $scram_ver=&SCRAMGenUtils::scramVersion($release);
0024 if($scram_ver=~/^V1_0_/)
0025 {
0026   print STDERR "ERROR: This version of script will only work with SCRAM versions V1_1* and above.\n";
0027   print STDERR "\"$release\" is based on SCRAM version $scram_ver.\n";
0028   exit 1;
0029 }
0030 &process($dir);
0031 exit 0;
0032 
0033 sub process ()
0034 {
0035   my $dir=shift || return;
0036   my $xml=shift || 0;
0037   if(!-d $dir){return;}
0038   my %bfs=();
0039   my $timestamp=0;
0040   foreach my $file (&SCRAMGenUtils::readDir("$dir",0))
0041   {
0042     my $fpath="${dir}/${file}";
0043     if(-d $fpath){&process($fpath,$xml);}
0044     elsif($file=~/^BuildFile(.xml|)\.auto$/){my @s=stat("${dir}/${file}");$timestamp=$s[9];}
0045     elsif($file=~/^(.+?)BuildFile(\.xml|)\.auto$/)
0046     {
0047       if($2 eq ".xml"){$xml=1;}
0048       my @s=stat("${dir}/${file}");
0049       $bfs{$file}=$s[9];
0050     }
0051   }
0052   if(scalar(keys %bfs)==0){return;}
0053   if ($timestamp)
0054   {
0055     my $new=0;
0056     foreach my $f (keys %bfs){if ($timestamp <= $bfs{$f}){$new=1;last;}}
0057     if (!$new){return;}
0058   }
0059   print "Working on $dir\n";
0060   my %commontools=();
0061   if($common)
0062   {
0063     my $flag=0;
0064     foreach my $file (keys %bfs)
0065     {
0066       if(($flag) && (scalar(keys %{$commontools{use}})==0) && (scalar(keys %{$commontools{lib}})==0)){last;}
0067       my $bf=&SCRAMGenUtils::readBuildFile("${dir}/${file}");
0068       foreach my $type ("bin", "library")
0069       {
0070         if(exists $bf->{$type})
0071         {
0072           foreach my $prod (keys %{$bf->{$type}})
0073       {
0074         my %local=();
0075         foreach my $x ("use","lib")
0076         {
0077           if(exists $bf->{$type}{$prod}{deps}{$x})
0078           {foreach my $u (keys %{$bf->{$type}{$prod}{deps}{$x}}){$local{$x}{$u}=1;}}
0079         }
0080         if($flag==0)
0081         {
0082           foreach my $x ("use","lib")
0083           {
0084             foreach my $u (keys %{$local{$x}}){$commontools{$x}{$u}=1;}
0085           }
0086           $flag=1;
0087         }
0088         else
0089         {
0090           foreach my $x ("use","lib")
0091           {foreach my $u (keys %{$commontools{$x}}){if(!exists $local{$x}{$u}){delete $commontools{$x}{$u};}}}
0092         }
0093       }
0094         }
0095       }
0096     }
0097   }
0098   my $mbf="${dir}/BuildFile.auto";
0099   if ($xml){$mbf="${dir}/BuildFile.xml.auto";}
0100   my $outfile;
0101   open($outfile,">$mbf") || die "Can not open \"$mbf\" for writing.";
0102   if($common)
0103   {
0104     foreach my $x ("use","lib")
0105     {
0106       foreach my $u (keys %{$commontools{$x}})
0107       {
0108         print $outfile "<$x name=\"$u\"";
0109         if ($xml){print $outfile "/";}
0110         print $outfile ">\n";
0111       }
0112     }
0113   }
0114   my $c=scalar(keys %bfs);
0115   print "Files:$c\n";
0116   foreach my $file (keys %bfs)
0117   {
0118     my $infile;
0119     open($infile,"${dir}/${file}") || die "Can not open \"${dir}/${file}\" for reading.";
0120     my $line="";
0121     while($line=$line || <$infile>)
0122     {
0123       chomp $line;
0124       if($common)
0125       {
0126         foreach my $x ("use","lib")
0127     {
0128       foreach my $u (keys %{$commontools{$x}})
0129           {if($line=~/^\s*<$x\s+name=\"$u\"(\/|)\s*>(.*)$/){$line=$2;}}
0130     }
0131       }
0132       if($line!~/^\s*$/){print $outfile "$line\n";$line="";}
0133     }
0134     close($infile);
0135   }
0136   close($outfile);
0137   my @s=stat($mbf);
0138   utime($s[9]+1,$s[9]+1,$mbf);
0139 }
0140           
0141 sub usage_msg() 
0142 {
0143   my $script=basename($0);
0144   print "Usage: $script --dir <dir> --release <path> [--common]\n\n";
0145   print "  --dir     <dir>   Path of the directory where the newly generated BuildFile.auto files exist.\n";
0146   print "  --release <path>  Path of SCRAM-based project release area.\n";
0147   print "  --common          To Search for common tools used by different products (library/bin) in a\n";
0148   print "                    test/bin area and add those tools once in the BuildFile.\n";
0149   exit 0;
0150 }