[Midnightbsd-cvs] mports: lib/Magus: Add logs.
ctriv at midnightbsd.org
ctriv at midnightbsd.org
Mon Oct 22 23:58:53 EDT 2007
Log Message:
-----------
Add logs. An entry is made in the log table for any phase of a build that
fails. This means that subresult rules now get to see all the output, not
just each line. While this costs some ram, it will be /much/ faster.
Modified Files:
--------------
mports/Tools/lib/Magus:
PortTest.pm (r1.4 -> r1.5)
Result.pm (r1.2 -> r1.3)
mports/Tools/lib/Magus/OutcomeRules:
Base.pm (r1.3 -> r1.4)
Added Files:
-----------
mports/Tools/lib/Magus:
Log.pm (r1.1)
-------------- next part --------------
--- /dev/null
+++ Tools/lib/Magus/Log.pm
@@ -0,0 +1,44 @@
+package Magus::Log;
+#
+# Copyright (c) 2007 Chris Reinhardt. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright notice
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $MidnightBSD: mports/Tools/lib/Magus/Log.pm,v 1.1 2007/10/23 03:58:51 ctriv Exp $
+#
+# MAINTAINER= ctriv at MidnightBSD.org
+#
+
+use strict;
+use warnings;
+use base qw(Magus::DBI);
+
+
+__PACKAGE__->table('logs');
+__PACKAGE__->columns(Essential => qw/result phase data/);
+__PACKAGE__->has_a(result => 'Mport::Result');
+
+
+1;
+__END__
+
Index: Result.pm
===================================================================
RCS file: /home/cvs/mports/Tools/lib/Magus/Result.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -LTools/lib/Magus/Result.pm -LTools/lib/Magus/Result.pm -u -r1.2 -r1.3
--- Tools/lib/Magus/Result.pm
+++ Tools/lib/Magus/Result.pm
@@ -42,6 +42,7 @@
__PACKAGE__->has_a(port => 'Magus::Port');
__PACKAGE__->has_a(machine => 'Magus::Machine');
__PACKAGE__->has_many(subresults => 'Magus::SubResult');
+__PACKAGE__->has_many(logs => 'Magus::Log');
1;
Index: PortTest.pm
===================================================================
RCS file: /home/cvs/mports/Tools/lib/Magus/PortTest.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -LTools/lib/Magus/PortTest.pm -LTools/lib/Magus/PortTest.pm -u -r1.4 -r1.5
--- Tools/lib/Magus/PortTest.pm
+++ Tools/lib/Magus/PortTest.pm
@@ -123,9 +123,17 @@
$results{summary} = 'fail';
}
+ my $log;
+ {
+ local $/;
+ open(my $fh, '<', "$self->{logdir}/$target") || die "Couldn't open $self->{logdir}/$target: $!\n";
+ $log = <$fh>;
+ close($fh) || die "Couldn't close $self->{logdir}/$target: $!\n";
+ }
+
my $testclass = "Magus::OutcomeRules::$target";
- my $presults = $testclass->test("$self->{logdir}/$target");
+ my $presults = $testclass->test(\$log);
# update the summary if the phase results is worse than what we had.
if ($results{summary} eq 'pass' || ($results{summary} eq 'warn' && $presults->{'summary'} ne 'pass')) {
@@ -141,6 +149,10 @@
}
if ($results{summary} eq 'fail') {
+ $results{log} = {
+ phase => $target,
+ data => $log,
+ };
last;
}
}
Index: Base.pm
===================================================================
RCS file: /home/cvs/mports/Tools/lib/Magus/OutcomeRules/Base.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -LTools/lib/Magus/OutcomeRules/Base.pm -LTools/lib/Magus/OutcomeRules/Base.pm -u -r1.3 -r1.4
--- Tools/lib/Magus/OutcomeRules/Base.pm
+++ Tools/lib/Magus/OutcomeRules/Base.pm
@@ -96,42 +96,36 @@
}
sub test {
- my ($class, $file) = @_;
+ my ($class, $output) = @_;
my %result = (
summary => 'pass'
);
- open(my $log, '<', $file) || die "Couldn't open $file: $!\n";
+ local $_ = $$output;
- # This kinda sucks (O(n^2)), but it's abstract enough that it can optimized later.
- while (<$log>) {
- foreach my $rule (@{$class->warning_rules || []}) {
- if (my $msg = $rule->()) {
- $result{summary} = 'warn' if $result{summary} eq 'pass';
- push(@{$result{warnings}}, {
- phase => $rule->{phase},
- msg => $msg,
- name => $rule->{name},
- });
- }
+ foreach my $rule (@{$class->warning_rules || []}) {
+ if (my $msg = $rule->()) {
+ $result{summary} = 'warn' if $result{summary} eq 'pass';
+ push(@{$result{warnings}}, {
+ phase => $rule->{phase},
+ msg => $msg,
+ name => $rule->{name},
+ });
}
+ }
- foreach my $rule (@{$class->error_rules || []}) {
- if (my $msg = $rule->{code}->()) {
- $result{summary} = 'fail';
- push(@{$result{errors}}, {
- phase => $rule->{phase},
- msg => $msg,
- name => $rule->{name},
- });
- }
+ foreach my $rule (@{$class->error_rules || []}) {
+ if (my $msg = $rule->{code}->()) {
+ $result{summary} = 'fail';
+ push(@{$result{errors}}, {
+ phase => $rule->{phase},
+ msg => $msg,
+ name => $rule->{name},
+ });
}
-
}
-
- close($log) || die "Couldn't close $file: $!\n";
-
+
return \%result;
}
More information about the Midnightbsd-cvs
mailing list