bldsystemtools/commonbldutils/buildenv.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Script to get version of various tools and Windows hotfixes and write to XML file
       
    15 # 
       
    16 #
       
    17 
       
    18 use strict;
       
    19 use Getopt::Long;
       
    20 use File::Copy;
       
    21 use Sys::Hostname;
       
    22 use FindBin;
       
    23 use lib $FindBin::Bin;
       
    24 use Carp;
       
    25 use buildenv;
       
    26 
       
    27 # Process the commandline
       
    28 my ($gHostName, $gXMLfilePathname) = ProcessCommandLine();
       
    29 
       
    30 &buildenv::Main($gHostName, $gXMLfilePathname);
       
    31 
       
    32 # ProcessCommandLine
       
    33 #
       
    34 # Inputs
       
    35 # Command line options via GetOptions()
       
    36 #
       
    37 # Returns
       
    38 # Hostname, XML output file name
       
    39 #
       
    40 # Description
       
    41 # This function processes the commandline and also establishes hostname and hence XML file name
       
    42 
       
    43 sub ProcessCommandLine {
       
    44   my ($iHelp, $iXMLfileLocation);
       
    45   GetOptions('h' => \$iHelp, 'o=s' => \$iXMLfileLocation);
       
    46 
       
    47   if ($iHelp) { Usage(); }
       
    48   
       
    49   if (!defined $iXMLfileLocation)
       
    50   {
       
    51     $iXMLfileLocation = '.\\';
       
    52   }
       
    53 
       
    54   # add trailing backslash if missing, and add filename as hostname.xml
       
    55   $iXMLfileLocation =~ s/[^\\]$/$&\\/;
       
    56 
       
    57 # Validate output directory. NB: If option not given, undef defaults to current directory!
       
    58   confess("ERROR: $iXMLfileLocation not a directory: $!") if !-d $iXMLfileLocation;
       
    59   my $iHostName = hostname;     # Depends on "use Sys::Hostname;"
       
    60   $iHostName =~ s/\.intra$//i;  # Remove trailing ".intra" if any.
       
    61   $iXMLfileLocation = $iXMLfileLocation . $iHostName ."\.xml";
       
    62 
       
    63   &backupFile($iXMLfileLocation) if (-e $iXMLfileLocation);
       
    64   return($iHostName, $iXMLfileLocation);    # NB: $iXMLfileLocation is now the full pathname of the output file
       
    65 }
       
    66 
       
    67 # backupFile
       
    68 #
       
    69 # Inputs
       
    70 # $iFile - filename to backup
       
    71 #
       
    72 # Outputs
       
    73 #
       
    74 # Description
       
    75 # This function renames an existing file with the .bak extension
       
    76 sub backupFile
       
    77 {
       
    78 	my ($iFile) = @_;
       
    79 	my ($iBak) = $iFile.".bak";
       
    80 	
       
    81 	if (-e $iFile)
       
    82 	{
       
    83 	    print "WARNING: $iFile already exists, creating backup of orignal with new name of $iBak\n";
       
    84 	    move($iFile,$iBak) or die "Could not backup $iFile to $iBak because of: $!\n";	  
       
    85 	}
       
    86 }
       
    87 
       
    88 # Usage
       
    89 #
       
    90 # Output Usage Information and exit
       
    91 #
       
    92 
       
    93 sub Usage {
       
    94   print <<USAGE_EOF;
       
    95 
       
    96   Usage: BuildEnv.pl [options]
       
    97 
       
    98   options:
       
    99 
       
   100   -h  Display this Help and exit
       
   101   -o  Directory in which to write output XML file (defaults to current)
       
   102       e.g \\\\Builds01\\Devbuilds\\BuildPCs\\BldEnvData\\2006-04-24
       
   103       Name will be added automatically as the host computername,
       
   104       extension as '.XML'
       
   105 USAGE_EOF
       
   106 	exit 1;
       
   107 }