author | marvin shi <marvin.shi@nokia.com> |
Wed, 17 Nov 2010 14:05:07 +0800 | |
changeset 691 | 9eeecb73a5d4 |
parent 647 | 53d1ab72f5bc |
permissions | -rw-r--r-- |
606 | 1 |
# |
2 |
# Copyright (c) 2006-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 contains fuctions specific to data drive image generation |
|
16 |
# |
|
17 |
||
18 |
||
19 |
package datadriveimage; |
|
20 |
||
21 |
require Exporter; |
|
22 |
@ISA=qw(Exporter); |
|
23 |
@EXPORT=qw( |
|
24 |
createDirectory |
|
25 |
deleteDirectory |
|
26 |
checkInArray |
|
27 |
setPath |
|
28 |
locateStubsisfiles |
|
29 |
copyFilesToFolders |
|
30 |
checkForSisFile |
|
31 |
copyNonSisFiles |
|
32 |
invokeInterpretsis |
|
33 |
invokeReadImage |
|
34 |
compareArrays |
|
35 |
dumpDatadriveObydata |
|
36 |
TraverseDir |
|
37 |
writeDataToFile |
|
38 |
generate_datadriveheader |
|
39 |
checkForWhiteSpace |
|
40 |
reportError |
|
41 |
); |
|
42 |
||
43 |
use strict; |
|
44 |
use File::Path; # Module to provide functions to remove or create directories in a convenient way. |
|
45 |
use File::Copy; # Module to provide functions to copy file(s) from source to destination. |
|
46 |
||
47 |
use Cwd; # Module to provide functions for determining the pathname of the current working directory. |
|
48 |
||
49 |
use romutl; |
|
50 |
use romosvariant; |
|
51 |
||
52 |
# This fuction is used primiarly to check for whitespace in the location for "zdrive" / "datadrive" folder creation, |
|
53 |
# specified by the user, if yes then it returns one, else zero |
|
54 |
sub checkForWhiteSpace |
|
55 |
{ |
|
56 |
my ($dirLoc,$dirName) = @_; |
|
57 |
if( $dirLoc =~ m/ / ) |
|
58 |
{ |
|
59 |
print "* Warning: $dirLoc contains whitespace, hence $dirName will be created in default location \n"; |
|
60 |
return 1; |
|
61 |
} |
|
62 |
else |
|
63 |
{ |
|
64 |
return 0; |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
||
69 |
# This function reports the appropriate meassage supplied to it |
|
70 |
# and does a exit if and only if keepgoing option is disabled. |
|
71 |
sub reportError |
|
72 |
{ |
|
73 |
my( $message,$keepgoingOpt ) = @_; |
|
74 |
# print the specified meassage. |
|
75 |
print STDERR "$message \n"; |
|
76 |
# bail out, if keepgoing option is not set. |
|
77 |
exit(1) if (!$keepgoingOpt); |
|
78 |
} |
|
79 |
||
80 |
# generate header for final datadrive oby file. |
|
81 |
sub generate_datadriveheader |
|
82 |
{ |
|
83 |
my ($idx,$datadriveimage) = @_; |
|
84 |
my $header; |
|
85 |
$header = "dataimagename=$$datadriveimage[$idx]{name}.img\n"; |
|
86 |
$header .= "dataimagefilesystem=$$datadriveimage[$idx]{fstype}\n"; |
|
87 |
||
88 |
# check whether the size of the image has been mentioned |
|
89 |
if(defined($$datadriveimage[$idx]{size})) |
|
90 |
{ |
|
91 |
$header .= "dataimagesize=$$datadriveimage[$idx]{size}\n\n"; |
|
92 |
} |
|
93 |
return $header; |
|
94 |
} |
|
95 |
||
96 |
# Create the specified directory by making use of mkpath function |
|
97 |
# from File::Path module. |
|
98 |
sub createDirectory |
|
99 |
{ |
|
100 |
my($dir) = @_; |
|
101 |
if( !-d $dir ) |
|
102 |
{ |
|
103 |
mkpath($dir); |
|
104 |
if (! -e $dir) |
|
105 |
{ |
|
106 |
print ("ERROR: Couldn't create $dir\n"); |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
# check if the given file is a reg file or ctl file or a txt file |
|
112 |
# if it is any of these files then return true else false. |
|
113 |
# This check is need since these three files or not valid not valid e32 file |
|
114 |
# and hence needs to be placed as an data file inside the image. |
|
115 |
sub checkRegCtlFiles |
|
116 |
{ |
|
117 |
my ($fileName) = @_; |
|
118 |
||
119 |
# check whether the file has "reg","ctl" or "txt" extension. |
|
120 |
if( $fileName =~/\.(reg|ctl|txt)$/i ) |
|
121 |
{ |
|
122 |
return 1; |
|
123 |
} |
|
124 |
else |
|
125 |
{ |
|
126 |
return 0; |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
# delete the given directory by making use of rmtree function |
|
131 |
# from File::Path module. |
|
132 |
sub deleteDirectory |
|
133 |
{ |
|
134 |
my($dir,$verboseOpt) = @_; |
|
135 |
# check whether the directory exists. |
|
136 |
if( -d $dir ) |
|
137 |
{ |
|
138 |
print("found $dir directory \n") if($verboseOpt); |
|
139 |
if(rmtree($dir)) |
|
140 |
{ |
|
141 |
print("$dir directory deleted \n") if($verboseOpt); |
|
142 |
return 0; |
|
143 |
} |
|
144 |
else |
|
145 |
{ |
|
146 |
print("$dir directory could'nt be deleted \n") if($verboseOpt); |
|
147 |
return 1; |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
# check for processed data drive image index. |
|
153 |
# if there is a match return one else return zero. |
|
154 |
# this check is done in order to ensure data drive image index is not repeated. |
|
155 |
sub checkInArray |
|
156 |
{ |
|
157 |
my($array, $value) = @_; |
|
158 |
foreach my $aLine(@$array) |
|
159 |
{ |
|
160 |
if( $aLine eq $value ) |
|
161 |
{ |
|
162 |
return 0; |
|
163 |
} |
|
164 |
} |
|
165 |
return 1; |
|
166 |
} |
|
167 |
||
168 |
# set the path for the given directory. |
|
169 |
sub setPath |
|
170 |
{ |
|
171 |
my($dirName) = @_; |
|
172 |
# get the working directory. |
|
173 |
my $curWorkingDir = getcwd; |
|
174 |
# substitute slash with double backward slash. |
|
175 |
$curWorkingDir =~ s/\\/\//g; |
|
176 |
#if $curWorkingDir already has trailing '\', don't include it again |
|
177 |
if( $curWorkingDir =~ /\/$/) |
|
178 |
{ |
|
179 |
return $curWorkingDir.$dirName; |
|
180 |
} |
|
181 |
else |
|
182 |
{ |
|
183 |
return $curWorkingDir."\/".$dirName; |
|
184 |
} |
|
185 |
} |
|
186 |
||
187 |
# create directory and copy respective file on to that directory. |
|
188 |
# is there is a problem while copying files from source to destination |
|
189 |
# then bail out if and only if keep going option is disabled. |
|
190 |
sub copyFilesToFolders |
|
191 |
{ |
|
192 |
my ($source,$dest,$dir,$verboseOpt) = @_; |
|
193 |
$source =~ s/\"//g; # remove double quotes from the string. |
|
194 |
my $destFileName = ""; # name of the destination file. |
|
195 |
$dest =~ s/\"//g; # remove double quotes from the string. |
|
196 |
my $destDirectory = $dest; |
|
197 |
# strip the last substring to get destination file |
|
198 |
if ($dest=~/.*[\/\\](\S+)/) |
|
199 |
{ |
|
200 |
$destFileName = $1; |
|
201 |
} |
|
202 |
else |
|
203 |
{ |
|
204 |
$destFileName = $dest; |
|
205 |
} |
|
206 |
#get the destination directory along with full path |
|
207 |
#when "[" and "]" appear in the file name we need add "\" before "[" or "]" |
|
208 |
#like this: [filename].exe translate to \[filename\].exe |
|
209 |
if($destFileName =~ /\[|\]/) |
|
210 |
{ |
|
211 |
my $tempFileName = $destFileName; |
|
212 |
$tempFileName =~ s/(\[|\])/\\$1/g; |
|
213 |
$destDirectory =~ s/$tempFileName//; |
|
214 |
} |
|
215 |
else |
|
216 |
{ |
|
217 |
$destDirectory =~ s/$destFileName//; |
|
218 |
} |
|
219 |
my $destfile = $dir."\/".$dest; |
|
220 |
my $createdir = $dir."\/".$destDirectory ; |
|
221 |
||
222 |
# create the specified directory. |
|
223 |
&createDirectory($createdir); |
|
224 |
if (!copy($source,$destfile)) |
|
225 |
{ |
|
226 |
warn "warning : $source file could not found \n"; |
|
227 |
return 0; |
|
228 |
} |
|
229 |
else |
|
230 |
{ |
|
231 |
print "$source copied to $destfile\n" if($verboseOpt); |
|
232 |
return "\"".$destfile."\""; |
|
233 |
} |
|
234 |
} |
|
235 |
||
236 |
# Make a check for sisfile keyword by reading the specified iby/oby file, |
|
237 |
# if sisfile keyword is found then push the respective image on to the respective array |
|
238 |
# and return true. |
|
239 |
sub checkForSisFile |
|
240 |
{ |
|
241 |
my($obyfile,$sisFileArray,$sisFilePrestent) = @_; |
|
242 |
# open the oby file in read only mode. |
|
243 |
open (DATA, "< $obyfile") or die("* Can't open $obyfile\n"); |
|
244 |
while (my $line =<DATA>) |
|
245 |
{ |
|
246 |
if($line =~ /^\s*sisfile\s*=\s*(\S+)/i ) |
|
247 |
{ |
|
248 |
# found a sis file. |
|
249 |
$$sisFilePrestent = 1; |
|
250 |
# push sis file on to stack. |
|
251 |
push(@$sisFileArray,$1); |
|
252 |
next; |
|
253 |
} |
|
254 |
} |
|
255 |
close(DATA); |
|
256 |
return $$sisFilePrestent; |
|
257 |
} |
|
258 |
||
259 |
# Make a check for zdriveimagename keyword by reading the specified iby/oby file, |
|
260 |
# if zdriveimagename keyword is found then push the respective image on to the respective array |
|
261 |
# and return true. |
|
262 |
sub checkForZDriveImageKeyword |
|
263 |
{ |
|
264 |
#$ZDriveImageFilePresent |
|
265 |
my($obyfile,$ZDriveImageKeywordArray,$ImageFilePresent) = @_; |
|
266 |
# open the oby file in read only mode. |
|
267 |
open (DATA, "< $obyfile") or die("* Can't open $obyfile\n"); |
|
268 |
while (my $line =<DATA>) |
|
269 |
{ |
|
270 |
if($line =~ /^\s*zdriveimagename\s*=\s*(\S+)/i ) |
|
271 |
{ |
|
272 |
# found a Z Drive Image file. |
|
273 |
$$ImageFilePresent = 1; |
|
274 |
# push sis file on to stack. |
|
275 |
push(@$ZDriveImageKeywordArray,$1); |
|
276 |
next; |
|
277 |
} |
|
278 |
} |
|
279 |
close(DATA); |
|
280 |
return $$ImageFilePresent; |
|
281 |
} |
|
282 |
||
283 |
# copy all non-sis file(s) on to prototype data drive folder |
|
284 |
# which are mentioned under input data drive iby/oby file. |
|
285 |
sub copyNonSisFiles |
|
286 |
{ |
|
287 |
my($dir,$obyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt) = @_; |
|
288 |
open (OBEY ,$obyfile) or die($obyfile."\n"); |
|
289 |
while(my $line =<OBEY>) |
|
290 |
{ |
|
647 | 291 |
if( $line =~ /^(file|data|dircopy)\s*=\s*(\"[^"]+\")\s+(\"[^"]+\")/i || |
292 |
$line =~ /^(file|data|dircopy)\s*=\s*(\"[^"]+\")\s+(\S+)/i || |
|
293 |
$line =~ /^(file|data|dircopy)\s*=\s*(\S+)\s+(\"[^"]+\")/i || |
|
294 |
$line =~ /^(file|data|dircopy)\s*=\s*(\S+)\s+(\S+)/i ) |
|
606 | 295 |
{ |
296 |
my $keyWord=$1; |
|
297 |
my $source=$2; |
|
298 |
my $dest=$3; |
|
299 |
||
647 | 300 |
my $currentdir=cwd; |
301 |
$currentdir=~s-\\-\/-go; |
|
302 |
$currentdir.= "\/" unless $currentdir =~ /\/$/; |
|
303 |
$currentdir =~ s-\/-\\-g if (&is_windows); |
|
304 |
my $drive = ""; |
|
305 |
$drive = $1 if ($currentdir =~ /^(.:)/); |
|
306 |
$source =~ s/\"//g; |
|
307 |
if ($source =~ /^[\\\/]/) |
|
308 |
{ |
|
309 |
$source = $drive.$source; |
|
310 |
}elsif ($source !~ /^.:/) |
|
311 |
{ |
|
312 |
$source = $currentdir.$source; |
|
606 | 313 |
} |
647 | 314 |
$source = "\"".$source."\""; |
315 |
||
316 |
my $var = $source; |
|
317 |
if ($keyWord ne "dircopy"){ |
|
318 |
$var = ©FilesToFolders( $source,$dest,$dir,$verboseOpt); |
|
319 |
} |
|
606 | 320 |
if($var) |
321 |
{ |
|
322 |
$line = $keyWord."=".$var."\t".$dest."\n"; |
|
323 |
push(@$nonsisFileArray,$line); |
|
324 |
} |
|
325 |
else |
|
326 |
{ |
|
327 |
exit(1)if(!$keepgoingOpt); |
|
328 |
} |
|
329 |
} |
|
330 |
elsif($line =~ /^rename\s+(\S+)\s+(\S+)/i) |
|
331 |
{ |
|
332 |
my $oldFile = $dir.$1; # existing-file |
|
333 |
my $newFile = $dir.$2; # destination-file |
|
334 |
print"found rename keyword\nrenaming $oldFile to $newFile\n" if ($verboseOpt); |
|
335 |
if ( rename($oldFile, $newFile) ) |
|
336 |
{ |
|
337 |
# push the line on to the stack. |
|
338 |
push(@$renameArray,$1."\t".$2."\n"); |
|
339 |
} |
|
340 |
else |
|
341 |
{ |
|
342 |
&datadriveimage::reportError("* Warning : can't rename $oldFile to $newFile: $!",$keepgoingOpt); |
|
343 |
} |
|
344 |
} |
|
345 |
elsif($line =~ /^alias\s+(\S+)\s+(\S+)/i) |
|
346 |
{ |
|
347 |
my $exFile = $dir.$1; # existing-file |
|
348 |
my $destFile = $dir.$2; # destination-file |
|
349 |
print"found alias keyword\n" if ($verboseOpt); |
|
350 |
if(!copy($exFile,$destFile)) |
|
351 |
{ |
|
352 |
&datadriveimage::reportError("* warning : couldnt create alias of $1 to $2 ",$keepgoingOpt); |
|
353 |
} |
|
354 |
else |
|
355 |
{ |
|
356 |
# push the line on to the stack. |
|
357 |
push(@$aliasArray,$1."\t".$2."\n"); |
|
358 |
} |
|
359 |
} |
|
360 |
elsif($line =~ /^hide\s+(\S+)/i) |
|
361 |
{ |
|
362 |
print"found hide keyword\n" if ($verboseOpt); |
|
363 |
print "$1 is marked as hidden, hence will not be part of the image\n" if($verboseOpt); |
|
364 |
if( unlink($dir.$1) ) |
|
365 |
{ |
|
366 |
# push the line on to the stack. |
|
367 |
push(@$hideArray,$1); |
|
368 |
} |
|
369 |
else |
|
370 |
{ |
|
371 |
&datadriveimage::reportError("* Warning : Can't delete $1: $! ",$keepgoingOpt); |
|
372 |
} |
|
373 |
} |
|
374 |
} |
|
375 |
close(OBEY); |
|
376 |
} |
|
377 |
||
378 |
# invoke the INTERPRETSIS tool with appropriate parameters. |
|
379 |
sub invokeInterpretsis |
|
380 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
381 |
my($sisFileArray,$dataDrivePath,$verboseOpt,$zDrivePath,$parafile,$keepgoingOpt,$interpretsisOptList,$outputdir) = @_; |
606 | 382 |
my $sisfile = ""; |
383 |
# default system drive letter is specified since interpretsis doesnt allow overloading of options unless default |
|
384 |
# options are specified. |
|
385 |
my $basicOption = "-d C: "; # default system drive letter |
|
386 |
my $command = "interpretsis "; |
|
387 |
my $vOption = "-w info" if ($verboseOpt); |
|
388 |
||
389 |
# do a check if the path has a white space. |
|
390 |
if( $dataDrivePath =~ m/ /) |
|
391 |
{ |
|
392 |
$dataDrivePath = '"'.$dataDrivePath.'"'; |
|
393 |
} |
|
394 |
||
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
395 |
my $currentdir=cwd; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
396 |
$currentdir=~s-\\-\/-go; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
397 |
$currentdir.= "\/" unless $currentdir =~ /\/$/; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
398 |
$currentdir =~ s-\/-\\-g if (&is_windows); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
399 |
my $drive = ""; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
400 |
$drive = $1 if ($currentdir =~ /^(.:)/); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
401 |
|
606 | 402 |
# find out size of the array |
403 |
my $sisarraysize = scalar(@$sisFileArray); |
|
404 |
for( my $i=0; $i<$sisarraysize; $i++ ) |
|
405 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
406 |
my $tempsisfile = pop(@$sisFileArray); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
407 |
if ($tempsisfile =~ /^[\\\/]/) |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
408 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
409 |
$tempsisfile = $drive.$tempsisfile; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
410 |
}elsif ($tempsisfile !~ /^.:/) |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
411 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
412 |
$tempsisfile = $currentdir.$tempsisfile; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
413 |
} |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
414 |
|
606 | 415 |
if($sisfile ne "") |
416 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
417 |
$sisfile = $tempsisfile.",".$sisfile; |
606 | 418 |
} |
419 |
else |
|
420 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
421 |
$sisfile = $tempsisfile; |
606 | 422 |
} |
423 |
} |
|
424 |
||
425 |
# check whether the directory exists or not |
|
426 |
if( -d $zDrivePath ) |
|
427 |
{ |
|
428 |
# do a check if the path has a white space. |
|
429 |
if( $zDrivePath =~ m/ /) |
|
430 |
{ |
|
431 |
$zDrivePath = '"'.$zDrivePath.'"'; |
|
432 |
} |
|
433 |
$basicOption .= "-z $zDrivePath "; |
|
434 |
} |
|
435 |
||
436 |
$basicOption .= "-c $dataDrivePath -s $sisfile $vOption"; |
|
437 |
||
438 |
# if parameter file is specified then invoke the INTERPRETSIS |
|
439 |
# with the specified parameter file with "-p" option. |
|
440 |
if( defined($parafile) ) |
|
441 |
{ |
|
442 |
# do a check if the path has a white space. |
|
443 |
if( $parafile =~ m/ /) |
|
444 |
{ |
|
445 |
$parafile = '"'.$parafile.'"'; |
|
446 |
} |
|
447 |
$command .= "-p $parafile "; |
|
448 |
} |
|
449 |
# else invoke the INTERPRETSIS with default parameter file with "-p" option. |
|
450 |
else |
|
451 |
{ |
|
452 |
# Truncate and open the parameter file for writing.. |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
453 |
$parafile = $outputdir."parameterfile.txt"; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
454 |
open( OPTDATA, "> $parafile" ) or die "can't open $parafile"; |
606 | 455 |
print OPTDATA $basicOption."\n"; |
456 |
close( OPTDATA ); |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
457 |
$command .= "-p $parafile "; |
606 | 458 |
} |
459 |
||
460 |
if( $interpretsisOptList ) |
|
461 |
{ |
|
462 |
# find out size of the array |
|
463 |
my $arraysize = scalar( @$interpretsisOptList ); |
|
464 |
for( my $i = 0; $i < $arraysize; $i++ ) |
|
465 |
{ |
|
466 |
$command .= $$interpretsisOptList[$i]." "; |
|
467 |
} |
|
468 |
} |
|
469 |
||
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
470 |
print "* Changing to $outputdir\n" if ( $verboseOpt ); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
471 |
chdir "$outputdir"; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
472 |
|
647 | 473 |
my $epocroot = &get_epocroot; |
474 |
if ($epocroot !~ /^(.:)/) |
|
475 |
{ |
|
476 |
$ENV{EPOCROOT} = $drive.$epocroot; |
|
477 |
} |
|
606 | 478 |
print "* Executing $command\n" if ( $verboseOpt ); |
479 |
system ( $command ); |
|
480 |
||
481 |
if ($? != 0) |
|
482 |
{ |
|
483 |
&datadriveimage::reportError("* ERROR: INTERPRETSIS failed",$keepgoingOpt); |
|
484 |
} |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
485 |
|
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
486 |
print "* Changing back to $currentdir\n" if ( $verboseOpt ); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
487 |
chdir "$currentdir"; |
647 | 488 |
$ENV{EPOCROOT} = $epocroot; |
606 | 489 |
} |
490 |
||
491 |
# invoke the READIMAGE tool with appropriate parameters. |
|
492 |
sub invokeReadImage |
|
493 |
{ |
|
494 |
my($imageName,$loc,$verboseOpt,$logFile,$keepgoingOpt) = @_; |
|
495 |
my $command = "readimage "; |
|
496 |
||
497 |
is_existinpath("readimage", romutl::DIE_NOT_FOUND); |
|
498 |
||
499 |
# check if log file has been supplied. |
|
500 |
if(defined($logFile)) |
|
501 |
{ |
|
502 |
if( $logFile =~ m/ /) |
|
503 |
{ |
|
504 |
$logFile = '"'.$logFile.'"'; |
|
505 |
} |
|
506 |
$command .= "-l $logFile "; |
|
507 |
} |
|
508 |
||
509 |
# do a check if the path has a white space. |
|
510 |
if( $loc =~ m/ /) |
|
511 |
{ |
|
512 |
$loc = '"'.$loc.'"'; |
|
513 |
} |
|
514 |
$command .= "-z ".$loc." ".$imageName; |
|
515 |
print "* Executing $command\n" if ($verboseOpt); |
|
516 |
system ($command); |
|
517 |
if ($? != 0) |
|
518 |
{ |
|
519 |
&datadriveimage::reportError("* ERROR: READIMAGE failed to read the image",$keepgoingOpt); |
|
520 |
return 0; |
|
521 |
} |
|
522 |
return 1; |
|
523 |
} |
|
524 |
||
525 |
# Each line from the OBY file is read and if any of the line contains "rename"/ "alias" keyword |
|
526 |
# then that corresponding line source and line destination is obtained and is passed to this function as one of the parameters. |
|
527 |
# This fuction compares given array with non-sis file(s) array, when an given line destination matches with the destination of an |
|
528 |
# element in the rename array/alias array(array holding list of file(s) that are renamed / made alias) then, |
|
529 |
# that respective element is removed from the rename array and a further check is made to see whether the given |
|
530 |
# line source matches with the destination of an element in the rename array/alias array.If a match is found then |
|
531 |
# a keyword check is done,if the keyword is "rename" then corresponding element's source and destination file is replaced |
|
532 |
# with given line destination file and if the keyword is "alias" then a new element will be added to non sis file array |
|
533 |
# with line destination file as the source and destination file. |
|
534 |
sub compareArrays |
|
535 |
{ |
|
536 |
my ( $firstarray,$nonsisArray,$linesource,$linedest,$linekeyword ) = @_; |
|
537 |
# count of array element(s). |
|
538 |
my $firstArrayCount = 0; |
|
539 |
# source file. |
|
540 |
my $linesourceFile; |
|
541 |
# destination file. |
|
542 |
my $linedestFile; |
|
543 |
# get source file. |
|
544 |
||
545 |
# strip first occurrence of back slash |
|
546 |
$linesource =~ s/[\/\\]//; |
|
547 |
||
548 |
# get source file. |
|
549 |
if ($linesource =~ /.*[\/\\](\S+)/ ) |
|
550 |
{ |
|
551 |
$linesourceFile = $1; |
|
552 |
} |
|
553 |
# get destination file. |
|
554 |
if ($linedest =~ /.*[\/\\](\S+)/ ) |
|
555 |
{ |
|
556 |
$linedestFile = $1; |
|
557 |
} |
|
558 |
# iterate trough all |
|
559 |
foreach my $firstarrayEntry (@$firstarray) |
|
560 |
{ |
|
561 |
if( $firstarrayEntry =~ /(\S+)\s+(\S+)/ ) |
|
562 |
{ |
|
563 |
my $firstarrayEntrydest = $2; |
|
564 |
||
565 |
if( $linedest eq $firstarrayEntrydest ) |
|
566 |
{ |
|
567 |
# remove the specified element from the array. |
|
568 |
splice(@$firstarray,$firstArrayCount,1); |
|
569 |
# initialize the nonsisFileListCount to zero. |
|
570 |
my $nonsisFileListCount = 0; |
|
571 |
foreach my $nonsisEntry ( @$nonsisArray ) |
|
572 |
{ |
|
573 |
if( $nonsisEntry =~ /^(\S+)=(\S+)\s+(\S+)/ ) |
|
574 |
{ |
|
575 |
my $nonsisEntryDest = $3; |
|
576 |
# remove double quotes. |
|
577 |
$nonsisEntryDest =~ s/\"//g; |
|
578 |
my $nonsisEntryDestFile; |
|
579 |
if ($nonsisEntryDest =~ /.*[\/\\](\S+)/ ) |
|
580 |
{ |
|
581 |
$nonsisEntryDestFile = $1; |
|
582 |
} |
|
583 |
if( $nonsisEntryDest eq $linesource ) |
|
584 |
{ |
|
585 |
if($linekeyword eq "rename") |
|
586 |
{ |
|
587 |
# remove the specified element from the array. |
|
588 |
splice(@$nonsisArray,$nonsisFileListCount,1); |
|
589 |
$nonsisEntry =~ s/$nonsisEntryDestFile/$linedestFile/g; |
|
590 |
push(@$nonsisArray,$nonsisEntry); |
|
591 |
} |
|
592 |
elsif($linekeyword eq "alias") |
|
593 |
{ |
|
594 |
my $newLine = $nonsisEntry; |
|
595 |
$newLine =~ s/$nonsisEntryDestFile/$linedestFile/g; |
|
596 |
push(@$nonsisArray,$newLine); |
|
597 |
} |
|
598 |
} |
|
599 |
} |
|
600 |
$nonsisFileListCount++; |
|
601 |
}#end of loop foreach my $newLine ( @nonsisArray ) |
|
602 |
} |
|
603 |
$firstArrayCount++; |
|
604 |
}#end of loop foreach my $newLine ( @firstarray) |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
# Traverse the entire directory and log the folder contents on to a file. |
|
609 |
sub dumpDatadriveObydata |
|
610 |
{ |
|
611 |
#assign a temporary name and extension to the new oby file. |
|
612 |
my $newobyfile = "temp.$$"; |
|
613 |
my ($datadir,$oldobyfile,$size,$nonsisFileArray,$renameArray,$aliasArray, |
|
614 |
$hideArray,$sisobyArray,$datadriveArray,$keepgoingOpt,$verboseOpt) = @_; |
|
615 |
# get the working directory. |
|
616 |
my $curWorkingDir = getcwd; |
|
617 |
# traverse the updated data drive directory structure. |
|
618 |
&TraverseDir($datadir,"",$sisobyArray,$datadir); |
|
619 |
# change the directrory to the Working directory. |
|
620 |
chdir($curWorkingDir); |
|
621 |
# copy non-sis file(s) on to prototype data drive folder. |
|
622 |
copyNonSisFiles($datadir,$oldobyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt); |
|
623 |
#open the oby file in read-only mode. |
|
624 |
open (OLDDATA, "< $oldobyfile") or die("* Can't open $oldobyfile\n"); |
|
625 |
# Truncate and open the new oby file for writing.. |
|
626 |
open(NEWDATA, "> $newobyfile") or die "can't open $newobyfile"; |
|
627 |
while (my $line =<OLDDATA>) |
|
628 |
{ |
|
629 |
if( $line =~ /^hide\s+(\S+)/i) |
|
630 |
{ |
|
631 |
my $lineToSearch = $1; |
|
632 |
my $hideListCount = 0; |
|
633 |
foreach my $newLine ( @$hideArray ) |
|
634 |
{ |
|
635 |
if( $newLine eq $lineToSearch ) |
|
636 |
{ |
|
637 |
splice(@$hideArray,$hideListCount,1); |
|
638 |
my $nonsisFileListCount = 0; |
|
639 |
foreach my $newLine ( @$nonsisFileArray ) |
|
640 |
{ |
|
641 |
if( $newLine =~ /^(\S+)=(\S+)\s+(\S+)/ ) |
|
642 |
{ |
|
643 |
my $newLineKeyword = $1; |
|
644 |
my $newLinesource = $2; |
|
645 |
my $newLinedest = $3; |
|
646 |
$newLinedest =~ s/\"//g; |
|
647 |
$newLinedest = "\/".$newLinedest; |
|
648 |
if( $newLinedest eq $lineToSearch ) |
|
649 |
{ |
|
650 |
# remove the specified element from the array. |
|
651 |
splice(@$nonsisFileArray,$nonsisFileListCount,1); |
|
652 |
} |
|
653 |
} |
|
654 |
# increment the non sis file list count. |
|
655 |
$nonsisFileListCount++; |
|
656 |
} |
|
657 |
} |
|
658 |
# increment the hide file list count. |
|
659 |
$hideListCount++; |
|
660 |
} |
|
661 |
} |
|
662 |
elsif( $line =~ /^rename\s+(\S+)\s+(\S+)/i) |
|
663 |
{ |
|
664 |
my $linesource = $1 ; |
|
665 |
my $linedest = $2; |
|
666 |
my $linekeyword = "rename"; |
|
667 |
&compareArrays($renameArray,$nonsisFileArray,$linesource,$linedest,$linekeyword); |
|
668 |
} |
|
669 |
elsif( $line =~ /^alias\s+(\S+)\s+(\S+)/i ) |
|
670 |
{ |
|
671 |
my $linesource = $1 ; |
|
672 |
my $linedest = $2; |
|
673 |
my $linekeyword = "alias"; |
|
674 |
&compareArrays($aliasArray,$nonsisFileArray,$linesource,$linedest,$linekeyword); |
|
675 |
} |
|
647 | 676 |
elsif( $line =~ /^(file|data|dircopy)\s*=\s*/i || $line =~ /^\s*(zdriveimagename|sisfile)\s*=\s*/i ) |
606 | 677 |
{ |
678 |
# skip to next line. |
|
679 |
next; |
|
680 |
} |
|
681 |
else |
|
682 |
{ |
|
683 |
# push it on to the array. |
|
684 |
unshift(@$datadriveArray,$line); |
|
685 |
} |
|
686 |
next; |
|
687 |
} |
|
688 |
# close the old oby files. |
|
689 |
close(OLDDATA)or die "can't close $oldobyfile"; |
|
690 |
#write the array contents on to the file |
|
691 |
print"* Updating $oldobyfile - final OBY file\n"; |
|
692 |
&writeDataToFile( $datadriveArray ); |
|
693 |
&writeDataToFile( $sisobyArray ); |
|
694 |
&writeDataToFile( $nonsisFileArray ); |
|
695 |
# close the new oby file. |
|
696 |
close(NEWDATA)or die "can't close $newobyfile"; |
|
697 |
#rename the file. |
|
698 |
rename( $newobyfile, $oldobyfile )or die "can't rename $newobyfile to $oldobyfile: $!"; |
|
699 |
} |
|
700 |
||
701 |
||
702 |
# Traverse the entire given directory |
|
703 |
# push all the folder contents on to an array. |
|
704 |
sub TraverseDir |
|
705 |
{ |
|
706 |
my($dir,$folderList,$sisFileContent,$rootdir) = @_; |
|
707 |
#check the specified directory |
|
708 |
chdir($dir) || die "Cannot chdir to $dir\n"; |
|
709 |
local(*DIR); |
|
710 |
opendir(DIR, ".");#open current directory. |
|
711 |
my $sourcedir; |
|
712 |
my $destdir; |
|
713 |
while (my $entry=readdir(DIR)) |
|
714 |
{ |
|
715 |
#skip, parent directory and current directory. |
|
716 |
next if ($entry eq "." || $entry eq ".."); |
|
717 |
#check if it is a file |
|
718 |
if( -f $entry ) |
|
719 |
{ |
|
720 |
my $sourcedir = $rootdir."\/".$folderList.$entry; |
|
721 |
my $destdir = "$folderList".$entry; |
|
722 |
my $sisSource; |
|
723 |
my $sisdestination; |
|
724 |
if(&checkRegCtlFiles($entry)) |
|
725 |
{ |
|
726 |
# check for any whitespace |
|
727 |
if($sourcedir =~ m/ /) |
|
728 |
{ |
|
729 |
# if yes, then append double quotes |
|
730 |
$sisSource = "data="."\"".$sourcedir."\""; |
|
731 |
} |
|
732 |
else |
|
733 |
{ |
|
734 |
# else dont append any double quotes for destination |
|
735 |
$sisSource = "data=".$sourcedir; |
|
736 |
} |
|
737 |
# push the line on to the array. |
|
738 |
push(@$sisFileContent,$sisSource."\t".'"'.$destdir.'"'); |
|
739 |
} |
|
740 |
else |
|
741 |
{ |
|
742 |
# check for any white space |
|
743 |
if($sourcedir =~ m/ /) |
|
744 |
{ |
|
745 |
# if yes, then append double quotes |
|
746 |
$sisSource = "file="."\"".$sourcedir."\""; |
|
747 |
} |
|
748 |
else |
|
749 |
{ |
|
750 |
# else dont append any double quotes for destination |
|
751 |
$sisSource = "file=".$sourcedir; |
|
752 |
} |
|
753 |
# push the line on to the array. |
|
754 |
push(@$sisFileContent,$sisSource."\t".'"'.$destdir.'"'); |
|
755 |
} |
|
756 |
} |
|
757 |
#else it's a directory |
|
758 |
else |
|
759 |
{ |
|
760 |
&TraverseDir($entry,$folderList.$entry."\/",$sisFileContent,$rootdir); |
|
761 |
} |
|
762 |
} |
|
763 |
closedir(DIR); |
|
764 |
chdir(".."); |
|
765 |
} |
|
766 |
||
767 |
# write the data in to oby file by accessing appropriate array. |
|
768 |
sub writeDataToFile |
|
769 |
{ |
|
770 |
my ($array) = @_; |
|
771 |
#get the array size. |
|
772 |
my $arraySize = scalar(@$array); |
|
773 |
for(my $i=0; $i<$arraySize ; $i++ ) |
|
774 |
{ |
|
775 |
#pop out the element to the respective obey file. |
|
776 |
my $line=pop(@$array); |
|
777 |
if (&is_windows){ |
|
778 |
$line =~ s-\/-\\-g; |
|
779 |
}else{ |
|
780 |
$line =~ s-\\-\/-g; |
|
781 |
} |
|
782 |
print NEWDATA $line."\n"; |
|
783 |
} |
|
784 |
} |