releasing/cbrtools/perl/GetSource
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 $overwrite = 0;
       
    33 my $iniData = IniData->New();
       
    34 my $commandController = CommandController->New($iniData, 'GetSource');
       
    35 my $envDb;
       
    36 my $comp;
       
    37 my $ver;
       
    38 my $installDir = "\\";
       
    39 
       
    40 
       
    41 #
       
    42 # Main.
       
    43 #
       
    44 
       
    45 ProcessCommandLine();
       
    46 GetSource();
       
    47 
       
    48 
       
    49 #
       
    50 # Subs.
       
    51 #
       
    52 
       
    53 sub ProcessCommandLine {
       
    54   Getopt::Long::Configure ("bundling");
       
    55   my $help;
       
    56   GetOptions('h' => \$help, 'i=s' => \$installDir, 'o' => \$overwrite, 'v+' => \$verbose);
       
    57 
       
    58   if ($help) {
       
    59     Usage(0);
       
    60   }
       
    61 
       
    62   $comp = shift @ARGV;
       
    63   $ver = shift @ARGV;
       
    64 
       
    65   unless ($#ARGV == -1) {
       
    66     print "Error: Invalid number of arguments\n";
       
    67     Usage(1);
       
    68   }
       
    69 
       
    70   Utils::CheckDirectoryName($installDir);
       
    71 
       
    72   $envDb = EnvDb->Open($iniData, $verbose);
       
    73   
       
    74   if (defined $comp and not defined $ver) {
       
    75     $ver = $envDb->Version($comp);
       
    76     unless (defined $ver) {
       
    77       die "Error: $comp not installed\n";
       
    78     }
       
    79   }
       
    80 }
       
    81 
       
    82 sub Usage {
       
    83   my $exitCode = shift;
       
    84 
       
    85   Utils::PrintDeathMessage($exitCode, "\nUsage: getsource [options] [<component> [<version>]]
       
    86 
       
    87 options:
       
    88 
       
    89 -h  help
       
    90 -i  <install_directory>
       
    91 -o  overwrite any existing source
       
    92 -v  verbose output (-vv very verbose)\n");
       
    93 }
       
    94 
       
    95 sub GetSource {
       
    96   if (defined $comp) {
       
    97     UnpackSource($comp, $ver, $installDir);
       
    98   }
       
    99   else {
       
   100     print "About to unpack the source for the entire environment. Continue? [y/n] ";
       
   101     my $response = <STDIN>;
       
   102     if ($response =~ /^y$/i) {
       
   103       my $versionInfo = $envDb->VersionInfo();
       
   104       foreach my $thisComp (sort keys %{$versionInfo}) {
       
   105         eval {
       
   106           UnpackSource($thisComp, $versionInfo->{$thisComp}, $installDir);
       
   107         };
       
   108  
       
   109         if ($@) {
       
   110           print $@;
       
   111         }
       
   112       }
       
   113     }
       
   114   }
       
   115 }
       
   116 
       
   117 sub UnpackSource {
       
   118   my $comp = shift;
       
   119   my $ver = shift;
       
   120   my $dir = shift;
       
   121 
       
   122   print "Getting source for $comp $ver...\n";
       
   123   $envDb->UnpackSource($comp, $ver, $dir, $overwrite, 1);
       
   124 }
       
   125 
       
   126 
       
   127 __END__
       
   128 
       
   129 =head1 NAME
       
   130 
       
   131 GetSource - Installs the source code from a component release into the current environment.
       
   132 
       
   133 =head1 SYNOPSIS
       
   134 
       
   135   getsource [options] [<component> [<version>]]
       
   136 
       
   137 options:
       
   138 
       
   139   -h  help
       
   140   -i  <install_directory>
       
   141   -o  overwrite any existing source
       
   142   -v  verbose output (-vv very verbose)
       
   143 
       
   144 =head1 DESCRIPTION
       
   145 
       
   146 Releases are generally made containing both source and binaries. By default, tools like C<GetEnv> and C<GetRel> only unpack the binaries. C<GetSource> provides a means of installing the source when it is required (e.g. for debugging purposes).
       
   147 
       
   148 If only a component name is specified, the source for the currently installed version of the component is unpacked into the root of the current drive. If the source code for a version of a component that is not currently installed is required, then specify both the version and a directory in which the source should be unpacked (this will be created if it does not already exist). If no arguments are specified, the source to all the installed components is unpacked into the root of the current drive.
       
   149 
       
   150 =head1 KNOWN BUGS
       
   151 
       
   152 None.
       
   153 
       
   154 =head1 COPYRIGHT
       
   155 
       
   156  Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   157  All rights reserved.
       
   158  This component and the accompanying materials are made available
       
   159  under the terms of the License "Eclipse Public License v1.0"
       
   160  which accompanies this distribution, and is available
       
   161  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   162  
       
   163  Initial Contributors:
       
   164  Nokia Corporation - initial contribution.
       
   165  
       
   166  Contributors:
       
   167  
       
   168  Description:
       
   169  
       
   170 
       
   171 =cut