Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #!/usr/bin/env perl
0002 use File::Basename;
0003 use lib dirname($0);
0004 use Getopt::Long;
0005 use SCRAMGenUtils;
0006 use FileHandle;
0007 use IPC::Open2;
0008 
0009 $|=1;
0010 
0011 #get the command-line options
0012 if(&GetOptions(
0013            "--dir=s",\$dir,
0014            "--order=s",\@packs,
0015            "--config=s",\$configfile,
0016            "--redo=s",\@prod,
0017            "--jobs=i",\$jobs,
0018            "--detail",\$detail,
0019            "--xml",\$xml,
0020            "--merge",\$merge,
0021            "--help",\$help,
0022               ) eq ""){print STDERR "#Wrong arguments.\n"; &usage_msg();}
0023 
0024 my $sdir=dirname($0);
0025 my $pwd=`/bin/pwd`; chomp $pwd; $pwd=&SCRAMGenUtils::fixPath($pwd);
0026 if ($sdir!~/^\//){$sdir=&SCRAMGenUtils::fixPath("${pwd}/${sdir}");}
0027 
0028 my $xconfig="";
0029 my $xjobs=10;
0030 if(defined $help){&usage_msg();}
0031 if(defined $detail){$detail="--detail";}
0032 if(defined $xml){$xml=1;}
0033 else{$xml=0;}
0034 if(defined $jobs){$xjobs=$jobs; $jobs="--jobs $jobs";}
0035 if(defined $configfile){$xconfig=$configfile;$configfile="--config $xconfig";}
0036 elsif(-f "${sdir}/createBuildFile.conf"){$xconfig="${sdir}/createBuildFile.conf";$configfile="--config $xconfig";}
0037 
0038 if((!defined $dir) || ($dir=~/^\s*$/)){print "ERROR: Missing SCRAM-based project release path.\n"; exit 1;}
0039 if($dir!~/^\//){$dir="${pwd}/${dir}";}
0040 $dir=&SCRAMGenUtils::fixPath($dir);
0041 my $release=&SCRAMGenUtils::scramReleaseTop($dir);
0042 if($release eq ""){print STDERR "ERROR: $dir is not under a SCRAM-based project.\n"; exit 1;}
0043 &SCRAMGenUtils::init ($release);
0044 my $scram_ver=&SCRAMGenUtils::scramVersion();
0045 if($scram_ver=~/^V1_0_/)
0046 {
0047   print STDERR "ERROR: This version of script will only work with SCRAM versions V1_1* and above.\n";
0048   print STDERR "\"$release\" is based on SCRAM version $scram_ver.\n";
0049   exit 1;
0050 }
0051 my $project=lc(&SCRAMGenUtils::getFromEnvironmentFile("SCRAM_PROJECTNAME",$release));
0052 my $releasetop=&SCRAMGenUtils::getFromEnvironmentFile("RELEASETOP",$release);
0053 if ($releasetop ne ""){system($SCRAMGenUtils::SCRAM_CMD." build -r echo_CXX 2>&1 >/dev/null");}
0054 if($project eq ""){print STDERR "ERROR: Can not find SCRAM_PROJECTNAME in ${release}.SCRAM/Environment file.\n"; exit 1;}
0055 
0056 my $scramarch=&SCRAMGenUtils::getScramArch();
0057 my $tmpdir="${release}/tmp/AutoBuildFile";
0058 my $symboldir="${release}/tmp/Symbols/${scramarch}";
0059 if($pwd!~/^$release(\/.*|)$/)
0060 {
0061   $tmpdir="${pwd}/AutoBuildFile";
0062   $symboldir="${tmpdir}/Symbols/${scramarch}";
0063 }
0064 
0065 my $data={};
0066 my $cache={};
0067 my $pcache={};
0068 my $projcache={};
0069 my $locprojcache={};
0070 my $cachedir="${tmpdir}/${scramarch}";
0071 my $depsdir="${cachedir}/new_pack_deps";
0072 my $bferrordir="${cachedir}/bferrordir";
0073 my $cfile="${cachedir}/product.cache";
0074 my $pcfile="${cachedir}/project.cache";
0075 my $xmlbf="BuildFile.xml";
0076 
0077 &SCRAMGenUtils::updateConfigFileData ($xconfig,$data);
0078 
0079 system("mkdir -p $symboldir $depsdir");
0080 &initCache($dir);
0081 
0082 foreach my $p (@prod)
0083 {
0084   if($p=~/^all$/i)
0085   {
0086     foreach $x (keys %{$cache}){delete $cache->{$x}{done};}
0087     @prod=();
0088     last;
0089   }
0090   elsif(exists $cache->{$p}){delete $cache->{$p}{done};}
0091 }
0092 foreach my $p (keys %$cache)
0093 {
0094   if((exists $pcache->{prod}{$p}) && (exists $pcache->{prod}{$p}{dir}))
0095   {
0096     my $d="${release}/src/".&SCRAMGenUtils::fixPath($pcache->{prod}{$p}{dir});
0097     if (!-d $d){$cache->{$p}{skip}=1;next;}
0098     if($d!~/^$dir(\/.*|)$/){$cache->{$p}{skip}=1;}
0099     else{delete $cache->{$p}{skip};}
0100   }
0101 }
0102 &SCRAMGenUtils::writeHashCache($cache,$cfile);
0103 
0104 foreach my $p (@packs)
0105 {
0106   foreach my $p1 (split /\s*,\s*/,$p)
0107   {
0108     if (exists $pcache->{packmap}{$p1}){$p1=$pcache->{packmap}{$p1};}
0109     else{$p1=&run_func("safename",$project,"${release}/src/${p1}");}
0110     if($p1){&processProd($p1);}
0111   }
0112 }
0113 if(scalar(@prod)==0){foreach my $f (keys %$cache){&processProd($f);}}
0114 else{foreach my $p (@prod){&processProd($p);}}
0115 if(!defined $merge){system("${sdir}/mergeProdBuildFiles.pl --release $release --dir ${tmpdir}/newBuildFile/src");}
0116 print STDERR "Path of newly generated BuildFile(s): ${tmpdir}/newBuildFile/src\n";
0117 exit 0;
0118 
0119 sub updateRevDeps ()
0120 {
0121   my $pack=shift;
0122   if (!defined $pack)
0123   {
0124     foreach my $dir (keys %{$pcache->{dir}}){&updateRevDeps($dir);}
0125     foreach my $dir (keys %{$pcache->{dir}}){delete $pcache->{dir}{$dir}{rdepsdone};delete $pcache->{dir}{$dir}{first};}
0126   }
0127   elsif ((!exists $pcache->{dir}{$pack}{rdepsdone}) && (-d "${release}/src/${pack}"))
0128   {
0129     $pcache->{dir}{$pack}{rdeps}={};
0130     $pcache->{dir}{$pack}{rdepsdone}=1;
0131     if (exists $pcache->{dir}{$pack}{deps})
0132     {
0133       foreach my $dep (keys %{$pcache->{dir}{$pack}{deps}})
0134       {
0135         &updateRevDeps($dep);
0136     if (exists $pcache->{dir}{$dep}{rdeps}){$pcache->{dir}{$dep}{rdeps}{$pack}=1;}
0137       }
0138     }
0139   }
0140 }
0141 
0142 sub initCache ()
0143 {
0144   my $dir=shift || "";
0145   if((-f $cfile) && (-f $pcfile) && (-f "${symboldir}.SymbolsCache.db"))
0146   {
0147     $cache=&SCRAMGenUtils::readHashCache($cfile);
0148     $pcache=&SCRAMGenUtils::readHashCache($pcfile);
0149     if (-d $depsdir)
0150     {
0151       my $ref;
0152       my $dirty=0;
0153       opendir ($ref,$depsdir) || die "Can not open directory for reading:$depsdir\n";
0154       foreach my $prod (readdir($ref))
0155       {
0156         if (($prod=~/^\./) || (!exists $pcache->{prod}{$prod})){next;}
0157     my $pk=$pcache->{prod}{$prod}{dir};
0158     $prod="${depsdir}/${prod}";
0159     my $c=&SCRAMGenUtils::readHashCache($prod);
0160     delete $c->{rdeps};delete $c->{rdepsdone};delete $c->{first};
0161     if (!exists $pcache->{dir}{$pk}{first}){$pcache->{dir}{$pk}=$c;$pcache->{dir}{$pk}{first}=1;}
0162     else
0163     {
0164       foreach my $k (keys %$c)
0165       {
0166         my $v=$c->{$k};
0167         if (ref($v) eq "HASH"){foreach my $k1 (keys %$v){$pcache->{dir}{$pk}{$k}{$k1}=$v->{$k1};}}
0168         else{$pcache->{dir}{$pk}{$k}=$v;}
0169       }
0170     }
0171     $dirty=1;
0172     unlink $prod;
0173       }
0174       closedir($ref);
0175       if($dirty)
0176       {
0177         &updateRevDeps();
0178     &SCRAMGenUtils::writeHashCache($pcache,$pcfile);
0179       }
0180     }
0181     $data->{ALL_SYMBOLS}=&SCRAMGenUtils::readHashCache("${symboldir}.SymbolsCache.db");
0182     foreach my $p (keys %$cache){if((exists $cache->{$p}{done}) && ($cache->{$p}{done}==0)){delete $cache->{$p}{done};}}
0183   }
0184   else
0185   {
0186     print STDERR "Initializing project caches and shared libs symbols information. It will take few mins.\n";
0187     my $tcache={};
0188     $cf=&SCRAMGenUtils::fixCacheFileName("${release}/.SCRAM/${scramarch}/ToolCache.db");
0189     if (-f $cf)
0190     {
0191       $tcache=&SCRAMGenUtils::readCache($cf);
0192       &addToolDep($tcache);
0193     }
0194     else{print STDERR "$cf file does not exists. Script need this to be available.\n"; exit 1;}
0195     
0196     if ($releasetop ne "")
0197     {
0198       my $cf=&SCRAMGenUtils::fixCacheFileName("${releasetop}/.SCRAM/${scramarch}/ProjectCache.db");
0199       if (-f $cf){$projcache=&SCRAMGenUtils::readCache($cf);}
0200       else{print STDERR "$cf file does not exists. Script need this to be available.\n"; exit 1;}
0201     }
0202     
0203     my $cf=&SCRAMGenUtils::fixCacheFileName("${release}/.SCRAM/${scramarch}/ProjectCache.db");
0204     if (!-f $cf){system("cd $release; scram b -r echo_CXX xfast 2>&1 >/dev/null");}
0205     $locprojcache=&SCRAMGenUtils::readCache($cf);
0206     foreach my $d (keys %{$locprojcache->{BUILDTREE}}){$projcache->{BUILDTREE}{$d}=$locprojcache->{BUILDTREE}{$d};}
0207     &addPackDep ($projcache);
0208     &updateRevDeps();
0209     
0210     &SCRAMGenUtils::scramToolSymbolCache($tcache,"self",$symboldir,$xjobs,$pcache->{packmap});
0211     &SCRAMGenUtils::waitForChild();
0212     print STDERR "\n";
0213     $data->{ALL_SYMBOLS}=&SCRAMGenUtils::mergeSymbols($symboldir,"${symboldir}.SymbolsCache.db");
0214     foreach my $d (reverse sort keys %{$projcache->{BUILDTREE}}){&updateProd($d);}
0215     $projcache={};
0216     $locprojcache={};
0217     &SCRAMGenUtils::writeHashCache($cache,$cfile);
0218     &SCRAMGenUtils::writeHashCache($pcache,$pcfile);
0219   }
0220 }
0221 
0222 sub updateProd ()
0223 {
0224   my $p=shift;
0225   if(exists $projcache->{BUILDTREE}{$p}{CLASS} && (exists $projcache->{BUILDTREE}{$p}{RAWDATA}{content}))
0226   {
0227     my $suffix=$projcache->{BUILDTREE}{$p}{SUFFIX};
0228     if($suffix ne ""){return 0;}
0229     my $class=$projcache->{BUILDTREE}{$p}{CLASS};
0230     my $c=$projcache->{BUILDTREE}{$p}{RAWDATA}{content};
0231     if($class=~/^(LIBRARY|CLASSLIB|SEAL_PLATFORM)$/){return &addPack($projcache->{BUILDTREE}{$p}{NAME},dirname($p));}
0232     elsif($class eq "PACKAGE"){return &addPack($projcache->{BUILDTREE}{$p}{NAME},$p);}
0233     elsif($class=~/^(TEST|BIN|PLUGINS|BINARY)$/){return &addProds($c,$p);}
0234   }
0235   return 0;
0236 }
0237 
0238 sub addProds ()
0239 {
0240   my $c=shift;
0241   my $p=shift;
0242   if (exists $pcache->{dir}{$p}{bf}){return;}
0243   my $bf1=&getBuildFile($p);
0244   $pcache->{dir}{$p}{bf}=basename($bf1);
0245   if($bf1 eq ""){return 0}
0246   my $bf=undef;
0247   foreach my $t (keys %{$c->{BUILDPRODUCTS}})
0248   {
0249     foreach my $prod (keys %{$c->{BUILDPRODUCTS}{$t}})
0250     {
0251       if($prod=~/^\s*$/){next;}
0252       my $xname=basename($prod);
0253       my $name=$xname;
0254       my $type=lc($t);
0255       if(exists $pcache->{prod}{$name})
0256       {
0257     $name="DPN_${xname}";
0258     my $i=0;
0259     while(exists $pcache->{prod}{$name}){$name="DPN${i}_${xname}";$i++;}
0260     my $d1=$pcache->{prod}{$xname}{dir};
0261     my $pbf="${d1}/".$pcache->{dir}{$d1}{bf};
0262     print STDERR "WARNING: \"$bf1\" has a product \"$xname\" which is already defined in \"$pbf\". Going to change it to \"$name\".\n";
0263       }
0264       $pcache->{prod}{$name}{dir}=$p;
0265       $pcache->{prod}{$name}{type}=$type;
0266       if (!defined $bf){$bf=&SCRAMGenUtils::readBuildFile($bf1);}
0267       if((exists $bf->{$type}{$xname}) && (exists $bf->{$type}{$xname}{file}))
0268       {
0269         my $files="";
0270     foreach my $f (@{$bf->{$type}{$xname}{file}}){$files.="$f,";}
0271     $files=~s/\,$//;
0272     if($files ne ""){$pcache->{prod}{$name}{file}=$files;}
0273       }
0274       $cache->{$name}={};
0275     }
0276   }
0277 }
0278 
0279 sub getBuildFile ()
0280 {
0281   my $pack=shift;
0282   my $bf="${release}/src/${pack}/BuildFile.xml";
0283   if(!-f $bf){$bf="${release}/src/${pack}/BuildFile";}
0284   if(!-f $bf){$bf="";}
0285   return $bf;
0286 }
0287 
0288 sub addPack ()
0289 {
0290   my $prod=shift;
0291   my $dir=shift;
0292   if (exists $pcache->{dir}{$dir}{bf}){return;}
0293   $pcache->{dir}{$dir}{bf}=basename(&getBuildFile($dir));
0294   $pcache->{prod}{$prod}{dir}=$dir;
0295   $cache->{$prod}={};
0296   return 1;
0297 }
0298 
0299 sub addToolDep ()
0300 {
0301   my $tools=shift;
0302   my $t=shift;
0303   if (!defined $t)
0304   {
0305     foreach $t (&SCRAMGenUtils::getOrderedTools($tools)){&addToolDep($tools,$t);}
0306     return;
0307   }
0308   if (exists $pcache->{tools}{$t}{deps}){return;}
0309   $pcache->{tools}{$t}{deps}={};
0310   my $c=$pcache->{tools}{$t}{deps};
0311   if (($t ne "self") && ((exists $tools->{SETUP}{$t}{SCRAM_PROJECT}) && ($tools->{SETUP}{$t}{SCRAM_PROJECT}==1)))
0312   {
0313     my $base=uc("${t}_BASE");
0314     if(exists $tools->{SETUP}{$t}{$base}){$base=$tools->{SETUP}{$t}{$base};}
0315     if(-d $base)
0316     {
0317       my $cf=&SCRAMGenUtils::fixCacheFileName("${base}/.SCRAM/${scramarch}/ProjectCache.db");
0318       if (-f $cf){&addPackDep(&SCRAMGenUtils::readCache($cf));}
0319     }
0320     &SCRAMGenUtils::scramToolSymbolCache($tools,$t,$symboldir,$xjobs,$pcache->{packmap});
0321   }
0322   else{&SCRAMGenUtils::toolSymbolCache($tools,$t,$symboldir,$xjobs);}
0323   if (!exists $tools->{SETUP}{$t}{USE}){return;}
0324   foreach my $u (@{$tools->{SETUP}{$t}{USE}})
0325   {
0326     $u=lc($u);
0327     if(exists $tools->{SETUP}{$u})
0328     {
0329       &addToolDep($tools,$u);
0330       $c->{$u}=1;
0331       foreach my $k (keys %{$pcache->{tools}{$u}{deps}}){$c->{$k}=1;}
0332     }
0333   }
0334 }
0335 
0336 sub addPackDep ()
0337 {
0338   my $cache=shift;
0339   my $p=shift;
0340   if (!defined $p)
0341   {
0342     my @packs=();
0343     foreach $p (keys %{$cache->{BUILDTREE}})
0344     {
0345       my $c=$cache->{BUILDTREE}{$p};
0346       my $suffix=$c->{SUFFIX};
0347       if($suffix ne ""){next;}
0348       my $class=$c->{CLASS};
0349       if($class=~/^(LIBRARY|CLASSLIB|SEAL_PLATFORM)$/)
0350       {
0351         my $pack=$c->{PARENT};
0352     $pcache->{packmap}{$pack}=$c->{NAME};
0353     &addPackDep($cache,$c,$pack);
0354       }
0355       elsif($class eq "PACKAGE"){push @packs,$p;}
0356       elsif($class=~/^(TEST|BIN|PLUGINS|BINARY)$/){&addPackDep($cache,$c,$p);}
0357     }
0358     foreach my $p (@packs){&addPackDep($cache,$cache->{BUILDTREE}{$p},$p);}
0359     return;
0360   }
0361   my $n=shift;
0362   if (exists $pcache->{dir}{$n}{deps}){return;}
0363   $pcache->{dir}{$n}{deps}={};
0364   if((!exists $p->{RAWDATA}) || (!exists $p->{RAWDATA}{DEPENDENCIES})){return;}
0365   my $c=$pcache->{dir}{$n}{deps};
0366   foreach my $u (keys %{$p->{RAWDATA}{DEPENDENCIES}})
0367   {
0368     my $t=lc($u);
0369     if ((exists $pcache->{tools}{$t}) && (exists $pcache->{tools}{$t}{deps}))
0370     {
0371       $c->{$t}=1;
0372       foreach my $k (keys %{$pcache->{tools}{$t}{deps}}){$c->{$k}=1;}
0373     }
0374     else
0375     {
0376       if (exists $cache->{BUILDTREE}{"${u}/src"}){&addPackDep($cache,$cache->{BUILDTREE}{"${u}/src"},$u);}
0377       elsif(exists $cache->{BUILDTREE}{$u}){&addPackDep($cache,$cache->{BUILDTREE}{$u},$u);}
0378       $c->{$u}=1;
0379       foreach my $k (keys %{$pcache->{dir}{$u}{deps}}){$c->{$k}=1;}
0380     }
0381   }
0382 }
0383 
0384 sub processProd ()
0385 {
0386   my $prod=shift;
0387   if ((!exists $cache->{$prod}) || (exists $cache->{$prod}{skip}) || (exists $cache->{$prod}{done})){return;}
0388   $cache->{$prod}{done}=0;
0389   my $pack=$pcache->{prod}{$prod}{dir};
0390   if ($pack eq ""){return 0;}
0391   my $bfn=$pcache->{dir}{$pack}{bf};
0392   my $pc=$pcache->{dir}{$pack};
0393   if(exists $pc->{deps})
0394   {
0395     foreach my $u (keys %{$pc->{deps}})
0396     {
0397       if(exists $pcache->{dir}{$u})
0398       {
0399         my $u1="";
0400     if (exists $pcache->{packmap}{$u}){$u1=$pcache->{packmap}{$u};}
0401     else{$u1=&run_func("safename",$project,"${release}/src/${u}");}
0402         if($u1 ne ""){&processProd($u1);}
0403       }
0404     }
0405   }
0406   my $nexport="${cachedir}/${prod}no-export";
0407   if(exists $pc->{rdeps})
0408   {
0409     my @nuse=();
0410     foreach my $u (keys %{$pc->{rdeps}}){push @nuse,$u;}
0411     if(scalar(@nuse) > 0)
0412     {
0413       my $nfile;
0414       open($nfile, ">$nexport") || die "Can not open file \"$nexport\" for writing.";
0415       foreach my $u (@nuse){print $nfile "$u\n";}
0416       close($nfile);
0417     }
0418   }
0419   elsif(-f "$nexport"){system("rm -f $nexport");}
0420 
0421   my $bfdir="${tmpdir}/newBuildFile/src/${pack}";
0422   system("mkdir -p $bfdir");
0423   my $nfile="${bfdir}/${bfn}.auto";
0424   my $ptype="";my $pname="";my $pfiles=""; my $xargs="";
0425   if ($xml || ($bfn=~/\.xml$/)){$nfile="${bfdir}/${xmlbf}.auto"; $xargs.=" --xml";}
0426   if(exists $pcache->{prod}{$prod}{type})
0427   {
0428     $ptype="--prodtype ".$pcache->{prod}{$prod}{type};
0429     $pname="--prodname $prod --files '".$pcache->{prod}{$prod}{file}."'";
0430     $nfile="${bfdir}/${prod}${bfn}.auto";
0431     if ($xml){$nfile="${bfdir}/${prod}${xmlbf}.auto";}
0432   }
0433   else{$pname="--prodname $prod";}
0434   my $cmd="${sdir}/_createBuildFile.pl $xargs $configfile --dir ${release}/src/${pack} --tmpdir $tmpdir $jobs --buildfile $nfile $ptype $pname $pfiles $detail";
0435   &processCMD($pack,$cmd);
0436   if(-f $nfile)
0437   {
0438     $cache->{$prod}{done}=1;
0439     &updateActualPackDeps($prod,$pack,$nfile);
0440     &SCRAMGenUtils::writeHashCache($cache,$cfile);
0441   }
0442   if(-f "$nexport"){system("rm -f $nexport");}
0443   print STDERR "##########################################################################\n";
0444 }
0445 
0446 sub updateActualPackDeps ()
0447 {
0448   my $prod=shift;
0449   my $pack=shift;
0450   my $d={};
0451   $d->{prodname}=$prod;
0452   if ((exists $pcache->{prod}{$prod}) && (exists $pcache->{prod}{$prod}{type})){$d->{prodtype}=$pcache->{prod}{$prod}{type};}
0453   my $prev="";
0454   if (!exists $pcache->{dir}{$pack}{first})
0455   {
0456     $pcache->{dir}{$pack}{deps}={};
0457     delete $pcache->{dir}{$pack}{rdeps};
0458   }
0459   else{$prev=$pcache->{dir}{$pack}{first};}
0460   my $bf=&SCRAMGenUtils::readBuildFile(shift);
0461   my $flags=&SCRAMGenUtils::findBuildFileTag($d,$bf,"flags");
0462   my $edm="";
0463   foreach my $a (keys %$flags)
0464   {
0465     foreach my $c (@{$flags->{$a}})
0466     {
0467       if (exists $c->{flags}{EDM_PLUGIN}){foreach my $v (@{$c->{flags}{EDM_PLUGIN}}){if($v->{v}==1){$edm="edm";last;}}}
0468       if ($edm){last;}
0469     }
0470     if ($edm){last;}
0471   }
0472   if ($edm){$pcache->{dir}{$pack}{plugin}=$edm;}
0473   my $use=&SCRAMGenUtils::findBuildFileTag($d,$bf,"use");
0474   foreach my $a (keys %$use)
0475   {
0476     foreach my $c (@{$use->{$a}})
0477     {
0478       foreach my $d (keys %{$c->{use}})
0479       { 
0480         $pcache->{dir}{$pack}{deps}{$d}=1;
0481     if((exists $pcache->{tools}{$d}) && (exists $pcache->{tools}{$d}{deps}))
0482     {foreach my $d1 (keys %{$pcache->{tools}{$d}{deps}}){$pcache->{dir}{$pack}{deps}{$d1}=1;}}
0483     elsif((exists $pcache->{dir}{$d}) && (exists $pcache->{dir}{$d}{deps}))
0484     {foreach my $d1 (keys %{$pcache->{dir}{$d}{deps}}){$pcache->{dir}{$pack}{deps}{$d1}=1;}}
0485       }
0486     }
0487   }
0488   delete $pcache->{dir}{$pack}{first};
0489   &SCRAMGenUtils::writeHashCache($pcache->{dir}{$pack},"${depsdir}/${prod}");
0490   if (($prev) && (-f "${depsdir}/${prev}")){unlink "${depsdir}/${prev}";}
0491   $pcache->{dir}{$pack}{first}=$prod;
0492 }
0493 
0494 sub processCMD ()
0495 {
0496   my $pack=shift;
0497   my $cmd=shift;
0498   print "$cmd\n";
0499   my $reader; my $writer;
0500   my $pid=open2($reader, $writer,"$cmd 2>&1");
0501   $writer->autoflush();
0502   while(my $line=<$reader>)
0503   {
0504     chomp $line;
0505     if ($line=~/^([^:]+):(.*)$/)
0506     {
0507       my $req=$1;
0508       my $func="processRequest_${req}";
0509       if(exists &$func){print $writer "${req}_DONE:",&$func($2,$pack),"\n";}
0510       else{print "$line\n";}
0511     }
0512     else{print "$line\n";}
0513   }
0514   close($reader); close($writer);
0515   waitpid $pid,0;
0516 }
0517 
0518 sub processRequest_EXIT ()
0519 {
0520   print STDERR "EXIT Requested\n";
0521   exit 0;
0522 }
0523 
0524 sub processRequest_HAVE_DEPS ()
0525 {
0526   my $line=shift;
0527   my $rep="NO";
0528   if($line=~/^([^:]+):(.+)$/)
0529   {
0530     my $packs=$1; my $tool=$2;
0531     my %tools=();
0532     foreach my $pack (split /,/,$packs)
0533     {
0534       if (($pack eq "") || ($pack eq $tool)){next;}
0535       $tools{$pack}=1;
0536     }
0537     $packs=&hasDependency($tool,\%tools);
0538     if($packs){$rep="YES:$packs";}
0539   }
0540   return $rep;
0541 }
0542 
0543 sub hasDependency ()
0544 {
0545   my $tool=shift;
0546   my $tools=shift;
0547   foreach my $d (keys %$tools)
0548   {
0549     if ($d eq $tool){next;}
0550     if((exists $pcache->{tools}{$d}) && (exists $pcache->{tools}{$d}{deps}{$tool})){return $d;}
0551     elsif(exists $pcache->{dir}{$d})
0552     {
0553       if((exists $pcache->{dir}{$d}{plugin}) && ($pcache->{dir}{$d}{plugin} eq "edm")){next;}
0554       elsif(exists $pcache->{dir}{$d}{deps}{$tool}){return $d;}
0555     }
0556   }
0557   return "";
0558 }
0559 
0560 sub processRequest_PLEASE_PROCESS_FIRST ()
0561 {
0562   my $u=shift;
0563   print STDERR "REQUEST: Process package $u\n";
0564   my $pack=shift;
0565   my $u1="";
0566   if (exists $pcache->{packmap}{$u}){$u1=$pcache->{packmap}{$u};}
0567   else{$u1=&run_func("safename",$project,"${release}/src/${u}");}
0568   if ($u1 ne "")
0569   {
0570     if ((!exists $cache->{$u1}) && (-d "${release}/src/${u}"))
0571     {
0572       $cache->{$u1}={};
0573       $pcache->{prod}{$u1}{dir}=$u;
0574       my $bf="BuildFile";
0575       if (-f "${release}/src/${u}/${bf}.xml"){$bf="BuildFile.xml";}
0576       $pcache->{dir}{$u}{bf}=$bf;
0577     }
0578   }
0579   if(($u1 ne "") && (exists $cache->{$u1}))
0580   {
0581     my $pc=$pcache->{dir}{$pack};
0582     print "New Dependency added: $pack => $u\n";
0583     $pc->{deps}{$u}=1;
0584     $pcache->{dir}{$u}{rdeps}{$pack}=1;
0585     foreach my $x (keys %{$pc->{rdeps}}){$pcache->{dir}{$u}{rdeps}{$x}=1;}
0586     &processProd($u1);
0587   }
0588   return $u;
0589 }
0590 
0591 sub processRequest_PRODUCT_INFO ()
0592 {
0593   my $pack=shift;
0594   my $rep="PROCESS";
0595   if (exists $pcache->{tools}{$pack}){$rep="NOT_EXISTS";}
0596   elsif (exists $pcache->{packmap}{$pack})
0597   {
0598     my $prod=$pcache->{packmap}{$pack};
0599     if(!exists $cache->{$prod}){$rep="NOT_EXISTS";}
0600     elsif(exists $cache->{$prod}{done}){$rep="DONE";}
0601     elsif(exists $cache->{$prod}{skip}){$rep="SKIP";}
0602   }
0603   return $rep;
0604 }
0605 
0606 sub processRequest_SYMBOL_CHECK_REQUEST ()
0607 {
0608   my $prod=shift;
0609   print STDERR "REQUEST: Symbol check $prod\n";
0610   my $sym={};
0611   if (-f $prod){$sym=&SCRAMGenUtils::getLibSymbols($prod,'^U$');}
0612   elsif ((exists $cache->{$prod}) && (exists $pcache->{prod}{$prod}) && (exists $pcache->{prod}{$prod}{dir}))
0613   {
0614     my $d=$pcache->{prod}{$prod}{dir};
0615     if (-d "${release}/tmp/${scramarch}/src/${d}")
0616     {
0617       my $objdir=`find ${release}/tmp/${scramarch}/src/${d} -name $prod -type d`; chomp $objdir;
0618       my $ref;
0619       if ($objdir && opendir($ref,$objdir))
0620       {
0621         foreach my $file (readdir($ref))
0622     {
0623       $file="${objdir}/${file}";
0624       if (($file=~/\.o$/) && (-f $file))
0625       {
0626         my $sx=&SCRAMGenUtils::getObjectSymbols($file,'^U$');
0627         foreach my $s (keys %$sx){$sym->{$s}=$sx->{$s};}
0628       }
0629     }
0630         closedir($ref);
0631       }
0632     }
0633   }
0634   my %ts=();
0635   my $allsyms=$data->{ALL_SYMBOLS};
0636   foreach my $s (keys %$sym)
0637   {
0638     if (exists $allsyms->{$s})
0639     {
0640       my $s1=$allsyms->{$s};
0641       my $hassystem=0;
0642       foreach my $t (keys %$s1)
0643       {
0644     if ($t eq "system"){$ts{$s}={};}
0645     if (!$hassystem){foreach my $l (keys %{$s1->{$t}}){$ts{$s}{$t}=$l;}}
0646     if ($t eq "system"){$hassystem=1;}
0647       }
0648     }
0649   }
0650   my $tmpfile=&SCRAMGenUtils::getTmpFile ($cachedir);
0651   &SCRAMGenUtils::writeHashCache(\%ts,$tmpfile);
0652   return $tmpfile;
0653 }
0654 
0655 sub processRequest_PACKAGE_TYPE ()
0656 {
0657   my $pack=shift;
0658   my $reply="UNKNOWN";
0659   if (exists $pcache->{tools}{$pack}){$reply="TOOL";}
0660   elsif (exists $pcache->{dir}{$pack})
0661   {
0662     if(exists $pcache->{dir}{$pack}{plugin}){$reply=uc($pcache->{dir}{$pack}{plugin});}
0663     else{$reply="PACK";}
0664   }
0665   return $reply;
0666 }
0667 
0668 #####################################
0669 # Run a tool specific func
0670 ####################################
0671 sub run_func ()
0672 {
0673   my $func=shift || return "";
0674   my $tool=shift || return "";
0675   if($tool eq "self"){$tool=$project;}
0676   $tool=lc($tool);
0677   $func.="_${tool}";
0678   if(exists &$func){return &$func(@_);}
0679   return "";
0680 }
0681 #############################################
0682 # generating library safe name for a package
0683 #############################################
0684 sub safename_pool ()
0685 {return "lcg_".basename(shift);}
0686 sub safename_seal ()
0687 {return "lcg_".basename(shift);}
0688 sub safename_coral ()
0689 {return "lcg_".basename(shift);}
0690 
0691 sub safename_ignominy ()
0692 {return &safename_cms1(shift);}
0693 sub safename_iguana ()
0694 {return &safename_cms1(shift);}
0695 sub safename_cmssw ()
0696 {return &safename_cms2(shift);}
0697 
0698 sub safename_cms1 ()
0699 {
0700   my $dir=shift;
0701   if($dir=~/^${release}\/src\/([^\/]+?)\/([^\/]+)$/){return "${2}";}
0702   else{return "";}
0703 }
0704 sub safename_cms2 ()
0705 {
0706   my $dir=shift;
0707   if($dir=~/^${release}\/src\/([^\/]+?)\/([^\/]+)$/){return "${1}${2}";}
0708   else{return "";}
0709 }
0710 
0711 sub usage_msg()
0712 {
0713   my $script=basename($0);
0714   print "Usage: $script --dir <path> [--xml] [--order <pack>[--order <pack> [...]]] [--detail] [--merge]\n",
0715         "        [--redo <prod|all> [--redo <prod> [...]]] [--jobs <jobs>] [--config <file>]\n\n",
0716         "e.g.\n",
0717         "  $script --dir /path/to/a/project/release/area\n\n",
0718         "--dir <path>    Directory path for which you want to generate BuildFile(s).\n",
0719     "--order <pack>  Packages order in which script should process them\n",
0720     "--redo <pack>   Re-process an already done package\n",
0721     "--config <file> Extra configuration file\n",
0722     "--jobs <jobs>   Number of parallel jobs\n",
0723         "--detail        To get a detail processing log info\n",
0724     "--xml           To generate xml BuildFiles i.e. BuildFile.xml.auto\n",
0725     "--merge         Do not merge generated BuildFiles at the end\n\n",
0726         "This script will generate all the BuildFile(s) for your <path>. Generated BuildFile.auto will be available under\n",
0727     "AutoBuildFile/newBuildFile if you are not in a dev area otherwise in <devarea>/tmp/AutoBuildFile/newBuildFile.\n",
0728     "Do not forget to run \"mergeProdBuildFiles.pl --dir <dir>/AutoBuildFile/newBuildFile\n",
0729     "after running this script so that it can merge multiple products BuuildFiles in to one.\n",
0730     "Once BuildFile.auto are generated then you can copy all newBuilsFilew/*/BuildFile.auto in to your src/*/BuildFile.\n";
0731   exit 0;
0732 }