Furthermore LoadLogErrorsFromFh() returns unsupported lines to the caller (in addition to setting BadLog) which allows embedding .errors-formatted sections in other text files.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/WineTestBot/LogUtils.pm | 99 +++++++++++++++++------------ 1 file changed, 60 insertions(+), 39 deletions(-)
diff --git a/testbot/lib/WineTestBot/LogUtils.pm b/testbot/lib/WineTestBot/LogUtils.pm index 1e7dcda8..17be624e 100644 --- a/testbot/lib/WineTestBot/LogUtils.pm +++ b/testbot/lib/WineTestBot/LogUtils.pm @@ -31,7 +31,7 @@ our @EXPORT = qw(GetLogFileNames GetLogLabel GetLogLineCategory GetReportLineCategory ParseTaskLog ParseWineTestReport SnapshotLatestReport UpdateLatestReport UpdateLatestReports - CreateLogErrorsCache LoadLogErrors); + CreateLogErrorsCache LoadLogErrorsFromFh LoadLogErrors);
use Algorithm::Diff; use File::Basename; @@ -830,11 +830,10 @@ sub GetLogLabel($) =pod =over 12
-=item C<LoadLogErrors()> - -Loads the specified log errors file. +=item C<LoadLogErrorsFromFh()>
-Returns the errors in the same format as TagNewErrors(). +Loads the specified log errors file, returning the errors in the same format +as TagNewErrors().
All lines are of the following form: <type> <value1> <value2> @@ -867,37 +866,23 @@ different type. =back =cut
-sub LoadLogErrors($) +sub LoadLogErrorsFromFh($$) { - my ($LogPath) = @_; + my ($LogInfo, $ErrorsFile) = @_;
- my $LogName = basename($LogPath); - my $LogInfo = { - LogName => $LogName, - LogPath => $LogPath, + $LogInfo->{ErrGroupNames} ||= []; + $LogInfo->{ErrGroups} ||= {};
- ErrGroupNames => [], - ErrGroups => {}, - }; - $LogPath .= ".errors"; - - my $ErrorsFile; - if (!open($ErrorsFile, "<", $LogPath)) - { - $LogInfo->{BadLog} = "Unable to open '$LogName.errors' for reading: $!"; - return $LogInfo; - } - - my ($LineNo, $CurGroup); - foreach my $Line (<$ErrorsFile>) + while (my $Line = <$ErrorsFile>) { - $LineNo++; + $LogInfo->{LineNo}++; chomp $Line; + my ($Type, $Property, $Value) = split / /, $Line, 3; if (!defined $Value) { - $LogInfo->{BadLog} = "$LineNo: Found an invalid line"; - last; + $LogInfo->{BadLog} = "$LogInfo->{LineNo}: Found an invalid line"; + return $Line; } # else $Type, $Property and $Value are all defined elsif ($Type eq "p") @@ -908,34 +893,70 @@ sub LoadLogErrors($) } else { - $LogInfo->{BadLog} = "$LineNo: Cannot set $Property = $Value because it is already set to $LogInfo->{$Property}"; - last; + $LogInfo->{BadLog} = "$LogInfo->{LineNo}: Cannot set $Property = $Value because it is already set to $LogInfo->{$Property}"; + return $Line; } } elsif ($Type eq "g") { - $CurGroup = _AddLogGroup($LogInfo, $Value, $Property); + $LogInfo->{CurGroup} = _AddLogGroup($LogInfo, $Value, $Property); } - elsif (!$CurGroup) + elsif (!$LogInfo->{CurGroup}) { - $LogInfo->{BadLog} = "$LineNo: Got a $Type line with no group"; - last; + $LogInfo->{BadLog} = "$LogInfo->{LineNo}: Got a $Type line with no group"; + return $Line; } elsif ($Type eq "o") { - _AddLogError($LogInfo, $CurGroup, $Value, $Property); + _AddLogError($LogInfo, $LogInfo->{CurGroup}, $Value, $Property); } elsif ($Type eq "n") { - _AddLogError($LogInfo, $CurGroup, $Value, $Property, "new"); + _AddLogError($LogInfo, $LogInfo->{CurGroup}, $Value, $Property, "new"); } else { - $LogInfo->{BadLog} = "$LineNo: Found an unknown line type ($Type)"; - last; + $LogInfo->{BadLog} = "$LogInfo->{LineNo}: Found an unknown line type ($Type)"; + return $Line; } } - close($ErrorsFile); + + return undef; +} + +=pod +=over 12 + +=item C<LoadLogErrors()> + +Loads the specified log errors file. + +See _LoadLogErrorsFromFh() for the format of the errors file. + +Returns the errors in the same format as TagNewErrors(). + +=back +=cut + +sub LoadLogErrors($) +{ + my ($LogPath) = @_; + + my $LogInfo = { + LogName => basename($LogPath), + LogPath => $LogPath, + }; + if (open(my $ErrorsFile, "<", "$LogPath.errors")) + { + LoadLogErrorsFromFh($LogInfo, $ErrorsFile); + delete $LogInfo->{CurGroup}; + close($ErrorsFile); + } + else + { + $LogInfo->{BadLog} = "Unable to open '$LogInfo->{LogName}.errors' for reading: $!"; + return $LogInfo; + }
return $LogInfo; }