releasing/cbrtools/perl/EnvInfo
changeset 602 3145852acc89
equal deleted inserted replaced
600:6d08f4a05d93 602:3145852acc89
       
     1 #!perl
       
     2 # Copyright (c) 2000-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 CommandController;
       
    25 
       
    26 
       
    27 #
       
    28 # Globals.
       
    29 #
       
    30 
       
    31 my $verbose = 0;
       
    32 my $full = 0;
       
    33 my $component;
       
    34 my $iniData = IniData->New();
       
    35 my $commandController = CommandController->New($iniData, 'EnvInfo');
       
    36 my $envDb;
       
    37 my $overallStatus;
       
    38 my $displayClean = 0;
       
    39 my $displayDirty = 0;
       
    40 my $displayPendingRelease = 0;
       
    41 my $noScan = 0;
       
    42 
       
    43 
       
    44 #
       
    45 # Main.
       
    46 #
       
    47 
       
    48 ProcessCommandLine();
       
    49 CheckEnv();
       
    50 DisplayInfo();
       
    51 
       
    52 
       
    53 #
       
    54 # Subs.
       
    55 #
       
    56 
       
    57 sub ProcessCommandLine {
       
    58   Getopt::Long::Configure ("bundling");
       
    59   my $help;
       
    60   GetOptions("h" => \$help, "f+" => \$full, "c" => \$displayClean, "d" => \$displayDirty, "p" => \$displayPendingRelease, "n" => \$noScan, "v+" => \$verbose);
       
    61   if ($help) {
       
    62     Usage(0);
       
    63   }
       
    64 
       
    65   if (not $full and ($displayClean or $displayDirty or $displayPendingRelease)) {
       
    66     print "Warning: Inappropriate option(s), must be invoked together with -f\n";
       
    67   }
       
    68 
       
    69   if (not $displayClean and not $displayDirty and not $displayPendingRelease) {
       
    70     $displayClean = 1;
       
    71     $displayDirty = 1;
       
    72     $displayPendingRelease = 1;
       
    73   }
       
    74 
       
    75   $component = $ARGV[0];
       
    76   $envDb = EnvDb->Open($iniData, $verbose);
       
    77 }
       
    78 
       
    79 sub Usage {
       
    80   my $exitCode = shift;
       
    81 
       
    82   Utils::PrintDeathMessage($exitCode, "\nUsage: envinfo [options] [<component>]
       
    83 
       
    84 options:
       
    85 
       
    86 -h  help
       
    87 -v  verbose output (-vv very verbose)
       
    88 -f  display fuller information (the remaining switches only apply when this is used)
       
    89 -ff display even fuller information (internal version and mrp name)
       
    90 -c  display the components with status \"clean\"
       
    91 -d  display the components with status \"dirty\"
       
    92 -p  display the components with status \"pending release\"
       
    93 -n  no scan\n");
       
    94 }
       
    95 
       
    96 sub CheckEnv {
       
    97   unless ($noScan or not $full) {
       
    98     if (defined $component) {
       
    99       $envDb->CheckComp($component, undef, 1);
       
   100     }
       
   101     else {
       
   102       ($overallStatus, undef, undef, my $unaccountedFiles, my $duplicates) = $envDb->CheckEnv(1, 0, 1);
       
   103       if (scalar (@$unaccountedFiles) > 0) {
       
   104 	foreach my $line (@$unaccountedFiles) {
       
   105 	  print "Warning: $line has unknown origin\n"; 
       
   106 	}
       
   107       }
       
   108       if (scalar (@$duplicates) > 0) {
       
   109 	foreach my $args (@$duplicates) {
       
   110 	  print "Warning: $args->[1] attempting to release $args->[0] which has already been released by $args->[2]\n"; 
       
   111 	}
       
   112       }
       
   113     }
       
   114   }
       
   115 }
       
   116 
       
   117 sub DisplayInfo {
       
   118   # Create a list of the components to be displayed.
       
   119   my @comps;
       
   120   if (defined $component) {
       
   121     my $ver = $envDb->Version($component);
       
   122     unless (defined $ver) {
       
   123       die "Error: $component not found\n";
       
   124     }
       
   125     push @comps, $component;
       
   126   }
       
   127   else {
       
   128     my $versionInfo = $envDb->VersionInfo();
       
   129     foreach my $comp (sort keys %{$versionInfo}) {
       
   130       push @comps, $comp;
       
   131     }
       
   132   }
       
   133 
       
   134   my $tableData;
       
   135   if ($full == 1) {
       
   136     $tableData = GenFullInfoTable(\@comps);
       
   137   }
       
   138   elsif ($full > 1) {
       
   139     $tableData = GenEvenFullerInfoTable(\@comps);
       
   140   }
       
   141   else {
       
   142     $tableData = GenMinimalInfoTable(\@comps);
       
   143   }
       
   144 
       
   145   # Only print the table if there's something in it.
       
   146   if (scalar(@$tableData) > 1) {
       
   147     print "\n";
       
   148     $iniData->TableFormatter->PrintTable($tableData, 1);
       
   149   }
       
   150 
       
   151   # Only display the overall status if a full check was done.
       
   152   if (defined $overallStatus) {
       
   153     print "\nOverall status: ", EnvDb::StatusString($overallStatus), "\n";
       
   154   }
       
   155 }
       
   156 
       
   157 sub GenMinimalInfoTable {
       
   158   my $comps = shift;
       
   159 
       
   160   # Create a two dimentional array of the data to be printed.
       
   161   my $tableData = [["Component", "Version"]];
       
   162   my $row = 1;
       
   163   foreach my $comp (@$comps) {
       
   164     my $ver = $envDb->Version($comp);
       
   165     $tableData->[$row++] = [$comp, $ver];
       
   166   }
       
   167   return $tableData;
       
   168 }
       
   169 
       
   170 sub GenFullInfoTable {
       
   171   my $comps = shift;
       
   172 
       
   173   # Create a two dimentional array of the data to be printed.
       
   174   my $tableData = [["Component", "Version", "Project", "Status"]];
       
   175   my $row = 1;
       
   176   foreach my $comp (@$comps) {
       
   177     my $ver = $envDb->Version($comp);
       
   178     my $status = $envDb->Status($comp);
       
   179     if (not $displayClean and $status == EnvDb::STATUS_CLEAN) {
       
   180       next;
       
   181     }
       
   182     elsif (not $displayDirty and ($status == EnvDb::STATUS_DIRTY or $status == EnvDb::STATUS_DIRTY_SOURCE)) {
       
   183       next;
       
   184     }
       
   185     elsif (not $displayPendingRelease and $status == EnvDb::STATUS_PENDING_RELEASE) {
       
   186       next;
       
   187     }
       
   188     my $project = $iniData->PathData->ComponentProject($comp, $ver);
       
   189     unless (defined $project) {
       
   190       $project = "-";
       
   191     }
       
   192     $tableData->[$row++] = [$comp, $ver, $project, EnvDb::StatusString($status)];
       
   193   }
       
   194   return $tableData;
       
   195 }
       
   196 
       
   197 sub GenEvenFullerInfoTable {
       
   198   my $comps = shift;
       
   199 
       
   200   # Create a two dimentional array of the data to be printed.
       
   201   my $tableData = [["Component", "Version", "Internal version", "Project",  "Status", "Mrp"]];
       
   202   my $row = 1;
       
   203   foreach my $comp (@$comps) {
       
   204     my $ver = $envDb->Version($comp);
       
   205     my $status = $envDb->Status($comp);
       
   206     if (not $displayClean and $status == EnvDb::STATUS_CLEAN) {
       
   207       next;
       
   208     }
       
   209     elsif (not $displayDirty and ($status == EnvDb::STATUS_DIRTY or $status == EnvDb::STATUS_DIRTY_SOURCE)) {
       
   210       next;
       
   211     }
       
   212     elsif (not $displayPendingRelease and $status == EnvDb::STATUS_PENDING_RELEASE) {
       
   213       next;
       
   214     }
       
   215 
       
   216     my $mrpName = $envDb->MrpName($comp);
       
   217     unless (defined $mrpName) {
       
   218       $mrpName = "-";
       
   219     }
       
   220     my $intVer = $envDb->InternalVersion($comp);
       
   221     unless (defined $intVer) {
       
   222       $intVer = "-";
       
   223     }
       
   224     my $project = $iniData->PathData->ComponentProject($comp, $ver);
       
   225     unless (defined $project) {
       
   226       $project= "-";
       
   227     }
       
   228     $tableData->[$row++] = [$comp, $ver, $intVer, $project, EnvDb::StatusString($status), $mrpName];
       
   229   }
       
   230   return $tableData;
       
   231 }
       
   232 
       
   233 
       
   234 =head1 NAME
       
   235 
       
   236 EnvInfo - Displays information about the installed components in the current environment.
       
   237 
       
   238 =head1 SYNOPSIS
       
   239 
       
   240   envinfo [options] [<component>]
       
   241 
       
   242 options:
       
   243 
       
   244   -h  help
       
   245   -v  verbose output (-vv very verbose)
       
   246   -f  display fuller information (the remaining switches only apply when this is used)
       
   247   -ff display even fuller information (internal version and mrp name)
       
   248   -c  display the components with status "clean"
       
   249   -d  display the components with status "dirty"
       
   250   -p  display the components with status "pending release"
       
   251   -n  no scan
       
   252 
       
   253 =head1 DESCRIPTION
       
   254 
       
   255 By default displays a brief summary table of the information contained in the current drive's environment database. For example:
       
   256 
       
   257  Component   Version
       
   258 
       
   259  mycomp1     026
       
   260  mycomp2     057
       
   261 
       
   262 If envoked with the C<-f> switch, a scan is performed of the F<\epoc32> tree and the status of each component is also reported:
       
   263 
       
   264  Component   Version   Status
       
   265 
       
   266  mycomp1     026       clean
       
   267  mycomp2     057       clean
       
   268 
       
   269  Overall status: clean
       
   270 
       
   271 The C<Status> field may have the following values:
       
   272 
       
   273 =over 4
       
   274 
       
   275 =item *
       
   276 
       
   277 B<clean> - The component's binaries all match the time stamp information that was stored when they were installed (or when they were last validated using either C<ValidateRel> or C<ValidateEnv>).
       
   278 
       
   279 =item *
       
   280 
       
   281 B<dirty> - One or more of the component's binaries doesn't match the time stamp information that was stored when they were installed. This may be because the source has been re-built but not changed (see the commands C<ValidateRel> and C<ValidateEnv> for details of how to check if a re-built set of binaries are identical to an already released set), or because changes have been made.
       
   282 
       
   283 =item *
       
   284 
       
   285 B<pending release> - The component is waiting to be released (see the commands C<PrepEnv> and C<MakeEnv> for details of how to make releases).
       
   286 
       
   287 =back
       
   288 
       
   289 The overall status of the environment is displayed last. This may have the following values:
       
   290 
       
   291 =over 4
       
   292 
       
   293 =item *
       
   294 
       
   295 B<clean> - All the installed components have a status of C<clean> and there are no files in the F<\epoc32> tree that have unkown origins (i.e. they are all known to belong to a component).
       
   296 
       
   297 =item *
       
   298 
       
   299 B<dirty> - One or more of the installed components has a status of C<dirty>, or there is one or more files in the F<\epoc32> tree that has unknown origins.
       
   300 
       
   301 =item *
       
   302 
       
   303 B<pending release> - All components have a status of either C<clean> or C<pending release> and there are no files in the F<\epoc32> with unknown origins. This status indicates that C<MakeEnv> may be used to release this environment.
       
   304 
       
   305 =back
       
   306 
       
   307 
       
   308 By default when C<EnvInfo> is envoked with the C<-f> switch, it will perform a scan of the F<\epoc32> tree checking all the time stamps. To avoid this processing, use the C<-n> switch also. This will cause the status of each component when the last scan was performed to be displayed (which may now be out of date). The output of C<EnvInfo> can be filtered according to status using the switches C<-c>, C<-d> and C<-p>. For example, if you wanted to view all the components that are either C<dirty> or C<pending release>, type:
       
   309 
       
   310   envinfo -fdp
       
   311 
       
   312 If envoked with a C<component> argument, then only the details of the specified component will be displayed and a scan of the F<\epoc32> tree will not be performed.
       
   313 
       
   314 =head1 KNOWN BUGS
       
   315 
       
   316 None.
       
   317 
       
   318 =head1 COPYRIGHT
       
   319 
       
   320  Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   321  All rights reserved.
       
   322  This component and the accompanying materials are made available
       
   323  under the terms of the License "Eclipse Public License v1.0"
       
   324  which accompanies this distribution, and is available
       
   325  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   326  
       
   327  Initial Contributors:
       
   328  Nokia Corporation - initial contribution.
       
   329  
       
   330  Contributors:
       
   331  
       
   332  Description:
       
   333  
       
   334 
       
   335 =cut