|
1 # |
|
2 # Copyright (c) 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 "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 # |
|
16 #! perl |
|
17 |
|
18 # This script builds ROMs which are specified in a supplied XML file |
|
19 # To use this script \epoc32\tools\buildrom must be installed on the drive |
|
20 # with \epoc32\tools in the path |
|
21 |
|
22 # Note: The TargetBoard attribute is no longer used but is still needed because of the structure of this script! |
|
23 |
|
24 use strict; |
|
25 use XML::Simple; |
|
26 use Getopt::Long; |
|
27 use Cwd; |
|
28 use Cwd 'abs_path'; |
|
29 use File::Copy; |
|
30 use File::Path; |
|
31 |
|
32 # Get command line arguments |
|
33 my ($romspec, $boards, $roms, $logdir, $buildnum, $publish, $help, $version) = ProcessCommandLine(); |
|
34 |
|
35 Usage() if ($help); |
|
36 Version() if ($version); |
|
37 |
|
38 die "Romspec xml file must be specified using the -romspec option\n" if (!$romspec); |
|
39 |
|
40 # Construct arrays of boards and roms if they were specified |
|
41 my @boards = split /,/, $boards if ($boards); |
|
42 my @roms = split /,/, $roms if ($roms); |
|
43 |
|
44 # Use the XML::Simple module to parse the romspec and pass the result |
|
45 # into the $Roms hash reference |
|
46 my $xml = new XML::Simple; |
|
47 my $Roms = $xml->XMLin($romspec); |
|
48 |
|
49 my $RomList = %$Roms->{'Rom'}; |
|
50 |
|
51 my $RomBuildStage = 1; |
|
52 |
|
53 foreach my $rom (sort keys %$RomList) |
|
54 { |
|
55 my $board = $RomList->{$rom}->{'TargetBoard'}; |
|
56 if( (@boards == 0 and @roms == 0) or grep $rom, @roms or grep $board, @boards) |
|
57 { |
|
58 BuildRom($RomBuildStage, $RomList, $rom, $logdir, $buildnum ,$publish); |
|
59 $RomBuildStage++; |
|
60 } |
|
61 } |
|
62 |
|
63 ##################################################### |
|
64 #### Run buildrom on the specified ROM using ######## |
|
65 #### info from the romspec.xml ######## |
|
66 ##################################################### |
|
67 sub BuildRom |
|
68 { |
|
69 my $Stage = shift; # BuildRom stage |
|
70 my $RomList = shift; # Hash of the romspec.xml |
|
71 my $rom = shift; # Rom to be built |
|
72 my $logdir = shift; # logs directory |
|
73 my $buildnum = shift; # build number |
|
74 my $publish = shift; # Publish Location |
|
75 my $type = $ENV{Type}; # type of Build Master or Release |
|
76 my $builddir = $ENV{BuildDir}; # Build Directory |
|
77 my $Epocroot = $ENV{EPOCROOT}; # EpocRoot; |
|
78 my $InFileList=""; # i.e. Platsec, Techview, obyfiles |
|
79 my $XmlFileList=""; |
|
80 my $MacroList=""; # for the buildrom -D option |
|
81 my $TargetBoard = $RomList->{$rom}->{'TargetBoard'}; |
|
82 my $ImageFile = " -o".$RomList->{$rom}->{'ImageFile'}->{'name'}; # for the buildrom -o option |
|
83 |
|
84 # Construct the list of InFiles to pass to buildrom |
|
85 my $InFiles = %$RomList->{$rom}->{'InFile'}; |
|
86 foreach my $infile (sort keys %$InFiles) |
|
87 { |
|
88 if ($infile eq "name") |
|
89 { |
|
90 $InFileList = " ".$InFiles->{'name'} unless (lc($InFiles->{'name'}) eq lc($TargetBoard)); |
|
91 } |
|
92 else |
|
93 { |
|
94 $InFileList .= " ".$infile unless(lc($infile) eq lc($TargetBoard)); |
|
95 } |
|
96 } |
|
97 my $RomXmlFlag='-f'; |
|
98 my $XmlFiles = %$RomList->{$rom}->{'XMLFile'}; |
|
99 foreach my $XmlFlags (keys %$XmlFiles) |
|
100 { |
|
101 if ($XmlFlags eq "flag") |
|
102 { |
|
103 $RomXmlFlag= $XmlFiles->{'flag'}; |
|
104 } |
|
105 } |
|
106 foreach my $XmlFile (keys %$XmlFiles) |
|
107 { |
|
108 if ($XmlFile eq "name") |
|
109 { |
|
110 $XmlFileList = "$RomXmlFlag"."$Epocroot"."epoc32\\rom\\include\\".$XmlFiles->{'name'}; |
|
111 } |
|
112 else |
|
113 { |
|
114 $XmlFileList .= "$RomXmlFlag"."$Epocroot"."epoc32\\rom\\include\\".$XmlFile unless(lc($XmlFile) eq lc($TargetBoard)); |
|
115 } |
|
116 } |
|
117 |
|
118 # Get the ROM macro if one is defined |
|
119 if ( defined $RomList->{$rom}->{'Macro'} ) |
|
120 { |
|
121 if (defined $RomList->{$rom}->{'Macro'}->{'name'} ) |
|
122 { |
|
123 if ( $RomList->{$rom}->{'Macro'}->{'value'} ne "" ) |
|
124 { |
|
125 $MacroList = " -D".$RomList->{$rom}->{'Macro'}->{'name'}."=".$RomList->{$rom}->{'Macro'}->{'value'}; |
|
126 } |
|
127 else |
|
128 { |
|
129 $MacroList = " -D".$RomList->{$rom}->{'Macro'}->{'name'}; |
|
130 } |
|
131 } |
|
132 else |
|
133 { |
|
134 my $Macros = %$RomList->{$rom}->{'Macro'}; |
|
135 foreach my $macro (keys %$Macros) |
|
136 { |
|
137 if ( $Macros->{$macro}->{'value'} ne "" ) |
|
138 { |
|
139 $MacroList .= " -D".$macro."=".$Macros->{$macro}->{'value'}; |
|
140 } |
|
141 else |
|
142 { |
|
143 $MacroList .= " -D".$macro; |
|
144 } |
|
145 } |
|
146 } |
|
147 } |
|
148 |
|
149 # Call buildrom |
|
150 my $buildrom_command = "buildrom $InFileList $MacroList $XmlFileList $ImageFile 2>&1"; |
|
151 my $gHiResTimer = 0; |
|
152 if (eval "require Time::HiRes;") |
|
153 { |
|
154 $gHiResTimer = 1; |
|
155 } |
|
156 else |
|
157 { |
|
158 print "Cannot load HiResTimer Module\n"; |
|
159 } |
|
160 open TVROMLOG, ">> $logdir\\techviewroms$buildnum.log"; |
|
161 print TVROMLOG "===------------------------------------------------\n"; |
|
162 print TVROMLOG "-- Stage=$Stage\n"; |
|
163 print TVROMLOG "===----------------------------------------------\n"; |
|
164 print TVROMLOG "-- Stage=$Stage started ".localtime()."\n"; |
|
165 print TVROMLOG "=== Stage=$Stage == Build $rom\n"; |
|
166 print TVROMLOG "-- Stage=$Stage == $TargetBoard $InFileList\n"; |
|
167 print TVROMLOG "-- $buildrom_command\n"; |
|
168 print TVROMLOG "-- MetaromBuild Executed ID $Stage $buildrom_command \n"; |
|
169 print TVROMLOG "++ Started at ".localtime()."\n"; |
|
170 if ($gHiResTimer == 1) |
|
171 { |
|
172 print TVROMLOG "+++ HiRes Start ".Time::HiRes::time()."\n"; |
|
173 } |
|
174 else |
|
175 { |
|
176 # Add the HiRes timer unavailable statement |
|
177 print TVROMLOG "+++ HiRes Time Unavailable\n"; |
|
178 } |
|
179 my $command_output = `$buildrom_command`; |
|
180 print TVROMLOG $command_output; |
|
181 if ($?) |
|
182 { |
|
183 print TVROMLOG "ERROR: $buildrom_command returned an error code $?\n"; |
|
184 } |
|
185 if (($command_output =~m/\d\sFile/g) and ($command_output!~/Failed/ig) and ($command_output!~/Unsucessful/ig)) |
|
186 { |
|
187 print TVROMLOG "Rom Built Sucessfully\n"; |
|
188 } |
|
189 else |
|
190 { |
|
191 print TVROMLOG "ERROR: $buildrom_command failed .Please check log techviewroms$buildnum.log for details\n"; |
|
192 } |
|
193 if ($gHiResTimer == 1) |
|
194 { |
|
195 print TVROMLOG "+++ HiRes End ".Time::HiRes::time()."\n"; |
|
196 } |
|
197 else |
|
198 { |
|
199 # Add the HiRes timer unavailable statement |
|
200 print TVROMLOG "+++ HiRes Time Unavailable\n"; |
|
201 } |
|
202 print TVROMLOG "++ Finished at ".localtime()."\n"; |
|
203 print TVROMLOG "=== Stage=$Stage finished ".localtime()."\n"; |
|
204 close TVROMLOG; |
|
205 |
|
206 # Publishing of Logs and Roms##################### |
|
207 my $ImageFileXML = $ImageFile ; |
|
208 $ImageFileXML =~s/^\s-o//i; |
|
209 $ImageFileXML =~/(.*\d.techview)/; |
|
210 my $ImageFileXMLresult = $1; |
|
211 my $cwdir = abs_path ( $ENV { 'PWD' } ); |
|
212 $cwdir =~s/\//\\/g; |
|
213 $rom =~ /(\w+).*/; |
|
214 my $data = $1; |
|
215 if(($publish ne "")) |
|
216 { |
|
217 if($rom =~ /(\w+).*/) |
|
218 { |
|
219 my $data = $1; |
|
220 if(not -d "$publish\\$1") |
|
221 { |
|
222 mkpath "$publish\\$1" || die "ERROR: Cannot create $publish\\$1"; # If folder doesnt exist create it |
|
223 } |
|
224 opendir(DIR, $cwdir) || die "can't opendir $cwdir: $!"; |
|
225 my @file_array =readdir(DIR); |
|
226 foreach ($ImageFileXMLresult) |
|
227 { |
|
228 foreach my $ImageFileConcat (@file_array) |
|
229 { |
|
230 $ImageFileConcat =~/(.*\d.techview)/; |
|
231 my $Image = $1; |
|
232 |
|
233 if ($ImageFileXMLresult eq $Image) |
|
234 { |
|
235 copy ("$cwdir\\$ImageFileConcat" , "$publish\\$data\\");# or die "Cannot copy file:$!"; |
|
236 } |
|
237 } |
|
238 closedir DIR; |
|
239 } |
|
240 } |
|
241 } |
|
242 else |
|
243 { |
|
244 print"Publish Option not used \n"; |
|
245 } |
|
246 } |
|
247 |
|
248 ######################################## |
|
249 ##### Process the command line ######### |
|
250 ######################################## |
|
251 sub ProcessCommandLine |
|
252 { |
|
253 my ($romspec, $boards, $roms, $publish, $help, $version); |
|
254 |
|
255 GetOptions('romspec=s' => \$romspec, |
|
256 'roms=s' => \$roms, |
|
257 'boards=s' => \$boards, |
|
258 'logdir=s' => \$logdir, |
|
259 'buildnum=s' => \$buildnum, |
|
260 'publish=s' => \$publish, |
|
261 'help' => \$help, |
|
262 'version' => \$version)|| die Usage(); |
|
263 |
|
264 return ($romspec, $boards, $roms, $logdir, $buildnum, $publish, $help, $version); |
|
265 } |
|
266 |
|
267 |
|
268 sub Usage |
|
269 { |
|
270 print <<USAGE_EOF; |
|
271 |
|
272 Usage |
|
273 ----- |
|
274 perl metarombuild.pl -romspec <romspec xml file> [options] |
|
275 |
|
276 When no options are specified, all ROMs specified in the romspec wil be built. |
|
277 |
|
278 Options: |
|
279 -logdir <path to logs directory> |
|
280 -buildnum <build number> |
|
281 -publish <location of path where rom logs will be published > |
|
282 -help |
|
283 -version |
|
284 |
|
285 USAGE_EOF |
|
286 exit 0; |
|
287 } |
|
288 |
|
289 sub Version |
|
290 { |
|
291 print <<VERSION_EOF; |
|
292 |
|
293 metarombuild.pl v1.0 |
|
294 Copyright (c) 2005-2009 Nokia Corporation. All rights reserved. |
|
295 |
|
296 VERSION_EOF |
|
297 exit 0; |
|
298 } |