| 1 | ## no critic (RequireUseStrict) | ||||||||||||||
| 2 | package Tapper::Producer::Kernel; | ||||||||||||||
| 3 | 1 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||
| 4 | # ABSTRACT: produce preconditions for a kernel package | ||||||||||||||
| 5 | 1 | $Tapper::Producer::Kernel::VERSION = '5.0.1'; | |||||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use YAML; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 1 | ▶ | use 5.010; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 1 | ▶ | use aliased 'Tapper::Config'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use File::stat; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | |||||||||||||||
| 15 | 0 | ▶ | sub younger { stat($a)->mtime() <=> stat($b)->mtime() } | ||||||||||||
|
Subroutine
younger: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | |||||||||||||||
| 18 | 0 | ▶ | sub get_version { | ||||||||||||
|
Subroutine
get_version: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 19 | 0 | my ($self, $kernelbuild) = @_; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | my @files; | |||||||||||||
| 22 | 0 | ▶ | if ($kernelbuild =~ m/gz$/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 23 | 0 | @files = qx(tar -tzf $kernelbuild); | |||||||||||||
| 24 | } elsif ($kernelbuild =~ m/bz2$/) { | ||||||||||||||
| 25 | 0 | @files = qx(tar -tjf $kernelbuild); | |||||||||||||
| 26 | } else { | ||||||||||||||
| 27 | 0 | die 'Can not detect type of file $kernelbuild. Supported types are tar.gz and tar.bz2'; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | 0 | chomp @files; | |||||||||||||
| 30 | 0 | foreach my $file (@files) { | |||||||||||||
| 31 | 0 | ▶ | if ($file =~m|boot/vmlinuz-(.+)$|) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 0 | return {version => $1}; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | } | ||||||||||||||
| 35 | } | ||||||||||||||
| 36 | |||||||||||||||
| 37 | |||||||||||||||
| 38 | 0 | ▶ | sub produce { | ||||||||||||
|
Subroutine
produce: not called CC=6 SCAR=34.6
Pod
documented
| |||||||||||||||
| 39 | 0 | my ($self, $job, $produce) = @_; | |||||||||||||
| 40 | |||||||||||||||
| 41 | 0 | my $pkg_dir = Config->subconfig->{paths}{package_dir}; | |||||||||||||
| 42 | |||||||||||||||
| 43 | # project may be x86_64, stable/x86_64, ... | ||||||||||||||
| 44 | 0 | ▶ | my $project = $produce->{arch} // 'x86_64'; | ||||||||||||
|
Condition0%0/2
$produce->{"arch"} // "x86_64"
MC/DC0%0/1
$produce->{"arch"} // "x86_64"
$produce->{"arch"}
Truth table0%0/2
A
A= $produce->{"arch"}
| |||||||||||||||
| 45 | 0 | my $kernel_path = $pkg_dir."/kernel"; | |||||||||||||
| 46 | 0 | ▶ | $project = "stable/$project" if $produce->{stable}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | |||||||||||||||
| 48 | |||||||||||||||
| 49 | 0 | my $version = '*'; | |||||||||||||
| 50 | 0 | ▶ | $version .= "$produce->{version}*" if $produce->{version}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | 0 | ▶ | my @kernelfiles = sort younger <$kernel_path/$project/$version>; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||
| 52 | 0 | ▶ | die 'No kernel files found' if not @kernelfiles; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 0 | my $kernelbuild = pop @kernelfiles; | |||||||||||||
| 54 | 0 | my $retval = $self->get_version($kernelbuild); | |||||||||||||
| 55 | 0 | my $kernel_version = $retval->{version}; | |||||||||||||
| 56 | 0 | my ($kernel_major_version) = $kernel_version =~ m/(2\.\d{1,2}\.\d{1,2})/; | |||||||||||||
| 57 | 0 | ($kernelbuild) = $kernelbuild =~ m|$pkg_dir/(kernel/$project/.+)$|; | |||||||||||||
| 58 | |||||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | $retval = [ | |||||||||||||
| 61 | { | ||||||||||||||
| 62 | precondition_type => 'package', | ||||||||||||||
| 63 | filename => $kernelbuild, | ||||||||||||||
| 64 | }, | ||||||||||||||
| 65 | { | ||||||||||||||
| 66 | precondition_type => 'exec', | ||||||||||||||
| 67 | filename => '/bin/gen_initrd.sh', | ||||||||||||||
| 68 | options => [ $kernel_version ], | ||||||||||||||
| 69 | } | ||||||||||||||
| 70 | ]; | ||||||||||||||
| 71 | |||||||||||||||
| 72 | return { | ||||||||||||||
| 73 | 0 | ▶ | topic => $produce->{topic} // "kernel-$kernel_major_version-reboot", | ||||||||||||
|
Condition0%0/2
$produce->{"topic"} // "kernel-$kernel_major_version-reboot"
MC/DC0%0/1
$produce->{"topic"} // "kernel-$kernel_major_version-reboot"
$produce->{"topic"}
Truth table0%0/2
A
A= $produce->{"topic"}
| |||||||||||||||
| 74 | precondition_yaml => Dump(@$retval), | ||||||||||||||
| 75 | }; | ||||||||||||||
| 76 | } | ||||||||||||||
| 77 | 1 | 1; | |||||||||||||
| 78 | |||||||||||||||
| 79 | __END__ | ||||||||||||||