bldsystemtools/commonbldutils/subst.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 subst and un-subst drives
       
    15 # 
       
    16 #
       
    17 
       
    18 use strict;
       
    19 use Getopt::Long;
       
    20 
       
    21 my ($drive, $path, $delete, $force) = &ProcessCommandLine;
       
    22 
       
    23 die "ERROR: Bad virtual drive \"$drive\"" if $drive !~ /^\w:$/;
       
    24 
       
    25 if ($delete)
       
    26 {
       
    27   system "subst /d $drive";
       
    28   die("ERROR: Could not un-subst \"$drive\"") if $?;
       
    29 }
       
    30 else
       
    31 {
       
    32   die "ERROR: \"$path\" does not exist" if !-d $path;
       
    33   `subst /d $drive` if $force;
       
    34   system "subst $drive $path";
       
    35   die("ERROR: Could not subst \"$path\" to \"$drive\"") if $?;
       
    36 }
       
    37 
       
    38 # Subst has been successful
       
    39 print "Resultant subst mappings:\n";
       
    40 my $output = `subst`;
       
    41 $output ? print $output : print "None";
       
    42 
       
    43 # End of script
       
    44 
       
    45 sub ProcessCommandLine {
       
    46   my ($iHelp, $iDrive, $iPath, $iDelete, $iForce);
       
    47   GetOptions('h'   => \$iHelp,
       
    48              'v=s' => \$iDrive,
       
    49              'p=s' => \$iPath,
       
    50              'd'   => \$iDelete,
       
    51              'f'   => \$iForce);
       
    52 
       
    53   if (($iHelp) || (!defined $iDrive) || ((!defined $iPath)&&(!defined $iDelete)))
       
    54   {
       
    55     Usage();
       
    56   } 
       
    57   else 
       
    58   {
       
    59     return($iDrive, $iPath, $iDelete, $iForce);
       
    60   }
       
    61 }
       
    62 
       
    63 # Usage
       
    64 #
       
    65 # Output Usage Information.
       
    66 #
       
    67 
       
    68 sub Usage {
       
    69   print <<USAGE_EOF;
       
    70 
       
    71 Usage: subst.pl [options]
       
    72 
       
    73 options:
       
    74 
       
    75   -d  delete the SUBSTed virtual drive
       
    76   -h  help
       
    77   -f  force an un-subst first in case drive is already SUBSTed
       
    78   -p  <physical path>
       
    79   -v  <virtual drive>
       
    80 
       
    81 For example "subst.pl -v z: -p d:\\master\\03237" will subst the directory
       
    82 "d:\\master\\03237" to the virtual drive "z:"
       
    83 USAGE_EOF
       
    84   exit 1;
       
    85 }