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 -w |
|
17 |
|
18 use strict; |
|
19 use Pod::Usage; |
|
20 use Getopt::Long; |
|
21 use FindBin; |
|
22 use FileHandle; |
|
23 use Net::SMTP; |
|
24 |
|
25 #--------------------------- GLOBAL VARIABLES ---------------------------# |
|
26 |
|
27 my $startDir = $FindBin::Bin; |
|
28 my %componentList; #This has the components from the export table. |
|
29 my @redundantComponents; #This is used by 2 methods. One populates it and |
|
30 #the other reads it to remove the redundant |
|
31 #components from the export table. |
|
32 |
|
33 # The location of the export tables |
|
34 my $srcDir = $ENV{'SourceDir'}; |
|
35 my $platform = $ENV{'Platform'}; |
|
36 my $exportTableLocation = "$srcDir\\os\\deviceplatformrelease\\symbianosbld\\productionbldcbrconfig\\"; |
|
37 |
|
38 |
|
39 my $help = 0; |
|
40 my $man = 0; |
|
41 my $autoclean = 0; |
|
42 my $autoadd = 0; |
|
43 my $email = 0; |
|
44 |
|
45 my @report; |
|
46 my ($notification_address) = 'SysBuildSupport@symbian.com'; |
|
47 my $message; |
|
48 |
|
49 # This has the components from the gt and tv components.txt |
|
50 # We need to manually put into the hash the following because these |
|
51 # are added by the release tools and are not explicitly mentioned in |
|
52 # the GTComponents.txt or TechviewComponents.txt |
|
53 my %mrpHashForProduct=( |
|
54 "gt_techview_baseline" => 1, |
|
55 "gt_only_baseline" => 1, |
|
56 "gt_overwritten"=> 1, |
|
57 "unresolved" => 1 |
|
58 ); |
|
59 |
|
60 # Just specify the export tables for each product |
|
61 my %exportTable = ( |
|
62 "8.0a" => "AutoCBR_Tornado_test_export.csv", |
|
63 "8.1a" => "AutoCBR_8.1a_test_export.csv", |
|
64 "8.0b" => "AutoCBR_Zephyr_test_export.csv", |
|
65 "8.1b" => "AutoCBR_8.1b_test_export.csv", |
|
66 "9.0" => "AutoCBR_9.0_test_export.csv", |
|
67 "9.1" => "AutoCBR_9.1_test_export.csv", |
|
68 "9.2" => "AutoCBR_9.2_test_export.csv", |
|
69 "9.3" => "AutoCBR_9.3_test_export.csv", |
|
70 "Intulo" => "AutoCBR_Intulo_test_export.csv", |
|
71 "Future" => "AutoCBR_Future_test_export.csv", |
|
72 "9.4" => "AutoCBR_9.4_test_export.csv", |
|
73 "9.5" => "AutoCBR_9.5_test_export.csv", |
|
74 "9.6" => "AutoCBR_9.6_test_export.csv", |
|
75 "tb92" => "AutoCBR_tb92_test_export.csv", |
|
76 "tb92sf" => "AutoCBR_tb92sf_test_export.csv", |
|
77 "tb101sf" => "AutoCBR_tb101sf_test_export.csv" |
|
78 ); |
|
79 |
|
80 my %componentFiles = ( |
|
81 "8.0a" => {"gtonly" => $exportTableLocation."8.0a\\gtcomponents.txt", |
|
82 "tv" => $exportTableLocation."8.0a\\techviewcomponents.txt"}, |
|
83 "8.0b" => {"gtonly" => $exportTableLocation."8.0a\\gtcomponents.txt", |
|
84 "tv" => $exportTableLocation."8.0a\\techviewcomponents.txt"}, |
|
85 "8.1a" => {"gtonly" => $exportTableLocation."8.1a\\gtcomponents.txt", |
|
86 "tv" => $exportTableLocation."8.1a\\techviewcomponents.txt"}, |
|
87 "8.1b" => {"gtonly" => $exportTableLocation."8.1b\\gtcomponents.txt", |
|
88 "tv" => $exportTableLocation."8.1b\\techviewcomponents.txt"}, |
|
89 "9.0" => {"gtonly" => $exportTableLocation."9.0\\gtcomponents.txt", |
|
90 "tv" => $exportTableLocation."9.0\\techviewcomponents.txt"}, |
|
91 "9.1" => {"gtonly" => $exportTableLocation."9.1\\gtcomponents.txt", |
|
92 "tv" => $exportTableLocation."9.1\\techviewcomponents.txt"}, |
|
93 "9.2" => {"gtonly" => $exportTableLocation."9.2\\gtcomponents.txt", |
|
94 "tv" => $exportTableLocation."9.2\\techviewcomponents.txt"}, |
|
95 "9.3" => {"gtonly" => $exportTableLocation."9.3\\gtcomponents.txt", |
|
96 "tv" => $exportTableLocation."9.3\\techviewcomponents.txt"}, |
|
97 "Intulo" => {"gtonly" => $exportTableLocation."Intulo\\gtcomponents.txt", |
|
98 "tv" => $exportTableLocation."Intulo\\techviewcomponents.txt"}, |
|
99 "Future" => {"gtonly" => $exportTableLocation."Future\\gtcomponents.txt", |
|
100 "tv" => $exportTableLocation."Future\\techviewcomponents.txt"}, |
|
101 "9.4" => {"gtonly" => $exportTableLocation."9.4\\gtcomponents.txt", |
|
102 "tv" => $exportTableLocation."9.4\\techviewcomponents.txt"}, |
|
103 "9.5" => {"gtonly" => $exportTableLocation."9.5\\gtcomponents.txt", |
|
104 "tv" => $exportTableLocation."9.5\\techviewcomponents.txt"}, |
|
105 "9.6" => {"gtonly" => $exportTableLocation."9.6\\gtcomponents.txt", |
|
106 "tv" => $exportTableLocation."9.6\\techviewcomponents.txt"}, |
|
107 "tb92" => {"gtonly" => $exportTableLocation."tb92\\gtcomponents.txt", |
|
108 "tv" => $exportTableLocation."tb92\\techviewcomponents.txt"}, |
|
109 "tb92sf" => {"gtonly" => $exportTableLocation."tb92sf\\gtcomponents.txt", |
|
110 "tv" => $exportTableLocation."tb92sf\\techviewcomponents.txt"}, |
|
111 "tb101sf" => {"gtonly" => $exportTableLocation."tb101sf\\gtcomponents.txt", |
|
112 "tv" => $exportTableLocation."tb101sf\\techviewcomponents.txt"} |
|
113 |
|
114 |
|
115 ); |
|
116 |
|
117 |
|
118 #------------------------ END OF GLOBAL VARIABLES -----------------------# |
|
119 |
|
120 |
|
121 # Utility function to print the keys of a hash ref (passed in). |
|
122 sub printHash |
|
123 { |
|
124 my $hashRef = shift; |
|
125 |
|
126 foreach my $line(sort keys %{$hashRef}) |
|
127 { |
|
128 push @report, $line."\n"; |
|
129 print $line."\n"; |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 |
|
135 # Compare the components in the export table against |
|
136 # the components in the gt and tv components.txt files. |
|
137 sub compareTables |
|
138 { |
|
139 my $product = shift; |
|
140 |
|
141 my $dirty = 0; |
|
142 foreach my $key (sort keys %componentList) |
|
143 { |
|
144 if(exists $mrpHashForProduct{$key}) |
|
145 { |
|
146 delete $mrpHashForProduct{$key}; |
|
147 } |
|
148 else |
|
149 { |
|
150 push @redundantComponents, $key; |
|
151 } |
|
152 } |
|
153 if (scalar (@redundantComponents) != 0) |
|
154 { |
|
155 $dirty =1; |
|
156 $message = "\n*** The following components can be removed from $exportTable{$product}:\n\n"; |
|
157 print $message; |
|
158 foreach my $line(@redundantComponents) |
|
159 { |
|
160 print $line."\n"; |
|
161 } |
|
162 } |
|
163 |
|
164 if (scalar keys %mrpHashForProduct != 0) |
|
165 { |
|
166 $dirty = 1; |
|
167 $message = "\n*** The following components are missing from $exportTable{$product}:\n\n"; |
|
168 push @report, $message; |
|
169 print $message; |
|
170 printHash(\%mrpHashForProduct); |
|
171 |
|
172 if ($email == 1) |
|
173 { |
|
174 &SendEmail("WARNING: For Symbian_OS_v$product: $exportTable{$product} is not up to date\n ",@report); |
|
175 } |
|
176 } |
|
177 |
|
178 if ($dirty == 0) |
|
179 { |
|
180 print "$exportTable{$product} is up to date\n"; |
|
181 } |
|
182 } |
|
183 # Get the components that are listed in the export table for the |
|
184 # product. |
|
185 |
|
186 sub getExportTableComponents |
|
187 { |
|
188 |
|
189 my $product = shift; |
|
190 my $expTable = $exportTableLocation."$product\\".$exportTable{$product}; |
|
191 |
|
192 open(EXP_TABLE,"<$expTable") or die("Cannot open export table:\n$expTable"); |
|
193 |
|
194 foreach my $line (<EXP_TABLE>) |
|
195 { |
|
196 if ($line =~ /\A([^\#,].+?),/) #Capture the component name. Ignore '#' or ',' if at beginning of line |
|
197 { |
|
198 $line = lc($1); |
|
199 $line =~ s/\s+//g; |
|
200 $line =~ s/\t+//g; |
|
201 |
|
202 if (not exists $componentList{$line}) |
|
203 { |
|
204 $componentList{$line} = 1; |
|
205 } |
|
206 else |
|
207 { |
|
208 print "Duplicate in export table: $line\n"; |
|
209 } |
|
210 } |
|
211 } |
|
212 close EXP_TABLE; |
|
213 } |
|
214 |
|
215 # Get the components from the gt and techview components.txt |
|
216 sub getComps |
|
217 { |
|
218 my $tvfile = shift; |
|
219 my $product = shift; |
|
220 my $rv = shift; |
|
221 |
|
222 my @mrpContents = split /\n/, $rv; |
|
223 |
|
224 foreach my $componentsLine (@mrpContents) |
|
225 { |
|
226 my $component = lc((split /[\s\t]/, $componentsLine)[0]); |
|
227 if (not exists $mrpHashForProduct{$component}) |
|
228 { |
|
229 $mrpHashForProduct{$component} =1; |
|
230 } |
|
231 else |
|
232 { |
|
233 print "Duplicate in gt/tv component: $component \n"; |
|
234 } |
|
235 } |
|
236 undef @mrpContents; |
|
237 |
|
238 #We make the assumption that the techviewcomponents.txt is |
|
239 #in the same location as the gtcomponents.txt for a given |
|
240 #product. |
|
241 open(TXT1, "<$tvfile") || die("Failed to find the components file for product $product"); |
|
242 undef $/; |
|
243 $rv = <TXT1>; |
|
244 close(TXT1); |
|
245 |
|
246 @mrpContents = split /\n/, $rv; |
|
247 foreach my $componentsLine (@mrpContents) |
|
248 { |
|
249 my $component = lc((split /[\s\t]/, $componentsLine)[0]); |
|
250 if (not exists $mrpHashForProduct{$component}) |
|
251 { |
|
252 $mrpHashForProduct{$component} =1; |
|
253 } |
|
254 else |
|
255 { |
|
256 print "Duplicate in gt/tv component: $component \n"; |
|
257 } |
|
258 } |
|
259 } |
|
260 |
|
261 # Get the location where the gt and techview components.txt |
|
262 # are in. Get the contents of the gtcomponents.txt. The |
|
263 # contents of the techviewcomponents.txt are gotten in getComps |
|
264 # function. |
|
265 sub getGtAndTvFiles |
|
266 { |
|
267 my $product = shift; |
|
268 |
|
269 my $rv; |
|
270 my $gtfilename = $componentFiles{$product}->{"gtonly"}; |
|
271 my $tvfilename = $componentFiles{$product}->{"tv"}; |
|
272 |
|
273 open(TXT2, "<$gtfilename") || die("Failed to find the components file for product $product"); |
|
274 undef $/; |
|
275 $rv = <TXT2>; |
|
276 close(TXT2); |
|
277 |
|
278 getComps($tvfilename, $product, $rv); |
|
279 |
|
280 # if ($rv !~ /no such file/) |
|
281 # { |
|
282 # my $tvfilename = "//EPOC/master/beech/product/tools/makecbr/files/$product/techviewcomponents.txt"; |
|
283 # getComps($tvfilename, $product, $rv); |
|
284 # return; |
|
285 # } |
|
286 # |
|
287 # $gtfilename = "//EPOC/master/os/deviceplatformrelease/symbianosbld/productionbldcbrconfig/$product/gtcomponents.txt"; |
|
288 # $rv = `p4 print -q $gtfilename 2>&1`; |
|
289 # |
|
290 # if ($rv !~ /no such file/) |
|
291 # { |
|
292 # my $tvfilename = "//EPOC/master/os/deviceplatformrelease/symbianosbld/productionbldcbrconfig/$product/techviewcomponents.txt"; |
|
293 # getComps($tvfilename, $product, $rv); |
|
294 # return; |
|
295 # } |
|
296 # die("Failed to find the Components file for product $product"); |
|
297 } |
|
298 |
|
299 sub autoclean ($) |
|
300 { |
|
301 my $product = shift; |
|
302 my $expTable = $exportTableLocation."$product\\".$exportTable{$product}; |
|
303 my %redundantComponentsHash; |
|
304 |
|
305 my $cleanexpTable = $exportTable{$product}; |
|
306 $cleanexpTable =~ s/\.csv//; |
|
307 $cleanexpTable = $startDir."\\"."${cleanexpTable}.csv"; |
|
308 |
|
309 if ($autoclean == 1) |
|
310 { |
|
311 print "********** Removing redundant components **********\n"; |
|
312 } |
|
313 #open the export table |
|
314 open(INPUT, "<$expTable") or die ("Could not open $expTable for read\n"); |
|
315 |
|
316 #create the clean table |
|
317 open(OUTPUT, ">$cleanexpTable") or die ("Could not create $cleanexpTable\n"); |
|
318 |
|
319 foreach my $key (@redundantComponents) |
|
320 { |
|
321 #print $key."\n"; |
|
322 if (not exists $redundantComponentsHash{$key}) |
|
323 { |
|
324 $redundantComponentsHash{$key} = 1; |
|
325 } |
|
326 } |
|
327 foreach my $line (<INPUT>) |
|
328 { |
|
329 if ($line =~ /\A([^\#,].+?),/) |
|
330 { |
|
331 my $component = lc($1); |
|
332 $component =~ s/\s+//g; |
|
333 $component =~ s/\t+//g; |
|
334 |
|
335 if ((not exists $redundantComponentsHash{$component}) || |
|
336 ($autoclean == 0)) |
|
337 { |
|
338 #print "Adding $line in $cleanexpTable\n"; |
|
339 print OUTPUT $line; |
|
340 } |
|
341 } |
|
342 else |
|
343 { |
|
344 print OUTPUT $line; |
|
345 } |
|
346 } |
|
347 |
|
348 #Warning: This sets the position in INPUT to the beginning of the file! |
|
349 my $curPos = tell(INPUT); |
|
350 seek(INPUT, 0,0); |
|
351 my $firstLine = <INPUT>; |
|
352 my @cells = split /,/, $firstLine; |
|
353 my $numOfKeys = scalar(@cells) -1; |
|
354 #restore the position in INPUT |
|
355 seek (INPUT, $curPos,0); |
|
356 |
|
357 #Now add the missing components |
|
358 if (((keys %mrpHashForProduct)> 0) && ($autoadd == 1)) |
|
359 { |
|
360 print OUTPUT "\n\n\#Automatically added componments - NEED CHECKING!\n"; |
|
361 print "********** Adding missing components **********\n"; |
|
362 |
|
363 foreach my $missingComponent (sort keys %mrpHashForProduct) |
|
364 { |
|
365 my $categoriesString; |
|
366 my $counter = 0; |
|
367 for ($counter = 0; $counter < $numOfKeys; $counter++) |
|
368 { |
|
369 $categoriesString = $categoriesString."D E F G,"; |
|
370 } |
|
371 my $string = $missingComponent.",".$categoriesString; |
|
372 |
|
373 #remove the extra ',' from the string |
|
374 chop($string); |
|
375 print OUTPUT $string."\n"; |
|
376 } |
|
377 } |
|
378 print "Closing files\n"; |
|
379 close(INPUT); |
|
380 close (OUTPUT); |
|
381 } |
|
382 |
|
383 # Send Email |
|
384 sub SendEmail |
|
385 { |
|
386 my ($subject, @body) = @_; |
|
387 my (@message); |
|
388 |
|
389 #return 1; # Debug to stop email sending |
|
390 |
|
391 push @message,"From: $ENV{COMPUTERNAME}\n"; |
|
392 push @message,"To: $notification_address\n"; |
|
393 push @message,"Subject: $subject\n"; |
|
394 push @message,"\n"; |
|
395 push @message,@body; |
|
396 |
|
397 my $smtp = Net::SMTP->new('lonsmtp.intra', Hello => $ENV{COMPUTERNAME}, Debug => 0); |
|
398 $smtp->mail(); |
|
399 $smtp->to($notification_address); |
|
400 |
|
401 $smtp->data(@message) or die "ERROR: Sending message because $!"; |
|
402 $smtp->quit; |
|
403 |
|
404 } |
|
405 |
|
406 sub main |
|
407 { |
|
408 |
|
409 GetOptions('help|?' => \$help, 'man' =>\$man, 'remove' =>\$autoclean, |
|
410 'add' => \$autoadd, 'e' => \$email) or pod2usage(-verbose => 2); |
|
411 pod2usage(-verbose => 1) if $help == 1; |
|
412 pod2usage(-verbose => 2) if $man == 1; |
|
413 |
|
414 if ($#ARGV < 0) |
|
415 { |
|
416 pod2usage(-verbose => 0); |
|
417 } |
|
418 |
|
419 print "******** $ARGV[0] ********\n"; |
|
420 my $prod = shift @ARGV; |
|
421 |
|
422 my $isTestBuild = $ENV{'PublishLocation'}; |
|
423 |
|
424 if ($isTestBuild =~ m/Test/i) |
|
425 |
|
426 { |
|
427 |
|
428 $email = 0 ; |
|
429 |
|
430 print "\nThis is a test build, no need to export\n"; |
|
431 |
|
432 exit 1; |
|
433 |
|
434 } |
|
435 |
|
436 |
|
437 if (not exists $exportTable{$prod}) |
|
438 { |
|
439 print "ERROR: Product is invalid\n"; |
|
440 print "Aborting...\n"; |
|
441 exit; |
|
442 |
|
443 } |
|
444 |
|
445 |
|
446 getExportTableComponents($prod); |
|
447 getGtAndTvFiles($prod); |
|
448 compareTables($prod); |
|
449 if (($autoclean == 1) || ($autoadd == 1) ) |
|
450 { |
|
451 autoclean($prod); |
|
452 } |
|
453 } |
|
454 |
|
455 main(); |
|
456 |
|
457 =pod |
|
458 |
|
459 =head1 NAME |
|
460 |
|
461 check_tables.pl - Check the export tables for a product against the components that are in the product. |
|
462 |
|
463 =head1 SYNOPSIS |
|
464 |
|
465 check_tables.pl [options] <product> |
|
466 |
|
467 Options: |
|
468 -help brief help message |
|
469 -man full documentation |
|
470 -remove Automatically remove redundant components. See below for details. |
|
471 -add Automatically add missing components. See below for details. |
|
472 -e Sends a notification email if a component is missing from export table. |
|
473 |
|
474 =head1 OPTIONS |
|
475 |
|
476 =over 8 |
|
477 |
|
478 =item B<-help> |
|
479 |
|
480 Prints a brief help message and exits |
|
481 |
|
482 =item B<-man> |
|
483 |
|
484 Prints the manual page and exists |
|
485 |
|
486 =item B<-remove> |
|
487 |
|
488 Create a clean version of the export table by removing the redundant entries. |
|
489 The clean table will be placed in the directory where the tool was run from |
|
490 and will have the same name as the export table in perforce. You will need to |
|
491 copy it to where you have your Perforce changes mapped in your client. |
|
492 |
|
493 =item B<-add> |
|
494 |
|
495 The same as -remove but will automatically add the missing components. The |
|
496 componenets are added with categories D E F and G. |
|
497 |
|
498 =item B<-e> |
|
499 |
|
500 Sends a notification email to SysBuildSupport@Symbian.com if any components |
|
501 are missing from the export table. |
|
502 |
|
503 =back |
|
504 |
|
505 =head1 DESCRIPTION |
|
506 |
|
507 B<This program> will take a product as an argument and will check the |
|
508 export table for that product for consistency. It will report any |
|
509 redundant entries in the export table and also any components that are |
|
510 missing. It will also report any duplicate entries in the export table |
|
511 itself. If no problems are found it will report that the tables are |
|
512 up to date. |
|
513 |
|
514 =head1 VERSION |
|
515 |
|
516 $Id: //SSS/master/sf/os/buildtools/bldsystemtools/commonbldutils/check_tables.pl#2 $ |
|
517 $Change: 1761879 $ $DateTime: 2010/02/11 15:53:10 $ |
|
518 |
|
519 =cut |
|