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