releasing/cbrtools/perl/MrpComplexity
changeset 602 3145852acc89
equal deleted inserted replaced
600:6d08f4a05d93 602:3145852acc89
       
     1 #!perl
       
     2 # Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     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 # Nokia Corporation - initial contribution.
       
    11 # 
       
    12 # Contributors:
       
    13 # 
       
    14 # Description:
       
    15 # 
       
    16 #
       
    17 
       
    18 use strict;
       
    19 use FindBin;
       
    20 use lib "$FindBin::Bin";
       
    21 use Getopt::Long;
       
    22 use IniData;
       
    23 use EnvDb;
       
    24 use Utils;
       
    25 
       
    26 
       
    27 #
       
    28 # Globals.
       
    29 #
       
    30 
       
    31 my $verbose = 0;
       
    32 my $iniData = IniData->New();
       
    33 my $force;
       
    34 
       
    35 
       
    36 #
       
    37 # Main.
       
    38 #
       
    39 
       
    40 ProcessCommandLine();
       
    41 Utils::QueryUnsupportedTool(undef, $force);
       
    42 my $ratings = ScanMrps();
       
    43 PrintReport($ratings);
       
    44 
       
    45 
       
    46 #
       
    47 # Subs.
       
    48 #
       
    49 
       
    50 sub ProcessCommandLine {
       
    51   Getopt::Long::Configure ('bundling');
       
    52   my $help;
       
    53   GetOptions('h' => \$help, 'v+' => \$verbose, 'f' => \$force);
       
    54 
       
    55   if ($help) {
       
    56     Usage(0);
       
    57   }
       
    58 }
       
    59 
       
    60 sub ScanMrps {
       
    61   my $envDb = EnvDb->Open($iniData, $verbose);
       
    62   my @comps = keys %{$envDb->{db}}; # This should go through an EnvDb interface - needs adding.
       
    63   my %ratings;
       
    64   foreach my $thisComp (@comps) {
       
    65     my $dbEntry = $envDb->{db}->{$thisComp};
       
    66     if (-e $dbEntry->{mrpName}) {
       
    67       $ratings{$thisComp} = RateMrpFile($dbEntry->{mrpName});
       
    68     }
       
    69     elsif ($verbose) {
       
    70       print "Warning: $thisComp\'s mrp file (\"$dbEntry->{mrpName}\") does not exit\n";
       
    71     }
       
    72   }
       
    73   return \%ratings;
       
    74 }
       
    75 
       
    76 sub PrintReport {
       
    77   my $ratings = shift;
       
    78   my $tableData = [["Component", "Complexity Rating"]];
       
    79 
       
    80   foreach my $thisComp (sort { $ratings->{$b} <=> $ratings->{$a} } keys %$ratings) {
       
    81     if ($ratings->{$thisComp} > 0) {
       
    82       push (@$tableData, [$thisComp, $ratings->{$thisComp}]);
       
    83     }
       
    84   }
       
    85 
       
    86   print "\n";
       
    87   Utils::PrintTable($tableData, 1);
       
    88 }
       
    89 
       
    90 sub RateMrpFile {
       
    91   my $file = shift;
       
    92   my $rating = 0;
       
    93   print "Rating \"$file\"...\n" if ($verbose);
       
    94   open (MRP, $file) or die "Error: Couldn't open \"$file\": $!\n";
       
    95   while (my $line = <MRP>) {
       
    96     chomp $line;
       
    97     $line =~ s/^\s*$//;
       
    98     $line =~ s/\s*#.*//;
       
    99     unless ($line) {
       
   100       # Nothing left.
       
   101       next;
       
   102     }
       
   103 
       
   104     my $keyWord;
       
   105     my $operand;
       
   106     if ($line =~ /(\S+)\s+(.*)/) {
       
   107       $keyWord = $1;
       
   108       $operand = $2;
       
   109     }
       
   110     else {
       
   111       die "Error: Invalid mrp file \"$file\"";
       
   112     }
       
   113 
       
   114     if ($keyWord eq 'binary') {
       
   115       if (-f $operand) {
       
   116 	print "binary <file> statement found in \"$file\"\n" if ($verbose);
       
   117 	++$rating;
       
   118       }
       
   119     }
       
   120     elsif ($keyWord eq '-binary') {
       
   121       print "-binary statement found in \"$file\"\n" if ($verbose);
       
   122       ++$rating;
       
   123     }
       
   124     elsif ($keyWord eq 'source') {
       
   125       if (-f $operand) {
       
   126 	print "source <file> statement found in \"$file\"\n" if ($verbose);
       
   127 	++$rating;
       
   128       }
       
   129     }
       
   130     elsif ($keyWord eq 'export_file') {
       
   131       print "export_file statement found in \"$file\"\n" if ($verbose);
       
   132       ++$rating;
       
   133     }
       
   134     elsif ($keyWord eq '-export_file') {
       
   135       print "-export_file statement found in \"$file\"\n" if ($verbose);
       
   136       ++$rating;
       
   137     }
       
   138     elsif ($keyWord eq 'testbinary') {
       
   139       print "testbinary statement found in \"$file\"\n" if ($verbose);
       
   140       ++$rating;
       
   141     }
       
   142   }
       
   143   close (MRP);
       
   144   return $rating;
       
   145 }
       
   146 
       
   147 sub Usage {
       
   148   my $exitCode = shift;
       
   149 
       
   150   Utils::PrintDeathMessage($exitCode, "\nUsage: mrpcomplexity [options] <file_name>
       
   151 
       
   152 options:
       
   153 
       
   154 -h  help
       
   155 -v  verbose output (-vv very verbose)
       
   156 -f  force, skip warnings about unsupported-ness\n");
       
   157 }
       
   158 
       
   159 
       
   160 __END__
       
   161 
       
   162 =head1 NAME
       
   163 
       
   164 MrpComplexity - Reports information on undesirable mrp constructs.
       
   165 
       
   166 =head1 SYNOPSIS
       
   167 
       
   168   MrpComplexity [options]
       
   169 
       
   170 options:
       
   171 
       
   172   -h  help
       
   173   -v  verbose output (-vv very verbose)
       
   174   -f  force, skip warnings about unsupported-ness
       
   175 
       
   176 =head1 DESCRIPTION
       
   177 
       
   178 Under normal circumstances F<mrp> files should contain very little information regarding where to find binary files. This information is best placed within the build configuration files (F<bld.inf>s and F<.mmp>s), as doing so allows F<mrp> files to be relatively self-maintaining.
       
   179 
       
   180 However, F<mrp> files support a rich syntax. This was designed to make it possible to release a component even if is it not possible to change the build configuration files (perhaps due to ownership restraints). Under these conditions, F<mrp> files can often become complex and as a result time consuming to maintain.
       
   181 
       
   182 This command provides a report that can be used to identify overly complex F<mrp> files, so that the root cause of this complexity can be found and eliminated. For each component in the environment, if its F<mrp> file is available, it is parsed and rated. The rating each is assigned is determined from the number of the following constructs that are found:
       
   183 
       
   184  binary <file_name>
       
   185  -binary
       
   186  source <file_name>
       
   187  export_file
       
   188  -export_file
       
   189  testbinary
       
   190 
       
   191 The report is presented showing the components with the highest complexity rating first. Those with a rating of zero are not shown.
       
   192 
       
   193 =head1 STATUS
       
   194 
       
   195 Unsupported/experimental. If you find a problem, please send us a patch.
       
   196 
       
   197 =head1 KNOWN BUGS
       
   198 
       
   199 None.
       
   200 
       
   201 =head1 COPYRIGHT
       
   202 
       
   203  Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   204  All rights reserved.
       
   205  This component and the accompanying materials are made available
       
   206  under the terms of the License "Eclipse Public License v1.0"
       
   207  which accompanies this distribution, and is available
       
   208  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   209  
       
   210  Initial Contributors:
       
   211  Nokia Corporation - initial contribution.
       
   212  
       
   213  Contributors:
       
   214  
       
   215  Description:
       
   216  
       
   217 
       
   218 =cut