common/tools/raptor/preprocess_log.pl
author Simon Howkins <simonh@symbian.org>
Tue, 06 Oct 2009 14:41:22 +0100
changeset 603 948baffead3b
parent 243 71d24b4fa162
child 843 c32873117195
permissions -rw-r--r--
Parse log generated during proprocessing of zip config, so it gets included in BRAG analysis.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
     1
#!perl -w
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     2
# Copyright (c) 2009 Symbian Foundation Ltd
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     3
# This component and the accompanying materials are made available
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     5
# which accompanies this distribution, and is available
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     7
#
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     8
# Initial Contributors:
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     9
# Symbian Foundation Ltd - initial contribution.
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    10
#
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    11
# Contributors:
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    12
#
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    13
# Description:
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    14
# Preprocess a raptor log, trying to countermeasure a list of known anomalies
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    15
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    16
use strict;
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    17
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    18
use Getopt::Long;
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    19
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    20
my $help = 0;
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    21
GetOptions(
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    22
	'help!' => \$help,
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    23
);
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    24
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    25
if ($help)
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    26
{
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    27
	warn <<"EOF";
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    28
Preprocess a raptor log, trying to countermeasure a list of known anomalies
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    29
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    30
Usage: perl preprocess_log.pl < INFILE > OUTFILE
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    31
EOF
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    32
	exit(0);
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    33
}
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    34
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    35
while (my $line = <>)
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    36
{
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    37
	if ($line =~ m{<[^<^>]+>.*&.*</[^<^>]+>})
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    38
	{
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    39
		$line = escape_ampersand($line);
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    40
	}
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    41
	elsif ($line =~ m{<\?xml\s.*encoding=.*\".*\?>})
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    42
	{
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    43
		$line = set_encoding_utf8($line);
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    44
	}
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    45
	elsif ($line =~ m{<archive.*?[^/]>})
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    46
	{
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    47
		$line = unterminated_archive_tag($line, scalar <>, $.)
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    48
	}
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    49
	
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    50
	print $line;
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    51
}
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    52
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    53
sub escape_ampersand
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    54
{
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    55
	my ($line) = @_;
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    56
	
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    57
	warn "escape_ampersand\n";
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    58
	warn "in: $line";
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    59
	
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    60
	$line =~ s,&,&amp;,g;
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    61
	
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    62
	warn "out: $line";
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    63
	return $line;
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    64
}
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    65
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    66
sub set_encoding_utf8
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    67
{
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    68
	my ($line) = @_;
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    69
	
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    70
	warn "set_encoding_utf8\n";
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    71
	warn "in: $line";
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    72
	
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    73
	$line =~ s,encoding=".*",encoding="utf-8",;
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    74
	
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    75
	warn "out: $line";
222
1d9c60a4e308 Adding extraction of whatlog information into "deliverables" files
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    76
	return $line;
243
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    77
}
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    78
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    79
sub unterminated_archive_tag
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    80
{
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    81
	my $line = shift;
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    82
	my $nextLine = shift;
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    83
	my $lineNum = shift;
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    84
	
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    85
	if ($nextLine !~ m{(<member>)|(</archive>)})
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    86
	{
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    87
		warn "unterminated_archive_tag\n";
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    88
		warn "in: $line";
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    89
		$line =~ s{>}{/>};
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    90
		warn "out: $line";
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    91
	}
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    92
	
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    93
	return $line . $nextLine;
71d24b4fa162 Updated preprocess_log to deal with mal-formed <archive> tags - workaround for Bug 170.
Simon Howkins <simonh@symbian.org>
parents: 222
diff changeset
    94
}