bldsystemtools/commonbldutils/GetDPComp/GetDPComp.pl
branchRCL_3
changeset 24 d90029decf65
parent 20 a9d4531388d0
child 33 54aa4a06a075
child 34 5e522efbae7b
equal deleted inserted replaced
20:a9d4531388d0 24:d90029decf65
     1 #!/usr/bin/perl
       
     2 
       
     3 =head1 NAME
       
     4 
       
     5 GetDPComp.pl
       
     6 
       
     7 =head1 SYNOPSIS
       
     8 
       
     9 GetDPComp.pl
       
    10 
       
    11 =head1 DESCRIPTION
       
    12 
       
    13 This script is designed to use latestver, envsize and getrel commands from the CBR tools to find and get the latest green version of one DP SF component(s).
       
    14 
       
    15 =head1 COPYRIGHT
       
    16 
       
    17 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
    18 All rights reserved.
       
    19 
       
    20 =cut
       
    21 
       
    22 use strict;
       
    23 use LWP::UserAgent;
       
    24 use Getopt::Long;
       
    25 use FindBin;
       
    26 use lib "$FindBin::Bin";
       
    27 use GetDPComp;
       
    28 
       
    29 my ($iComponentNames, $iInputFile, $iBaselineComponentName, $iBaselineComponentVersion, $iSource, $iOutputFile) = ProcessCommandLine();
       
    30 $iBaselineComponentName = GetDPComp::LRtrim($iBaselineComponentName);
       
    31 $iBaselineComponentVersion = GetDPComp::LRtrim($iBaselineComponentVersion);
       
    32 
       
    33 if (!defined $iBaselineComponentName) {
       
    34   $iBaselineComponentName = "sf_tools_baseline";
       
    35 }
       
    36 
       
    37 my $retval = 1 ;
       
    38 ($iBaselineComponentVersion, $retval) = GetDPComp::ValidateVersion( $iBaselineComponentVersion, $iBaselineComponentName);
       
    39 if ($retval == 0 ) {
       
    40   print "\nERROR: Input version is wrong. \n";
       
    41   exit ;
       
    42 }
       
    43 
       
    44 my %ComponentVersion = GetDPComp::GenerateComponentVersion( $iBaselineComponentVersion, $iBaselineComponentName ) ;
       
    45 
       
    46 if ( scalar(@$iComponentNames) == 0 ) {
       
    47   open(INPUT, "<$iInputFile") or die $! ;
       
    48   (@$iComponentNames) = <INPUT>;
       
    49   close(INPUT);
       
    50 }
       
    51 
       
    52 if ($iSource)
       
    53 {
       
    54   $iSource = "-s";
       
    55 } else {
       
    56   $iSource = "";
       
    57 }
       
    58 
       
    59 foreach my $includecomponent ( @$iComponentNames ){
       
    60   $includecomponent = GetDPComp::LRtrim( $includecomponent );
       
    61   print "getrel -v $iSource -o $includecomponent $ComponentVersion{$includecomponent} \n";
       
    62   `getrel -v $iSource -o $includecomponent $ComponentVersion{$includecomponent} `;
       
    63 }
       
    64 
       
    65 open(UPDATE, ">$iOutputFile") or die $! ;
       
    66 foreach my $includecomponent ( @$iComponentNames ){
       
    67   $includecomponent = GetDPComp::LRtrim( $includecomponent );
       
    68   print UPDATE "$includecomponent => $ComponentVersion{$includecomponent} \n";
       
    69 }
       
    70 close(UPDATE);
       
    71 
       
    72 # ProcessCommandLine
       
    73 #
       
    74 # Description
       
    75 # This function processes the commandline
       
    76 sub ProcessCommandLine {
       
    77   my (@iComponentNames, $iInputFile, $iBaselineComponentName, $iBaselineComponentVersion, $iSource, $iOutputFile, $iHelp);
       
    78 
       
    79   GetOptions('c=s@' => \@iComponentNames, 'cf=s' => \$iInputFile, 'bc=s' => \$iBaselineComponentName, 'bv=s' => \$iBaselineComponentVersion, 's' => \$iSource, 'o=s' => \$iOutputFile, 'h' => \$iHelp);
       
    80   Usage() if ($iHelp);
       
    81 
       
    82   Usage("-c and -cf can not use together") if ( (scalar(@iComponentNames) > 0 ) and (defined $iInputFile));
       
    83   Usage("Must specify component via -c or component list via -cf") if (( scalar(@iComponentNames) == 0 ) and ( ! defined $iInputFile) );
       
    84   Usage("Must specify baseline component version via -bv and output file name via -o") if ((! defined $iBaselineComponentVersion) or (! defined $iOutputFile) );
       
    85 
       
    86   return(\@iComponentNames, $iInputFile, $iBaselineComponentName, $iBaselineComponentVersion, $iSource, $iOutputFile);
       
    87 }
       
    88 
       
    89 # Usage
       
    90 #
       
    91 # Output Usage Information.
       
    92 #
       
    93 
       
    94 sub Usage {
       
    95   my ($reason) = @_;
       
    96   
       
    97   print "ERROR: $reason\n" if ($reason);
       
    98   
       
    99   print <<USAGE_EOF;
       
   100 
       
   101   Usage: GetDPComp.pl [Args]
       
   102 
       
   103   Args: 
       
   104   -c <Specified component name>, [Multiple -c options allowed], this option should not use together with -cf option.
       
   105   -cf <Specified file name which contains list of component name>, this option should not use together with -c option.
       
   106   -bc <Specified basline component name>, e.g. developer_product_baseline, this argument is optional.
       
   107   -bv <Version string for baseline component specified by -bc or sf_tools_baseline>, valid input: latest, green, #specifiednumber. 
       
   108   -s                    install (and overwrite) source code, this is optional argument.
       
   109   -o  <Specified file name which records version information for component specified by -c or components specified by -cf>
       
   110   -h                    help
       
   111   
       
   112   
       
   113   Example Commandline
       
   114   GetDPComp.pl -s -c tools_sbs -bc developer_product_baseline -bv green -o component_version.txt
       
   115   GetDPComp.pl -s -c tools_sbs -bc developer_product_baseline -bv latest -o component_version.txt
       
   116   GetDPComp.pl -s -c tools_sbs -bc developer_product_baseline -bv DP00454_DeveloperProduct -o component_version.txt
       
   117   GetDPComp.pl -cf component_list.txt -bv green -o component_version.txt
       
   118   GetDPComp.pl -cf component_list.txt -bv latest -o component_version.txt
       
   119   GetDPComp.pl -cf component_list.txt -bv DP00454_DeveloperProduct -o component_version.txt
       
   120   GetDPComp.pl -c dev_build_sbsv2_raptor -c dev_build_sbsv2_cpp-raptor -c dev_hostenv_dist_cygwin-1.5.25 -c dev_hostenv_dist_mingw-5.1.4 -c dev_hostenv_pythontoolsplat_python-2.5.2 -bv green -o component_version.txt
       
   121   GetDPComp.pl -h
       
   122 
       
   123 USAGE_EOF
       
   124 	exit 1;
       
   125 }