releasing/makecbr/CConfig.pm
author y4jin
Tue, 23 Nov 2010 14:07:04 +0800
changeset 705 67449e76cb84
parent 602 3145852acc89
permissions -rw-r--r--
Fix the illegal word scanned by sfchecksource tools
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
#!\bin\perl -w
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
# CConfig
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
package CConfig;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
use IO::File;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
use COutputHandler;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
# Added for scanlog compatibility
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
use Time::localtime;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
# CConfig New(scalar aFilename) : constructor
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
sub New($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
	my $proto = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
	my ($aFilename) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
	my $class = ref($proto) || $proto;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
	my $self = { RELTOOLS_REQUIRED => "",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
                     outputHandler => COutputHandler->new()};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
	bless($self, $class);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
  # undef the logfile here so that the folowing warning goes to stdout
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
  $self->{iLOGFILE} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
	# Load in options
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
	if (defined($aFilename))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
		if (!$self->Reload($aFilename))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
			$self->Warning("Option file could not be loaded.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
  # Added support for scanlog and Die() control.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
  $self->{iPhaseErrorCount} = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
	$self->{iPhase} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
        
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
	return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
# boolean Set(scalar aOptionName, scalar aValue)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
sub Set($$)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
	my ($aOptionName, $aValue) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
	if (!defined($aOptionName))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
		$self->Warning("Cannot set undefined option");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
		return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
	if (!defined($aValue))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
		$self->Warning("Cannot set option '$aOptionName' to undefined value.");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
		return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
	if ((ref($aValue) ne "") && (ref($aValue) ne "ARRAY"))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
		$self->Warning("Value of '$aOptionName' must be either a string or list.");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
		return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
	$self->{iOptions}->{lc($aOptionName)} = [$aOptionName, $aValue];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
	return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
# scalar Get(scalar aOptionName)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
sub Get($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
	my ($aOptionName) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
	if (defined($self->{iOptions}->{lc($aOptionName)}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
		return ($self->{iOptions}->{lc($aOptionName)})->[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
		return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
# boolean Reload(scalar aFilename)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
sub Reload($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
	my ($aFilename) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
	my $okay = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
	$self->{iOptions}={}; # Blank existing options
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
	if (!open(FILE, $aFilename))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
		$self->Warning("Option file '$aFilename' could not be opened.");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
		$okay = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
		foreach my $line (<FILE>)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
			chomp ($line);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
			# Split on colon
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
			my $parms = $line;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
			$parms =~ s/([^\\]):/$1\x08/g; # Turn unescaped colons into 0x08 chars
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
			$parms =~ s/\\:/:/g; # Unescape escaped colons
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
			my @parms = split(/\x08/,$parms); # Split on 0x08
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
			if (scalar(@parms) != 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
				if (scalar(@parms) == 2)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
					my $key = $parms[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
					$key =~ s/^\s+//; # Remove preceding spaces
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
					$key =~ s/([^\\])\s$/$1/g; # Remove unescaped trailing spaces
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
					$key =~ s/\\(\s)/$1/g; # Unescape space characters
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
					my $value = $parms[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
					if ($value =~ /\s*\[.*\]\s*$/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
						# Value is a [list]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
						# Remove square brackets
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
						$value =~ s/^\s*\[//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
						$value =~ s/\]\s*$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
						# Split on comma
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
						$value =~ s/([^\\]),/$1\x08/g; # Turn unescaped commas into 0x08 chars
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
						$value =~ s/\\,/,/g; # Unescape escaped commas
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
						my @values = split(/\x08/,$value); # Split on 0x08
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
						map(s/^\s+//, @values); # Remove preceding spaces
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
						map(s/([^\\])\s$/$1/g, @values); # Remove unescaped trailing spaces
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
						map(s/\\(\s)/$1/g, @values); # Unescape space characters
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
						$value = [@values];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
					else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
						# Value is a scalar
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
						$value =~ s/^\s+//; # Remove preceding spaces
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
						$value =~ s/([^\\])\s$/$1/g; # Remove unescaped trailing spaces
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
						$value =~ s/\\(\s)/$1/g; # Unescape space characters
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
					if (!($self->Set($key, $value)))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
						$okay = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
				else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
					$self->Warning("In file '$aFilename', ".scalar(@parms)." parameters found on a line.\nOnly two parameters, colon separated, are supported.\nLine: '$line'");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
					$okay = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
		close(FILE);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
	return ($okay);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
# boolean Save(scalar aFilename)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
sub Save($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
	my ($aFilename) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
	my $okay = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
	if (!open(FILE, ">$aFilename"))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
		$self->Warning("Could not open option file '$aFilename' to save to.");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
		$okay = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
		foreach my $pair (values(%{$self->{iOptions}}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
			my $key = $pair->[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
			my $value = $pair->[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
			
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
			if (!defined($value))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
				$self->Error("Cannot write undefined value for key '$key' when saving options.");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
				$okay = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
			else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
				if (ref($value))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
					if (ref($value) ne "ARRAY")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
						$self->Error("Cannot write ".ref($value)." for key '$key' when saving options.");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
						$okay = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
					else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
						{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
						# It's a list: [value,value,value] and escape any commas or opening spaces
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
						my @values = @{$value};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
						map(s/^(\s)/\\$1/,@values);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
						map(s/,/\\,/g,@values);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
						$value = "[".join(",",@values)."]";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
						}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
				else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
					{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
					# It's a scalar string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
					# Escape opening space
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
					$key =~ s/^(\s)/\\$1/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
					# Escape square brackets;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
					}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
					
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
				# Escape colons
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
				$key =~ s/:/\\:/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
				$value =~ s/:/\\:/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
				
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
				print FILE $key.":".$value."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
		close (FILE)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
	return $okay;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
# boolean SetLog(scalar aFilename)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
sub SetLog($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
	my ($aLogFile) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
	if (defined($self->{iLOGFILE}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
		$self->{iLOGFILE}->close();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
    # This forces any subsequent error message to go to stdout
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
    $self->{iLOGFILE} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
	if (-e $aLogFile)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
		if (-e $aLogFile."~")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
			if (!unlink $aLogFile."~")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
				$self->Error("Couldn't delete backup log file\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
				return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
		if (system("copy $aLogFile $aLogFile~ > nul 2>&1"))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
			$self->Error("Couldn't back-up existing log file\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
			return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
		
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
	$self->{iLOGFILE}=new IO::File("> $aLogFile");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
	if (defined($self->{iLOGFILE}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
		return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
		$self->Error("Couldn't open logfile $aLogFile\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
		return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
# void Print(scalar aLogLine)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
sub Print($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
	my ($aLogLine) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
	my $logfile = $self->{iLOGFILE};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
	if ($aLogLine !~ /\n$/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
		$aLogLine = $aLogLine."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
                
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
        $aLogLine = $self->{outputHandler}->CheckOutput($aLogLine);      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
	if (!defined($logfile))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
		print $aLogLine;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
		print $logfile $aLogLine;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
# void Die(scalar aError)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
sub Die($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
	my ($aError) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
	my $logfile = $self->{iLOGFILE};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
	if ($aError !~ /\n$/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
		$aError = $aError."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
	if (!defined($logfile))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
		die $aError;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
	else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
		print $logfile $aError;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
		die "ERROR: System experienced a fatal error; check the log file.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
# void Status(scalar aMessage)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
sub Status($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
	my ($aMessage) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
	if (defined($self->{iLOGFILE}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
		print STDOUT $aMessage."\n"; # Only display status (to STDOUT) if everything else is going to the logfile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
# Returns the number of errors encountered in a phase
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
sub GetErrorCount()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
  return $self->{iPhaseErrorCount};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
###########################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
# Utility functions
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
###########################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
# boolean CheckRelTools()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
sub CheckRelTools()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
	# Search for reldata API
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
	my $found = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
	foreach my $path (split(/;/,$ENV{PATH}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
		if (-e $path."\\reldata\.pm")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
			$found = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
			last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
	return $found
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
# void RequireRelTools() - Requires RelData and IniData. Dies if tools can't be located, or die when being required.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
sub RequireRelTools()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
	if ($self->{RELTOOLS_REQUIRED} ne "required")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
		# Locate reldata API
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
		my $found = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
		foreach my $path (split(/;/,$ENV{PATH}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
			if (-e $path."\\reldata\.pm")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
				{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
				push @INC, $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
				$found = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
				last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
				}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
		if (!$found)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
			{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
			$self->Error("Couldn't find release tools in path");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
			}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
		# Require core modules
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
		require RelData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
		require IniData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
		$self->{RELTOOLS_REQUIRED}="required";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
###########################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
# Handling Commands, Phases and components.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
###########################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
# void Command(scalar aMessage)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
# Prints out a command in scanlog format to the log file or stdout
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
sub Command($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
	my ($aCommand) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
  my $message = "===-------------------------------------------------\n=== Stage=$self->{stageNumber}.$aCommand\n===-------------------------------------------------\n";	my $logfile = $self->{iLOGFILE};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
  $self->Print($message);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
# void PhaseStart(scalar aPhaseName)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
# If a current phase is active then this is closed, if when doing so a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
# non-zero error count is returned by PhaseEnd() then Die is called. This
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
# is regarded as a logic error as the stage runner should normally call PhaseEnd()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
# itself and decide what to do about any errors that occured in that phase.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
sub PhaseStart($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
  my $phase = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
  if (defined $self->{iPhase})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
    my $numErrs = $self->PhaseEnd();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
    # If there are errors returned by PhaseEnd then Die()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
    if ($numErrs != 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   441
        $self->Die("Fatal logic error detected, CConfig::PhaseStart() called without PhaseEnd() when phase has $numErrs errors.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   442
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   443
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   444
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   445
    $self->{stageNumber}++; # For scanlog compatibility
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
    $self->Command($phase);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
    $self->{iPhase} = $phase;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
    my $localTime = ctime(); 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
    my $message = "=== Stage=$self->{stageNumber}.$self->{iPhase} started $localTime\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
    $message .= "=== Stage=$self->{stageNumber}.$self->{iPhase} == $self->{iPhase}\n"; # For Scanlog compatibility
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
    $message .= "+++ HiRes Start " . time() . "\n"; # For Scanlog compatibility
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
    $message .= "--  $self->{iPhase}: Miscellaneous\n"; # For Scanlog compatibility
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
    $self->Print($message);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
    $self->{iPhaseErrorCount} = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
# scalar PhaseEnd(void)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
# Closes the current phase and returns a count of the number of errors encountered.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
# This will die if a PhaseStart() has not been declared.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
sub PhaseEnd()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
  my $localTime = ctime();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
  if (defined $self->{iPhase})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
    {   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
    my $message = "+++ HiRes End " . time() . "\n"; # For Scanlog compatibility
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
    $message .= "=== Stage=$self->{stageNumber}.$self->{iPhase} finished $localTime\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
    $self->Print($message);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
  else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
    $self->Die("Error: CConfig::PhaseEnd() called without corresponding PhaseStart()\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
	$self->{iPhase} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
  return $self->{iPhaseErrorCount};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
# void Component(scalar aComponent)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
# Prints out a component for this phase in scanlog format to the log file or stdout
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
sub Component($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
	my ($aComponent) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
  if (!defined $self->{iPhase})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
    $self->Die("Logger: Undefined phase for component \"$aComponent\"\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
  else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
    my $message = "+++ HiRes End " . time() . "\n-- $aComponent\n+++ HiRes Start " . time();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
    $self->Print($message);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
###############################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
# Handling errors and warnings.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
###############################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
# void Error(scalar aMessage)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
# Writes an error message to the logfile (if defined) or stdout
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
# and will increment the error count for this phase.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
sub Error($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
	my ($aMessage) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
  $self->{iPhaseErrorCount} += 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
  my $message = "ERROR: $aMessage";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
  $self->Print($message);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
# void Warning(scalar aMessage)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
# Writes an warning message to the logfile (if defined) or stdout
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
sub Warning($)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
	my ($aMessage) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
  my $message = "WARNING: $aMessage";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
  $self->Print($message);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   522
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   523
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   524
sub DESTROY
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   525
	{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   526
	my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   527
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   528
	# Avoid "unreferenced scalar" error in Perl 5.6 by not calling
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   529
	# PhaseEnd method for each object in multi-threaded CDelta.pm
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   530
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   531
   if ((defined $self->{iPhase}) && ($self->{iPhase} !~ /CDelta/)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   532
      $self->PhaseEnd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   533
   }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   534
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   535
	if (defined($self->{iLOGFILE}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   536
		{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   537
		$self->{iLOGFILE}->close();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   538
		$self->{iLOGFILE} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   539
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   540
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   541
1;