code_churn/fbf_churn.pl
changeset 49 c0d2a34bf681
child 55 7b39c2ae2526
equal deleted inserted replaced
48:8e73266ba54f 49:c0d2a34bf681
       
     1 #! perl -w
       
     2 
       
     3 # Copyright (c) 2009 Symbian Foundation Ltd
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Symbian Foundation Ltd - initial contribution.
       
    11 # 
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 #
       
    16 
       
    17 use strict;
       
    18 use Getopt::Long;
       
    19 
       
    20 use FindBin;
       
    21 #my $churn_core = "D:\\mirror\\churn_core.pl";
       
    22 my $churn_core = "$FindBin::Bin\\churn_core.pl";
       
    23 my $churn_output_temp = "$FindBin::Bin\\fbf_churn_output";
       
    24 mkdir $churn_output_temp;
       
    25 
       
    26 sub Usage($)
       
    27   {
       
    28   my ($msg) = @_;
       
    29   
       
    30   print "$msg\n\n" if ($msg ne "");
       
    31   
       
    32 	print <<'EOF';
       
    33 
       
    34 	
       
    35 fbf_churn.pl - simple script for calculating code churn in between two revisions 
       
    36 or labels for a package. This script can also be used to calculate code size for 
       
    37 a package.
       
    38 
       
    39 When used without a package name or filter, this script runs for all the packages
       
    40 in the BOM (build-info.xml) file supplied to it. 
       
    41 
       
    42 Important: 
       
    43   This script uses clone_all_packages.pl which clones all repositories listed in 
       
    44   the BOM or pull changes into a previously cloned repository.
       
    45   
       
    46   This script uses its accompayning script churn_core.pl - which should be
       
    47   present in the same directory as this script.
       
    48 
       
    49 Limitations:
       
    50   If a BOM is not supplied to the script using the -bom option, then the script 
       
    51   runs on the package locations inside both MCL and FCL producing two results
       
    52   for a single package. For running the script for calculating code churn between 
       
    53   two release buils (using labels) or for calculating code size for a release build,
       
    54   it is essential that a BOM (preferably for the newer build) is passed as an 
       
    55   argument using the -bom option.
       
    56   
       
    57 
       
    58 Options:
       
    59 
       
    60 -o --old		old revision or label for a package/respoitory
       
    61 
       
    62 -n --new		new revision or label for a package/respoitory
       
    63 
       
    64 --rev			revision for package/respoitory - Use this while calculating code size for a single package
       
    65 			
       
    66 --label			revision tag for package or release build - Use this while calculating code size
       
    67 
       
    68 -bom --bom		build-info.xml files supplied with Symbian PDKs
       
    69 
       
    70 -verbose		print the underlying "clone_all_packages" & "hg" commands before executing them
       
    71 
       
    72 -help			print this help information
       
    73 
       
    74 -package <RE>   	only process repositories matching regular expression <RE>
       
    75 
       
    76 -filter <RE>    	only process repositories matching regular expression <RE>
       
    77 
       
    78 EOF
       
    79   exit (1);  
       
    80   }
       
    81 
       
    82 print "\n\n==Symbian Foundation Code Churn Tool v1.0==\n\n";
       
    83 
       
    84 
       
    85 
       
    86 my $old = "null";
       
    87 my $new = "";
       
    88 my $filter = "";
       
    89 my $codeline = "";
       
    90 my $package = "";
       
    91 my $licence = "";
       
    92 my $packagelist = "";
       
    93 my $verbose = 0;
       
    94 my $help = 0;
       
    95 
       
    96 sub do_system
       
    97 	{
       
    98 	my (@args) = @_;
       
    99 	print "* ", join(" ", @args), "\n" if ($verbose);
       
   100 	return system(@args);
       
   101 	}
       
   102 
       
   103 # Analyse the command-line parameters
       
   104 if (!GetOptions(
       
   105     "n|new-rev|new-label|label|rev=s" => \$new,
       
   106     "o|old-rev|old-label=s" => \$old,
       
   107     "f|filter=s" => \$filter,
       
   108     "p|package=s" => \$filter,
       
   109     "cl|codeline=s" => \$codeline,
       
   110     "li|licence=s" => \$licence,
       
   111 	"bom|bom=s" => \$packagelist,
       
   112 	"v|verbose" => \$verbose,
       
   113 	"h|help" => \$help,
       
   114     ))
       
   115   {
       
   116   Usage("Invalid argument");
       
   117   }
       
   118   
       
   119 Usage("") if ($help);
       
   120 Usage("Too few arguments....use at least one from -n|new-rev|new-label|label|rev or -bom") if ($new eq "" && $packagelist eq "");
       
   121 #Usage("Too many arguments") if ($new ne "" && $packagelist ne "");
       
   122 
       
   123 
       
   124 if ($old eq 'null')
       
   125   {
       
   126     print "\nCode size calculation....\n";		  
       
   127   }
       
   128 else
       
   129   {
       
   130     print "\nCode churn calculation....\n";		  
       
   131   }
       
   132 
       
   133   
       
   134 my @packagelistopts = ();
       
   135 @packagelistopts = ("-packagelist", $packagelist) if ($packagelist ne "");
       
   136 
       
   137 my @verboseopt = ();
       
   138 @verboseopt = "-v" if ($verbose);
       
   139 
       
   140 my $new_rev = $new;
       
   141 $new_rev = "%REV%" if ($new_rev eq "");
       
   142 
       
   143 #TO_DO: Locate clone_all_packages relative to the location of this script.
       
   144 #TO_DO: Remove references to absolute paths, change to relative paths.
       
   145 do_system("clone_all_packages.pl",@verboseopt,"-mirror","-filter","$licence.*$codeline.*$filter",@packagelistopts,"-exec","--",
       
   146    "hg","--config","\"extensions.hgext.extdiff=\"","extdiff","-p",$churn_core,"-o",$churn_output_temp,
       
   147    "-r","$old","-r","$new_rev");
       
   148 
       
   149 exit(0);