File Coverage

blib/lib/PkgForge/BuildCommand/Check/RPMLint.pm
Criterion Covered Total %
statement 30 62 48.3
branch 0 8 0.0
condition 0 9 0.0
subroutine 10 12 83.3
pod 0 1 0.0
total 40 92 43.4


line stmt bran cond sub pod time code
1             package PkgForge::BuildCommand::Check::RPMLint; # -*-perl-*-
2 1     1   1644 use strict;
  1         2  
  1         43  
3 1     1   6 use warnings;
  1         2  
  1         56  
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             our $VERSION = '1.1.10';
12              
13 1     1   6 use English qw(-no_match_vars);
  1         3  
  1         9  
14 1     1   541 use File::Spec ();
  1         3  
  1         17  
15 1     1   6 use IO::File ();
  1         3  
  1         15  
16 1     1   7 use IPC::Run ();
  1         4  
  1         16  
17              
18 1     1   6 use Readonly;
  1         2  
  1         105  
19              
20             Readonly my $RPMLINT => '/usr/bin/rpmlint';
21             Readonly my $ERRORS_FOUND_CODE => 64;
22              
23 1     1   6 use overload q{""} => sub { shift->stringify };
  1     0   2  
  1         12  
  0         0  
24              
25 1     1   70 use Moose;
  1         2  
  1         8  
26              
27             with 'PkgForge::BuildCommand::Check';
28              
29             has '+tools' => (
30             default => sub { [$RPMLINT] },
31             );
32              
33 1     1   12702 no Moose;
  1         2  
  1         5  
34             __PACKAGE__->meta->make_immutable;
35              
36             sub run {
37 0     0 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 0         my $logfh = IO::File->new( $rpmlint_log, 'w' )
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 0 0       if ( $pkg !~ m/\.rpm$/ || $pkg =~ m/\.src\.rpm$/ ) {
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 ) };
  0            
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 0 0       if ( $err_msg || ( !$ok && !$errors_found ) ) {
      0        
77 0           $logger->log_and_die(
78             level => 'error',
79             message => "Failed to run rpmlint: $err_msg",
80             );
81             }
82              
83 0 0         if ($errors_found) {
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;
100             __END__