sbsv1_os/e32toolp/toolinfo/rvct_ver2set.pm
changeset 0 83f4b4db085c
child 10 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2008-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 # This module provides a mapping from RVCT versions to the corresponding environment
       
    15 # settings. The information is obtained from a configuration file pointed to by the
       
    16 # environment variable ABLD_RVCT_INI. The following example shows the file's
       
    17 # structure:
       
    18 # [2.2.616]
       
    19 # bin=C:\Apps\ARM-RVCT\2.2.616\bin
       
    20 # inc=C:\Apps\ARM-RVCT\2.2.616\inc
       
    21 # lib=C:\Apps\ARM-RVCT\2.2.616\lib
       
    22 # [3.1.700]
       
    23 # bin=C:\Apps\ARM-RVCT\3.1.700\bin
       
    24 # inc=C:\Apps\ARM-RVCT\3.1.700\inc
       
    25 # lib=C:\Apps\ARM-RVCT\3.1.700\lib
       
    26 # If the file is used, it must contain at least one section.
       
    27 # 
       
    28 #
       
    29 
       
    30 
       
    31 package RVCT_ver2set;
       
    32 use strict;
       
    33 
       
    34 #
       
    35 # PUBLIC FUNCTIONS
       
    36 #
       
    37 
       
    38 # Returns a list of available RVCT versions, for example ["2.2.435", "2.2.616"].
       
    39 sub get_versions();
       
    40 
       
    41 # Returns true if the given RVCT version exists.
       
    42 sub compiler_exists($);
       
    43 
       
    44 # Given an RVCT version, returns what the name and value of the RVCT??BIN
       
    45 # variable would be. 
       
    46 sub get_bin_name($);
       
    47 sub get_bin_path($);
       
    48 
       
    49 # Given an RVCT version, returns what the name and value of the RVCT??INC
       
    50 # variable would be. 
       
    51 sub get_inc_name($);
       
    52 sub get_inc_path($);
       
    53 
       
    54 # Given an RVCT version, returns what the name and value of the RVCT??LIB
       
    55 # variable would be. 
       
    56 sub get_lib_name($);
       
    57 sub get_lib_path($);
       
    58 
       
    59 
       
    60 #
       
    61 # PRIVATE HELPER FUNCTIONS
       
    62 #
       
    63 
       
    64 # Prints an error message and then terminates.
       
    65 sub _err_and_die(@);
       
    66 
       
    67 
       
    68 #
       
    69 # GLOBAL DATA
       
    70 #
       
    71 
       
    72 # Contains all the information read from the configuration file.
       
    73 my %g_data;
       
    74 
       
    75 
       
    76 sub get_versions()
       
    77 {
       
    78     return sort(keys %g_data);
       
    79 }
       
    80 
       
    81 sub compiler_exists($)
       
    82 {
       
    83     my $vers = shift;
       
    84     return ( $g_data{$vers} ); 
       
    85 }
       
    86 
       
    87 sub get_bin_name($)
       
    88 {
       
    89     my $vers = shift;
       
    90     return $g_data{$vers}->{bin_name}; 
       
    91 }
       
    92 
       
    93 sub get_bin_path($)
       
    94 {
       
    95     my $vers = shift;
       
    96     return $g_data{$vers}->{bin_path}; 
       
    97 }
       
    98 
       
    99 sub get_inc_name($)
       
   100 {
       
   101     my $vers = shift;
       
   102     return $g_data{$vers}->{inc_name}; 
       
   103 }
       
   104 
       
   105 sub get_inc_path($)
       
   106 {
       
   107     my $vers = shift;
       
   108     return $g_data{$vers}->{inc_path}; 
       
   109 }
       
   110 
       
   111 sub get_lib_name($)
       
   112 {
       
   113     my $vers = shift;
       
   114     return $g_data{$vers}->{lib_name}; 
       
   115 }
       
   116 
       
   117 sub get_lib_path($)
       
   118 {
       
   119     my $vers = shift;
       
   120     return $g_data{$vers}->{lib_path}; 
       
   121 }
       
   122 
       
   123 sub _err_and_die(@)
       
   124 {
       
   125     print STDERR "error: @_\n";
       
   126     exit 1;
       
   127 }
       
   128 
       
   129 
       
   130 # initialize module
       
   131 {
       
   132     my $fname = $ENV{ABLD_RVCT_INI};
       
   133 
       
   134     if ($fname) # The environment varaible is set.
       
   135     {
       
   136         _err_and_die("ABLD_RVCT_INI doesn't point to a file.") unless -f $fname;
       
   137 
       
   138         open (my $in,  "<",  $fname) or _err_and_die("couldn't open ABLD_RVCT_INI = $fname.");
       
   139 
       
   140         my @lines = ();
       
   141 
       
   142         while (<$in>)
       
   143         {
       
   144             chomp;
       
   145 
       
   146             next if /^\s*;/ ;
       
   147             next if /^\s*#/ ;
       
   148             next if /^\s*$/ ;
       
   149 
       
   150             push @lines, $_;
       
   151         }
       
   152 
       
   153         close $in or _err_and_die("couldn't close ABLD_RVCT_INI = $fname.");
       
   154 
       
   155         while (@lines)
       
   156         {
       
   157             my $ver = shift @lines;
       
   158             my $kv1 = shift @lines;
       
   159             my $kv2 = shift @lines;
       
   160             my $kv3 = shift @lines;
       
   161 
       
   162             my $Mm = "";
       
   163 
       
   164             if ( $ver =~ /^\s*\[(\d+)\.(\d+)\.(\d+)\]\s*$/ )
       
   165             {
       
   166                 _err_and_die("$fname: duplicate section: $ver.") if $g_data{$1};
       
   167                 $ver = "$1.$2.$3";
       
   168                 $Mm  = "$1$2";
       
   169             }
       
   170             else
       
   171             {
       
   172                 _err_and_die("$fname: invalid section header: $ver.");
       
   173             }
       
   174 
       
   175             my %kv = ();
       
   176 
       
   177             for ($kv1, $kv2, $kv3)
       
   178             {
       
   179                 _err_and_die("$fname: not enough data in section $ver.") unless $_;
       
   180 
       
   181                 if ( $_ =~ /^\s*(bin|inc|lib)\s*=(.*)$/i )
       
   182             {
       
   183                     my $key = uc($1);
       
   184                     my $val = $2;
       
   185 
       
   186                     $val =~ s/^\s+//;
       
   187                     $val =~ s/\s+$//;
       
   188 
       
   189                     _err_and_die("$fname: in section $ver: \"$key\" doesn't point to a directory.") unless -d $val;
       
   190                     _err_and_die("$fname: in section $ver: duplicate key \"$key\".") if $kv{$key};
       
   191 
       
   192                     $kv{$key} = $val;
       
   193                 }
       
   194                 else
       
   195                 {
       
   196                     _err_and_die("$fname: in section $ver: invalid line \"$_\".");
       
   197                 }
       
   198             }
       
   199 
       
   200             $g_data{$ver}->{bin_name} = "RVCT${Mm}BIN";
       
   201             $g_data{$ver}->{bin_path} = "$kv{BIN}";
       
   202             $g_data{$ver}->{inc_name} = "RVCT${Mm}INC";
       
   203             $g_data{$ver}->{inc_path} = "$kv{INC}";
       
   204             $g_data{$ver}->{lib_name} = "RVCT${Mm}LIB";
       
   205             $g_data{$ver}->{lib_path} = "$kv{LIB}";
       
   206         }
       
   207 
       
   208     }
       
   209     else
       
   210     {
       
   211         # ABLD_RVCT_INI isn't set. This is not an error. All public functions will
       
   212         # return NULL.
       
   213     }
       
   214 }
       
   215 
       
   216 1;
       
   217 
       
   218