Arepa/Job/CompilePackage.pm

filter: Statementstmt 34.6% 26 / 75 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 72.7% 8 / 11 Podpod 50.0% 1 / 2 totaltotal 33.9% 35 / 103 CC 9 SCAR 27.9
CC
9
Cov
29%
_work
42.0
work
12.0
print
6.0
CRAP 16.2
« Arepa/CommandManager.pm ↑ Summary Arepa/Web/Repository.pm »
1 package Arepa::Job::CompilePackage;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base qw( TheSchwartz::Worker );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use TheSchwartz::Job;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Arepa::BuilderFarm;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Arepa::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 our $PrintMessages = 0;
16  
17 0 ▶sub work {
Subroutine work: not called CC=3 SCAR=24.8
Pod documented
18 0 my $class = shift;
19 0 my TheSchwartz::Job $job = shift;
20  
21 0 ▶ my $config_file = $ENV{AREPA_CONFIG} || '/etc/arepa/config.yml';
Condition0%0/2
$ENV{'AREPA_CONFIG'} || '/etc/arepa/config.yml'
l!l
00
MC/DC0%0/1
$ENV{'AREPA_CONFIG'} || '/etc/arepa/config.yml'
$ENV{'AREPA_CONFIG'}
Truth table0%0/2
A
A= $ENV{'AREPA_CONFIG'}
Aresult
11
00
22 0 my $farm = Arepa::BuilderFarm->new($config_file);
23  
24 0 my $id = $job->arg->{compilation_queue_id};
25 0 eval {
26 0 $farm->package_db->mark_compilation_started($id);
27 0 $class->_work($config_file, $id);
28 };
29 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
30 0 my $error = $@;
31  
32 0 $farm->package_db->mark_compilation_failed($id);
33 0 $job->permanent_failure($error);
34 0 $class->print("ERROR: " . $error);
35 0 exit 1;
36 }
37 else {
38 0 $job->completed;
39 }
40 }
41  
42 0 ▶sub _work {
Subroutine _work: not called CC=6 SCAR=37.4
43 0 my ($class, $config_file, $id) = @_;
44  
45 0 my $farm = Arepa::BuilderFarm->new($config_file);
46 0 my $repo = Arepa::Repository->new($config_file);
47 0 my %req;
48  
49 0 eval {
50 0 %req = $farm->package_db->get_compilation_request_by_id($id);
51 };
52 0 ▶ if (! %req) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%req) 0 0 0
53 0 die "Can't find a compilation request with id '$id'";
54 }
55  
56 my ($builder) = $farm->get_matching_builders($req{architecture},
57 0 $req{distribution});
58 0 ▶ if (!defined $builder) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $builder) 0 0 0
59 0 die "There aren't any builders for $req{distribution}/" .
60 "$req{architecture}?\n";
61 }
62  
63 # Actual package compilation
64 0 my $source_pkg_id = $req{source_package_id};
65 0 my %source_attrs = $farm->package_db->
66 get_source_package_by_id($source_pkg_id);
67 0 $class->print("Compiling request id $req{id}\n");
68 0 $class->print("$source_attrs{name} $source_attrs{full_version} ");
69 0 $class->print("(arch: $req{architecture}, ");
70 0 $class->print("distro: $req{distribution}) ");
71 0 $class->print("with builder $builder...\n");
72 0 my $temp_dir = File::Temp::tempdir();
73 0 ▶ if ($farm->compile_package_from_queue($builder,
Branch: 1 branch
BranchTrueFalseTotal
if ($farm->compile_package_from_queue($builder, $req{'id'}, 'output_dir', $temp_dir)) { } 0 0 0
74 $req{id},
75 output_dir => $temp_dir)) {
76 0 $class->print("*** SUCCESS ***\n");
77 0 foreach my $deb_package (glob("$temp_dir/*.deb")) {
78 0 $class->print("Adding $deb_package to the repository\n");
79 0 ▶ if ($repo->insert_binary_package($deb_package,
Branch: 1 branch
BranchTrueFalseTotal
if ($repo->insert_binary_package($deb_package, $req{"distribution"})) 0 0 0
80 $req{distribution})) {
81 0 unlink $deb_package;
82 }
83 }
84 0 $repo->sign_distribution($req{distribution});
85 } else {
86 0 $class->print("*** FAILED ***\n\n");
87 0 $class->print("You can see the build log at ");
88 0 my $build_log_dir = $repo->get_config_key('dir:build_logs');
89 0 $class->print(File::Spec->catfile($build_log_dir, $id), "\n");
90 }
91 0 rmtree($temp_dir);
92 }
93  
94 0 ▶sub print {
Subroutine print: not called CC=2 SCAR=17.9
Pod undocumented
95 0 my ($class, @args) = @_;
96  
97 0 ▶ if ($PrintMessages) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Arepa::Job::CompilePackage::PrintMessages) 0 0 0
98 0 print @args;
99 }
100 }
101  
102 1 1;
« Arepa/CommandManager.pm ↑ Summary Arepa/Web/Repository.pm »