|
1 # Copyright (c) 2006-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 # Script to check for Missing Stages in MainBuild/PostBuild Logs |
|
15 # Purpose: This script checks dropped stages in PostBuild/MainBuild Logs |
|
16 # by reading the stages in Log file and comparing each of the stage against the stages in the corresponding XML file, |
|
17 # if the stages are missing sends out an e-mail to the system build support team. |
|
18 # |
|
19 # |
|
20 |
|
21 use strict; |
|
22 use Net::SMTP; |
|
23 use File::Basename; |
|
24 |
|
25 my %hashlist = ("$ENV{LogsDir}\\"."$ENV{BuildNumber}.xml" => "$ENV{LogsDir}\\"."$ENV{BuildBaseName}.log", "$ENV{SourceDir}\\os\\buildtools\\bldsystemtools\\commonbldutils\\".'postbuild.xml' => "$ENV{LogsDir}\\".'postbuild.log'); |
|
26 |
|
27 foreach my $xmlFile (keys %hashlist) |
|
28 { |
|
29 ReportMissingStages ($xmlFile, $hashlist{$xmlFile}); |
|
30 } |
|
31 |
|
32 sub ReportMissingStages |
|
33 { |
|
34 my ($XML, $log) = @_; |
|
35 my $logFile = basename $log; |
|
36 my $XMLFile = basename $XML; |
|
37 if ( ! -e $XML) |
|
38 { |
|
39 &SendEmail("ERROR: $XML File not found"); |
|
40 } |
|
41 elsif ( ! -e $log) |
|
42 { |
|
43 &SendEmail("ERROR: $log File not found"); |
|
44 } |
|
45 else |
|
46 { |
|
47 my %hashXML; |
|
48 my %hashLOG; |
|
49 open(FH, "<$XML") or die "ERROR: Cannot open $XMLFile: $!\n"; |
|
50 my @iXML = <FH>; |
|
51 close(FH); |
|
52 foreach (@iXML) |
|
53 { |
|
54 next if(/^\<\!\-\-/); |
|
55 while(/(%(\w+)%)|(%%(\w+)%%)/g) |
|
56 { |
|
57 my $iVarName = $4?$4:$2; |
|
58 if (defined $ENV{$iVarName}) |
|
59 { |
|
60 s/(%\w+%)|(%%\w+%%)/$ENV{$iVarName}/; |
|
61 } |
|
62 else |
|
63 { |
|
64 s/(%\w+%)|(%%\w+%%)//; #undefined variables become 'nothing' |
|
65 } |
|
66 } |
|
67 s/2>&1/2>&1/g; |
|
68 s/"/"/g; |
|
69 s/>/>/g; |
|
70 s/</</g; |
|
71 |
|
72 if(my $line = m/CommandLine="(.*)"/i) |
|
73 { |
|
74 if(! exists $hashXML{$1}) |
|
75 { |
|
76 my $XMLEntry = $1; |
|
77 $XMLEntry =~ s/\s+/ /g; |
|
78 $hashXML{$XMLEntry} =1; |
|
79 } |
|
80 else |
|
81 { |
|
82 $hashXML{$1}+= 1; |
|
83 } |
|
84 } |
|
85 } |
|
86 |
|
87 open(IN, "<$log") or die "error: cant open $logFile: $!\n"; |
|
88 my @iLog = <IN>; |
|
89 close IN; |
|
90 foreach(@iLog) |
|
91 { |
|
92 if(m/^--\s(.*)/) |
|
93 { |
|
94 if(! exists $hashLOG{$1}) |
|
95 { |
|
96 my $logEntry = $1; |
|
97 $logEntry =~ s/\s+/ /g; |
|
98 $hashLOG{$logEntry} =1; |
|
99 } |
|
100 else |
|
101 { |
|
102 $hashLOG{$1}+= 1; |
|
103 } |
|
104 } |
|
105 } |
|
106 my @missing = grep ! exists $hashLOG{$_}, keys %hashXML; |
|
107 #To remove missingstages.pl stage being reported itself as missing in log file |
|
108 @missing = grep !/missingstages.pl/, @missing; |
|
109 if(@missing) |
|
110 { |
|
111 #To Print each MissingStage in a seperate line |
|
112 my @MissingStages; |
|
113 foreach my $Stage(@missing) |
|
114 { |
|
115 push @MissingStages, "$Stage\n\n"; |
|
116 } |
|
117 &SendEmail("Missing Stages found in $logFile: \n\n@MissingStages"); |
|
118 } |
|
119 |
|
120 } |
|
121 } |
|
122 |
|
123 sub SendEmail |
|
124 { |
|
125 my (@body, @message, $sender_address, $notification_address); |
|
126 @body = @_; |
|
127 $sender_address = 'I_EXT_sysbuildsupport@nokia.com'; |
|
128 $notification_address = 'I_EXT_sysbuildsupport@nokia.com'; |
|
129 |
|
130 push @message,"From: $sender_address\n"; |
|
131 push @message,"To: $notification_address\n"; |
|
132 push @message,"Subject: MissingStages found in build $ENV{BuildNumber}\n"; |
|
133 push @message,"\n"; |
|
134 push @message,@body; |
|
135 |
|
136 my $smtp = Net::SMTP->new('smtp.nokia.com', Hello => $ENV{COMPUTERNAME}, Debug => 0); |
|
137 $smtp->mail(); |
|
138 $smtp->to($notification_address); |
|
139 |
|
140 $smtp->data(@message) or die "ERROR: Sending message"; |
|
141 $smtp->quit; |
|
142 } |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |