602
|
1 |
#!\bin\perl
|
|
2 |
# Copyright (c) 2003-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 |
# CStageRunner
|
|
16 |
#
|
|
17 |
#
|
|
18 |
|
|
19 |
package CStageRunner;
|
|
20 |
|
|
21 |
use strict;
|
|
22 |
|
|
23 |
use FindBin;
|
|
24 |
use lib $FindBin::Bin."\\stages";
|
|
25 |
|
|
26 |
# CStageRunner New(listref aStageNames, CConfig aOptions) : constructor
|
|
27 |
sub New($$)
|
|
28 |
{
|
|
29 |
my $proto = shift;
|
|
30 |
my ($aStageNames, $aOptions) = @_;
|
|
31 |
|
|
32 |
my $class = ref($proto) || $proto;
|
|
33 |
|
|
34 |
my $self = {};
|
|
35 |
bless($self, $class);
|
|
36 |
|
|
37 |
if (!defined($aOptions))
|
|
38 |
{
|
|
39 |
$aOptions->Die("ERROR: CStageRunner takes an CConfig object as its second parameter.");
|
|
40 |
}
|
|
41 |
|
|
42 |
# Instantiate stages
|
|
43 |
$self->{iStages} = [];
|
|
44 |
my $stage;
|
|
45 |
my $okay = 1;
|
|
46 |
|
|
47 |
# Added scanlog compatibility
|
|
48 |
$aOptions->PhaseStart("Initialising CStageRunner");
|
|
49 |
foreach my $stageName (@$aStageNames)
|
|
50 |
{
|
|
51 |
my $found = 0;
|
|
52 |
foreach my $path (@INC)
|
|
53 |
{
|
|
54 |
if (-e $path."\\$stageName.pm")
|
|
55 |
{
|
|
56 |
$found = 1;
|
|
57 |
}
|
|
58 |
}
|
|
59 |
|
|
60 |
if (!$found)
|
|
61 |
{
|
|
62 |
$aOptions->Error("Stage $stageName does not exist.");
|
|
63 |
$okay = 0;
|
|
64 |
}
|
|
65 |
elsif (eval("require $stageName"))
|
|
66 |
{
|
|
67 |
$stage = New $stageName($aOptions);
|
|
68 |
|
|
69 |
if (!defined($stage))
|
|
70 |
{
|
|
71 |
$aOptions->Error("Stage $stageName could not be started.");
|
|
72 |
$okay = 0;
|
|
73 |
}
|
|
74 |
else
|
|
75 |
{
|
|
76 |
push @{$self->{iStages}}, $stage;
|
|
77 |
}
|
|
78 |
}
|
|
79 |
else
|
|
80 |
{
|
|
81 |
$aOptions->Error("Stage $stageName could not be loaded:\n$@");
|
|
82 |
$okay = 0;
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
if (!$okay)
|
|
87 |
{
|
|
88 |
$aOptions->Die("");
|
|
89 |
}
|
|
90 |
else
|
|
91 |
{
|
|
92 |
$aOptions->Print("All stages loaded and options checked.");
|
|
93 |
}
|
|
94 |
# This flag triggers an error message if any stage produces errors
|
|
95 |
# but does not die. The flag is used to emit a warning, once only,
|
|
96 |
# that subsequent stages may be polluted buy the errors in previous stages.
|
|
97 |
$self->{iWarnOnStageEerror} = 1;
|
|
98 |
$self->iOptions($aOptions);
|
|
99 |
|
|
100 |
# Scanlog compatibility, we ignore the return value as that is covered by $okay
|
|
101 |
$aOptions->PhaseEnd();
|
|
102 |
return $self;
|
|
103 |
}
|
|
104 |
|
|
105 |
# Getters/setters
|
|
106 |
sub iOptions()
|
|
107 |
{
|
|
108 |
my $self = shift;
|
|
109 |
if (@_) { $self->{iOPTIONS} = shift; }
|
|
110 |
return $self->{iOPTIONS};
|
|
111 |
}
|
|
112 |
|
|
113 |
# boolean Run()
|
|
114 |
sub Run()
|
|
115 |
{
|
|
116 |
my $self = shift;
|
|
117 |
|
|
118 |
my $okay = 1;
|
|
119 |
my $options;
|
|
120 |
|
|
121 |
foreach my $stage (@{$self->{iStages}})
|
|
122 |
{
|
|
123 |
$options = $self->iOptions();
|
|
124 |
$options->PhaseStart($stage->iName());
|
|
125 |
if ($stage->PreCheck())
|
|
126 |
{
|
|
127 |
$options->Status("Running ".$stage->iName());
|
|
128 |
if ($stage->Run())
|
|
129 |
{
|
|
130 |
# Passed stage i.e. no fatal errors but check for 'normal' errors
|
|
131 |
my $errors = $options->GetErrorCount();
|
|
132 |
# Check if the stage had errors and write a precautionary
|
|
133 |
# error message if this has not been done so already
|
|
134 |
if ($errors > 0 && $self->{iWarnOnStageEerror} != 0)
|
|
135 |
{
|
|
136 |
$options->Error("Stage errors mean that subsequent stages might be unreliable.");
|
|
137 |
# It is a write once error message so clear the internal flag
|
|
138 |
$self->{iWarnOnStageEerror} = 0;
|
|
139 |
}
|
|
140 |
}
|
|
141 |
else
|
|
142 |
{
|
|
143 |
# Stage signalled a fatal error by returning non-zero so bail out
|
|
144 |
$options->Error("Fatal error received from ".$stage->iName()."::Run().");
|
|
145 |
$options->PhaseEnd();
|
|
146 |
$okay = 0;
|
|
147 |
last;
|
|
148 |
}
|
|
149 |
}
|
|
150 |
else
|
|
151 |
{
|
|
152 |
$options->Error("Stage failed PreCheck()");
|
|
153 |
$okay = 0;
|
|
154 |
$options->PhaseEnd();
|
|
155 |
last;
|
|
156 |
}
|
|
157 |
$options->PhaseEnd();
|
|
158 |
}
|
|
159 |
|
|
160 |
return ($okay == 1);
|
|
161 |
}
|
|
162 |
1;
|