releasing/cbrtools/perl/GetEnv
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 RelData;
       
    24 use EnvDb;
       
    25 use CommandController;
       
    26 use GetEnv;
       
    27 
       
    28 
       
    29 #
       
    30 # Globals.
       
    31 #
       
    32 
       
    33 my $verbose = 0;
       
    34 my $overwriteSource = 0;
       
    35 my $sourceInstallPath = undef;
       
    36 my $iniData = IniData->New();
       
    37 my $commandController = CommandController->New($iniData, 'GetEnv');
       
    38 my $comp;
       
    39 my $ver;
       
    40 my $installSource = 0;
       
    41 my $removeSource =0;
       
    42 my $excludeComponents = undef;
       
    43 my $forceExclusion = 0;
       
    44 my $sourceOnly;
       
    45 
       
    46 
       
    47 #
       
    48 # Main.
       
    49 #
       
    50 
       
    51 ProcessCommandLine();
       
    52 
       
    53 if ($sourceOnly) {
       
    54   GetEnvSource();
       
    55 }
       
    56 else {
       
    57   GetEnv::GetEnvFromRelData($iniData, $comp, $ver, $installSource, $sourceInstallPath, $overwriteSource, $removeSource, $verbose, $excludeComponents, $forceExclusion);
       
    58   print "Checking environment...\n";
       
    59   my $envDb = EnvDb->Open($iniData, $verbose);
       
    60   (my $status) = $envDb->CheckEnv();
       
    61   print "Status: ", EnvDb::StatusString($status), "\n";
       
    62 }
       
    63 
       
    64 #
       
    65 # Subs.
       
    66 #
       
    67 
       
    68 sub ProcessCommandLine {
       
    69   Getopt::Long::Configure ("bundling");
       
    70   my $help;
       
    71   GetOptions('h' => \$help, 's' => \$installSource, 'o' => \$overwriteSource, 'r' => \$removeSource, 'v+' => \$verbose,  'i=s' => \$sourceInstallPath, 'x=s' => \$excludeComponents, 'f' => \$forceExclusion, 'source-only' => \$sourceOnly);
       
    72 
       
    73   if ($help) {
       
    74     Usage(0);
       
    75   }
       
    76 
       
    77   $comp = shift @ARGV;
       
    78   $ver = shift @ARGV;
       
    79 
       
    80   unless (defined $comp and defined $ver and $#ARGV = -1) {
       
    81     print "Error: Invalid arguments\n";
       
    82     Usage(1);
       
    83   }
       
    84 
       
    85   if ($sourceInstallPath and not ($installSource || $sourceOnly )) {
       
    86     print "Error: Invalid options - cannot specify install path (using -i) without installing source (using -s or --source-only)\n";
       
    87     Usage(1);
       
    88   }
       
    89   
       
    90   Utils::CheckDirectoryName($sourceInstallPath) if defined $sourceInstallPath;
       
    91 }
       
    92 
       
    93 sub Usage {
       
    94   my $exitCode = shift;
       
    95 
       
    96   Utils::PrintDeathMessage($exitCode, "\nUsage: getenv [options] <component> <external_version>
       
    97 
       
    98 options:
       
    99 
       
   100 -h  help
       
   101 -s  install source also
       
   102 -r  remove source which belongs to components deleted during upgrade
       
   103 -i  <source_install_directory>
       
   104 -o  overwrite any existing source and binaries (including pending release components)
       
   105 -v  verbose output (-vv very verbose)
       
   106 -x  <component_name> to exclude from installation or <file> with list of components to exclude (sets -r)
       
   107 -f  overrides the user prompt when removing components specified with the -x flag. Does nothing if -x not defined
       
   108 --source-only Installs the source code for any environment, irrespective of whether it is the current environment or not\n");
       
   109 }
       
   110 
       
   111 sub GetEnvSource {   
       
   112     my $reldata = RelData->Open($iniData, $comp, $ver, $verbose);
       
   113     my $components = $reldata->Environment();    
       
   114     my $envDb = EnvDb->Open($iniData, $verbose);
       
   115     
       
   116     if (defined $excludeComponents) {
       
   117       $components = GetEnv::FilterCompsToExclude($components, $excludeComponents, $verbose, $forceExclusion);
       
   118     }
       
   119     
       
   120     foreach my $thisComp (sort keys %{$components}) {
       
   121         eval {
       
   122             print "Getting source for $thisComp $components->{$thisComp}...\n";
       
   123             $envDb->UnpackSource($thisComp, $components->{$thisComp}, $sourceInstallPath || "\\", $overwriteSource, $verbose);     
       
   124         };
       
   125     }
       
   126 }
       
   127 
       
   128 __END__
       
   129 
       
   130 =head1 NAME
       
   131 
       
   132 GetEnv - Installs the environment from which a component release was made.
       
   133 
       
   134 =head1 SYNOPSIS
       
   135 
       
   136   getenv [options] <component> <version>
       
   137 
       
   138 options:
       
   139 
       
   140   -h  help
       
   141   -s  install source also
       
   142   -r  removes source which belongs to components deleted during upgrade
       
   143   -i  <source_install_directory>
       
   144   -o  overwrite any existing source and binaries (including components pending release)
       
   145   -v  verbose output (-vv very verbose)
       
   146   -x  <component_name> to exclude from installation or <file> with list of components to exclude (sets -r)
       
   147   -f  overrides the user prompt when removing components specified with the -x flag. Does nothing if -x not defined.
       
   148   --source-only Installs the source code for any environment, irrespective of whether it is the current environment or not
       
   149 
       
   150 =head1 DESCRIPTION
       
   151 
       
   152 When a release is made, a description of the environment it was made from is stored with it. C<GetEnv> reads this and installs the necessary components into the current environment in order to make it identical to the environment from which the release was made. Note, the term I<environment> is used to mean the F<\epoc32> tree. C<GetEnv> will optionally install source code into the root of the current drive, but it makes no attempt to verify the cleanliness of these directories.
       
   153 
       
   154 Components that were present in the release environment, but which are not present in the current environment are simply installed. Components of a different version in the current environment to that of the release environment are upgraded. The upgrade process involves removing the currently installed binaries, and then unpacking the new binaries. The binaries of components that have the same version in the current environment to that of the release environment are checked against the time stamp information that was stored when they were installed. If the check fails, the component is upgraded. If it succeeds, the component left untouched.
       
   155 
       
   156 As well as overwriting existing source code, C<-o> will overwrite any binaries which are left on the drive. There will only be leftover binaries in exceptional circumstances; normally C<getenv> will remove old versions of components before trying to install new ones. C<-o> will also force 'pending release' components to be removed if necessary.
       
   157 
       
   158 Unrequired components, (e.g. documentation), can be optionally excluded from being installed using the -x flag and specifying the component name or a file which contains a list of component names (Wildcards are supported). If the unrequired component exists in the current environment the binaries and source will be removed from the current environment, if it does not currently exist the component will simply not be installed if it is in the new environment. This option should be used cautiously especially if making releases from your local work area.
       
   159 
       
   160 Examples of -x flag:
       
   161 
       
   162 	getenv -vos gt_techview_baseline <some_version> -x tools_e32toolp
       
   163 	
       
   164 	This will exclude the component tools_e32toolp from the new installation if it exists in the archive
       
   165 	
       
   166 	
       
   167 	
       
   168 	getenv -vos gt_techview_baseline <some_version> -x tools*
       
   169 	
       
   170 	This will exclude any components which begin with the string "tools" in their name from the new installation
       
   171 	
       
   172 	
       
   173 	
       
   174 	getenv -vos gt_techview_baseline <some_version> -x d:\exclude.txt
       
   175 	
       
   176 	This will exclude any components that are mentioned in the file from the new installation if they exist in the archive
       
   177 	(File can be named anything)
       
   178 	
       
   179 	
       
   180 	Format of the file:
       
   181 	
       
   182 	component_one
       
   183 	component_two
       
   184 	component_three
       
   185 	component*
       
   186 	
       
   187 	(All components are to be on seperate lines, empty lines are permitted).
       
   188 	
       
   189 	When using the * wildcard this must be at the end of the line.
       
   190 	
       
   191 =head1 KNOWN BUGS
       
   192 
       
   193 None.
       
   194 
       
   195 =head1 COPYRIGHT
       
   196 
       
   197  Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   198  All rights reserved.
       
   199  This component and the accompanying materials are made available
       
   200  under the terms of the License "Eclipse Public License v1.0"
       
   201  which accompanies this distribution, and is available
       
   202  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   203  
       
   204  Initial Contributors:
       
   205  Nokia Corporation - initial contribution.
       
   206  
       
   207  Contributors:
       
   208  
       
   209  Description:
       
   210  
       
   211 
       
   212 =cut