File Coverage

blib/lib/Alien/Build/Plugin/Gather/IsolateDynamic.pm
Criterion Covered Total %
statement 44 44 100.0
branch 7 10 70.0
condition 2 3 66.6
subroutine 9 9 100.0
pod 1 1 100.0
total 63 67 94.0


line stmt bran cond sub pod time code
1             package Alien::Build::Plugin::Gather::IsolateDynamic;
2              
3 3     3   1387 use strict;
  3         6  
  3         97  
4 3     3   20 use warnings;
  3         9  
  3         67  
5 3     3   48 use 5.008004;
  3         10  
6 3     3   459 use Alien::Build::Plugin;
  3         7  
  3         21  
7 3     3   22 use Path::Tiny ();
  3         7  
  3         83  
8 3     3   24 use Alien::Build::Util qw( _destdir_prefix );
  3         43  
  3         152  
9 3     3   1688 use File::Copy ();
  3         7370  
  3         1314  
10              
11             # ABSTRACT: Plugin to gather dynamic libraries into a separate directory
12             our $VERSION = '2.46'; # VERSION
13              
14              
15             sub init
16             {
17 9     9 1 22 my($self, $meta) = @_;
18              
19             # plugin was introduced in 0.42, but had a bug which was fixed in 0.48
20 9         35 $meta->add_requires('share' => 'Alien::Build::Plugin::Gather::IsolateDynamic' => '0.48' );
21              
22             $meta->after_hook(
23             gather_share => sub {
24 2     2   5 my($build) = @_;
25 2         10 $build->log("Isolating dynamic libraries ...");
26              
27 2         9 my $install_root;
28 2 100       8 if($build->meta_prop->{destdir})
29             {
30 1         4 my $destdir = $ENV{DESTDIR};
31 1         5 $install_root = Path::Tiny->new(_destdir_prefix($ENV{DESTDIR}, $build->install_prop->{prefix}));
32             }
33             else
34             {
35 1         4 $install_root = Path::Tiny->new($build->install_prop->{stage});
36             }
37              
38 2         119 foreach my $dir (map { $install_root->child($_) } qw( bin lib ))
  4         70  
39             {
40 4 50       130 next unless -d $dir;
41 4         104 foreach my $from ($dir->children)
42             {
43 16 100 66     1906 next unless $from->basename =~ /\.so/
44             || $from->basename =~ /\.(dylib|bundle|la|dll|dll\.a)$/;
45 10         421 my $to = $install_root->child('dynamic', $from->basename);
46 10         457 $to->parent->mkpath;
47 10 50       1401 unlink "$to" if -e $to;
48 10         239 $build->log("move @{[ $from->parent->basename ]}/@{[ $from->basename ]} => dynamic/@{[ $to->basename ]}");
  10         41  
  10         708  
  10         96  
49 10 50       65 File::Copy::move("$from", "$to") || die "unable to move $from => $to $!";
50             }
51             }
52              
53 2         173 $build->log(" Done!");
54             },
55 9         78 );
56             }
57              
58             1;
59              
60             __END__