BuildCommand/Check/RPMLint.pm

filter: Statementstmt 52.8% 37 / 70 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 76.9% 10 / 13 Podpod 0.0% 0 / 1 totaltotal 44.3% 47 / 106 CC 9 SCAR 36.7
CC
9
Cov
43%
run
90.0
__ANON__
2.0
BEGIN
1.0
CRAP 39.2
« Builder/RPM.pm ↑ Summary Builder.pm »
1 package PkgForge::BuildCommand::Check::RPMLint; # -*-perl-*-
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # $Id: RPMLint.pm.in 16798 2011-04-22 11:50:05Z squinney@INF.ED.AC.UK $
6 # $Source:$
7 # $Revision: 16798 $
8 # $HeadURL: https://svn.lcfg.org/svn/source/tags/PkgForge-Server/PkgForge_Server_1_1_10/lib/PkgForge/BuildCommand/Check/RPMLint.pm.in $
9 # $Date: 2011-04-22 12:50:05 +0100 (Fri, 22 Apr 2011) $
10  
11 1 our $VERSION = '1.1.10';
12  
13 1 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use IO::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use IPC::Run ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 Readonly my $RPMLINT => '/usr/bin/rpmlint';
21 1 Readonly my $ERRORS_FOUND_CODE => 64;
22  
23 0 ▶use overload q{""} => sub { shift->stringify };
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
24  
25 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 with 'PkgForge::BuildCommand::Check';
28  
29 has '+tools' => (
30 0 ▶ default => sub { [$RPMLINT] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 1 );
32  
33 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 __PACKAGE__->meta->make_immutable;
35  
36 0 ▶sub run {
Subroutine run: not called CC=9 SCAR=45.0
Pod undocumented
37 0 my ( $self, $job, $buildinfo, $buildlog ) = @_;
38  
39 0 my $logger = $buildlog->logger;
40  
41 0 my $logdir = $buildlog->logdir;
42  
43 0 my $rpmlint_log = File::Spec->catfile( $logdir, 'check-rpmlint.log' );
44 0 ▶ my $logfh = IO::File->new( $rpmlint_log, 'w' )
Branch: 1 branch
BranchTrueFalseTotal
my $logfh = "IO::File"->new($rpmlint_log, "w") or $logger->log_and_die("level", "error", "message", "Could not open '${rpmlint_log}' for writing: $PkgForge::BuildCommand::Check::RPMLint::OS_ERROR") 0 0 0
45 or $logger->log_and_die(
46 level => 'error',
47 message => "Could not open '$rpmlint_log' for writing: $OS_ERROR",
48 );
49  
50 0 $logfh->autoflush(1);
51  
52 0 $buildinfo->add_logs($rpmlint_log);
53  
54 0 my $errors = 0;
55 0 for my $pkg ($buildinfo->products_list) {
56 0 ▶ if ( $pkg !~ m/\.rpm$/ || $pkg =~ m/\.src\.rpm$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pkg =~ /\.rpm$/ or $pkg =~ /\.src\.rpm$/) 0 0 0
Condition0%0/3
not $pkg =~ /\.rpm$/ or $pkg =~ /\.src\.rpm$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $pkg =~ /\.rpm$/ or $pkg =~ /\.src\.rpm$/
not $pkg =~ /\.rpm$/ $pkg =~ /\.src\.rpm$/
Truth table0%0/3
not(A) or B
A= not $pkg =~ /\.rpm$/B= $pkg =~ /\.src\.rpm$/
ABresult
1X1
011
000
57 0 next;
58 }
59  
60 0 $logger->info("Running rpmlint on $pkg");
61 0 $logfh->print("Running rpmlint on $pkg\n");
62  
63 0 my @cmd = ( $RPMLINT, $pkg );
64  
65 0 $logger->debug("Will run command '@cmd'");
66  
67 0 my $rpmlint_out;
68 0 my $ok = eval { IPC::Run::run( \@cmd, \undef, '>&', \$rpmlint_out ) };
69 0 my $err_msg = $EVAL_ERROR;
70 0 my $exit_code = $CHILD_ERROR >> 8;
71 0 my $errors_found = $exit_code & $ERRORS_FOUND_CODE;
72  
73 0 $logfh->print($rpmlint_out);
74 0 $logfh->print("\n\n");
75  
76 0 ▶ if ( $err_msg || ( !$ok && !$errors_found ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err_msg or not $ok || $errors_found) 0 0 0
Condition0%0/6
$err_msg or not $ok || $errors_found
l!l&&r!l&&!r
000
$ok || $errors_found
l!l&&r!l&&!r
000
MC/DC0%0/3
$err_msg or not $ok || $errors_found
$err_msg $ok $errors_found
Truth table0%0/4
A or not(B || C)
A= $err_msgB= $okC= $errors_found
ABCresult
1XX1
0001
01X0
0010
77 0 $logger->log_and_die(
78 level => 'error',
79 message => "Failed to run rpmlint: $err_msg",
80 );
81 }
82  
83 0 ▶ if ($errors_found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errors_found) { } 0 0 0
84 0 $errors++;
85 0 $logger->error("Package '$pkg' failed the rpmlint check");
86 } else {
87 0 $logger->info("Package '$pkg' passed the rpmlint check");
88 }
89  
90 }
91  
92 0 $logfh->close();
93  
94 # For now we are not requiring the passing of rpmlint checks
95 #return ( $errors == 0 ? 1 : 0 );
96 0 return 1;
97 }
98  
99 1 1;
100 __END__
« Builder/RPM.pm ↑ Summary Builder.pm »