imgtools/buildrom/tools/externaltools.pm
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 #
       
     2 # Copyright (c) 2005-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 # This package invokes single and multiple external tools
       
    16 #
       
    17 
       
    18 package externaltools;
       
    19 
       
    20 require Exporter;
       
    21 @ISA=qw (Exporter);
       
    22 @EXPORT=qw (
       
    23 	loadTools
       
    24 	runExternalTool
       
    25 		
       
    26 );
       
    27 
       
    28 use Modload; # Dynamically loads the module
       
    29 my %invocations; # Indexed by invocation name;
       
    30 
       
    31 #Set the Module path to load perl modules
       
    32 {
       
    33 	my $epocToolsPath = $ENV{EPOCROOT}."epoc32\\tools\\";
       
    34 	Load_SetModulePath($epocToolsPath);
       
    35 }
       
    36 
       
    37 # Get all the external tool perl module files to load them
       
    38 sub loadTools{
       
    39 	
       
    40 	my $toolList = shift;
       
    41 	my @toolModules = split(/,/,$toolList);
       
    42 	foreach my $tool (@toolModules) {
       
    43 		# An optional command line can be passed to the tool if it is of the form "<toolname>[:<cmdline>]"
       
    44 		if ($tool !~ /^([^:]+)(:(.*))?$/) {
       
    45 			print "No tool specified as parameter for external tool invocation\n";
       
    46 		}
       
    47 		my $toolName = $1;
       
    48 		my $toolCmdLine = $3;
       
    49 		&Load_ModuleL($toolName);
       
    50 		my $toolDetailsMap = $toolName.'::' . $toolName.'_info';
       
    51 		update(&$toolDetailsMap, $toolCmdLine);
       
    52 	}
       
    53 }
       
    54 
       
    55 #Initialises information from external tool
       
    56 sub update 
       
    57 {
       
    58 	my ($info, $toolCmdLine) = @_;
       
    59 	my $toolName;
       
    60 	my $toolStage;
       
    61 
       
    62 	# name - name of the tool. used to associate with appropriate oby tool
       
    63 	#		keyword
       
    64 	# invocation - stage when tool shall be invoked.
       
    65 	# multiple - routine to invoke for multiple invocation
       
    66 	# single - routine to invoke for single invocation
       
    67 	# initialize - optional routine to initialize tool before main invocation.
       
    68 	# 
       
    69 	if (defined ($info->{name})) {
       
    70 		$toolName = $info->{name};
       
    71 	}
       
    72 	if (defined ($info->{invocation})) {
       
    73 		$toolStage = lc $info->{invocation};
       
    74 	}
       
    75     
       
    76     push @{$invocations{$toolStage}}, $info;
       
    77 	
       
    78 	if (defined ($info->{initialize}))
       
    79 		{
       
    80 		&{$$info{'initialize'}}($toolCmdLine);
       
    81 		}
       
    82 }
       
    83 
       
    84 # Called between the buildrom stage to invoke single or multiple invocation
       
    85 sub runExternalTool {
       
    86 	
       
    87 	my ($stageName,$OBYData) = @_;
       
    88 	$stageName = lc $stageName;
       
    89 	my @toolInfoList =  @{$invocations{$stageName}}; # Collect Tools with respect to its stagename.
       
    90 	
       
    91 	foreach my $tool (@toolInfoList) { # Traverse for the tools
       
    92 
       
    93 		if (exists($tool->{single})) {#Check if single invocation exists
       
    94 			if (defined ($OBYData)) {
       
    95 				invoke_single($OBYData, $tool);
       
    96 			}				
       
    97 			else {
       
    98 				print "Empty OBYData array reference in Single Invocation\n";
       
    99 			}
       
   100 
       
   101 		}#End Single if 
       
   102 
       
   103 		if (exists($tool->{multiple})) { #Check if multiple invocation exists
       
   104 			if (defined ($OBYData)) { 
       
   105 				# Called from appropriate stage to invoke multiple invocation
       
   106 				invoke_multiple($OBYData, $tool);
       
   107 			}
       
   108 			else {
       
   109 				print "Empty OBYData Line in Multiple Invocation\n";
       
   110 			}
       
   111 
       
   112 		}#End Multiple if 
       
   113 
       
   114 	}#End of tool traversal
       
   115 	
       
   116 }#End of Method
       
   117 
       
   118 #Runs Tool for each line of the OBY file
       
   119 #Gets modified line and adds to OBY line data reference
       
   120 sub invoke_multiple
       
   121 {
       
   122     my ($OBYDataRef,$tool) = @_;
       
   123 	my $modifiedOBYLine;
       
   124 	my $toolName;
       
   125 	my $index = 0;# Index each OBY line
       
   126 	my $arrayLength = scalar(@$OBYDataRef);
       
   127 	my $OBYLineRef;
       
   128 
       
   129 	while ($index < $arrayLength) {
       
   130 
       
   131 		$OBYLineRef = \$OBYDataRef->[$index];# Get the line reference
       
   132 			
       
   133 		if ($$OBYLineRef =~/tool=(\w+)/){ # Match for 'tool' keyword
       
   134 			$toolName = $1;
       
   135 
       
   136 			if ($toolName eq $tool->{name}) {# Match the tool name
       
   137 				my $routine=$tool->{multiple};
       
   138 				$modifiedOBYLine = &$routine($$OBYLineRef); #Invoke multiple Invocation, get modified line
       
   139 			
       
   140 				if (defined ($modifiedOBYLine)) { # If line is not empty
       
   141 					$$OBYLineRef = $modifiedOBYLine; # Modify the line reference with new line
       
   142 				}
       
   143 
       
   144 			}#End of if toolname match
       
   145 
       
   146 		}#End of if 'tool' keyword match
       
   147 
       
   148 		$index++; # For each line of OBY file.
       
   149 	
       
   150 	}#End of oby line traversal <while>
       
   151 
       
   152 }
       
   153 
       
   154 #Runs Tool only once.
       
   155 #Add new data to the obydata array reference.
       
   156 sub invoke_single {
       
   157 
       
   158     my ($OBYDataRef,$tool) = @_;
       
   159     my $routine = $tool->{single};
       
   160     &$routine($OBYDataRef);#Invoke single Invocation, update new data
       
   161 }
       
   162 
       
   163 
       
   164 
       
   165 1;