Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-21 23:14:21

0001 #!/usr/bin/perl
0002 
0003 $RUNDIR = '/data2/matevz/CMSSW_12_2_0_pre2/src';
0004 
0005 $pwd = `pwd`; chomp $pwd; die "Has to be run in $RUNDIR" unless $pwd eq $RUNDIR;
0006 
0007 # all files: `find RecoTracker -name \*.h -or -name \*.cc -or -name \*.icc -or -name \*.acc`;
0008 
0009 ### Setup headers, short-headers and header map. Exclude standalone/
0010 
0011 @headers = grep { chomp; $_ !~ m!/(?:standalone)/!; } `find RecoTracker -name \*.h`;
0012 
0013 @sheaders = map { my $a = $_; $a = $1 if $a =~ m!.*/([^/]+)$!; $a; } @headers;
0014 
0015 $NH = scalar(@headers);
0016 
0017 %hmap = ();
0018 for (my $i=0; $i<$NH; ++$i) { $hmap{$sheaders[$i]} = $headers[$i];}
0019 
0020 
0021 # Setup files to process, filter out stuff we don't want to touch.
0022 
0023 @files = grep { chomp; $_ !~ m!/(?:attic|dusty-chest)/!; } `find RecoTracker -name \*.h -or -name \*.cc`;
0024 
0025 print "HEADERS:\n";
0026 for (my $i=0; $i<$NH; ++$i) { print "  ", $headers[$i], "  -->  ", $sheaders[$i], "\n"; }
0027 print "\n\n";
0028 print "FILES:\n", join("\n", @files);
0029 print "\n\n";
0030 
0031 
0032 ################################################################
0033 
0034 for my $file (@files)
0035 {
0036     open F, $file;
0037     @lines = <F>;
0038     close F;
0039 
0040     # print $file,"\n",$f,"\n\n";
0041 
0042     my $insrc = $file =~ m!^(.*/(?:src|plugins)(?:/.*)?)/[^/]+$!;
0043     $insrc = $1 if $insrc;
0044 
0045     print "Processing file $file, N_lines = ", scalar(@lines), ", in_src = ", $insrc, "\n";
0046 
0047     my $changed = 0;
0048 
0049     for my $l (@lines)
0050     {
0051         if ($l =~ m!^#include\s+"(.*)"\s*!)
0052         {
0053             my $sh = $1; $sh = $1 if $sh =~ m!.*/([^/]+)$!;
0054 
0055             my $have = exists $hmap{$sh};
0056 
0057             my $line_to_print = $l;
0058             chomp $line_to_print;
0059             print "Found includeline $line_to_print -- $sh --> $hmap{$sh}\n";
0060 
0061             if ($have)
0062             {
0063                 # replace the line ... but first check if these are in the same src/ directory.
0064                 my $full_inc = $hmap{$sh};
0065                 if ($insrc && ($full_inc =~ m!^${insrc}!))
0066                 {
0067                     $full_inc =~ s!^${insrc}/(.*)!$1!;
0068                     print "   QQQQQQQ File and include in the same src/ --> shortening to ${full_inc}\n";
0069                 }
0070 
0071                 $l = "#include \"${full_inc}\"\n";
0072                 $changed = 1;
0073 
0074                 print "  new line is $l";
0075             }
0076         }
0077     }
0078 
0079     if ($changed)
0080     {
0081         open F, ">$file";
0082         print F @lines;
0083         close F;
0084     }
0085 }