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   1278 use strict;
  3         7  
  3         89  
4 3     3   15 use warnings;
  3         6  
  3         65  
5 3     3   80 use 5.008004;
  3         10  
6 3     3   387 use Alien::Build::Plugin;
  3         6  
  3         20  
7 3     3   21 use Path::Tiny ();
  3         7  
  3         65  
8 3     3   18 use Alien::Build::Util qw( _destdir_prefix );
  3         12  
  3         132  
9 3     3   1604 use File::Copy ();
  3         6930  
  3         1230  
10              
11             # ABSTRACT: Plugin to gather dynamic libraries into a separate directory
12             our $VERSION = '2.45'; # VERSION
13              
14              
15             sub init
16             {
17 9     9 1 21 my($self, $meta) = @_;
18              
19             # plugin was introduced in 0.42, but had a bug which was fixed in 0.48
20 9         34 $meta->add_requires('share' => 'Alien::Build::Plugin::Gather::IsolateDynamic' => '0.48' );
21              
22             $meta->after_hook(
23             gather_share => sub {
24 2     2   7 my($build) = @_;
25 2         9 $build->log("Isolating dynamic libraries ...");
26              
27 2         7 my $install_root;
28 2 100       16 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         3 $install_root = Path::Tiny->new($build->install_prop->{stage});
36             }
37              
38 2         98 foreach my $dir (map { $install_root->child($_) } qw( bin lib ))
  4         57  
39             {
40 4 50       107 next unless -d $dir;
41 4         81 foreach my $from ($dir->children)
42             {
43 16 100 66     1620 next unless $from->basename =~ /\.so/
44             || $from->basename =~ /\.(dylib|bundle|la|dll|dll\.a)$/;
45 10         353 my $to = $install_root->child('dynamic', $from->basename);
46 10         374 $to->parent->mkpath;
47 10 50       1106 unlink "$to" if -e $to;
48 10         201 $build->log("move @{[ $from->parent->basename ]}/@{[ $from->basename ]} => dynamic/@{[ $to->basename ]}");
  10         41  
  10         579  
  10         86  
49 10 50       59 File::Copy::move("$from", "$to") || die "unable to move $from => $to $!";
50             }
51             }
52              
53 2         71 $build->log(" Done!");
54             },
55 9         75 );
56             }
57              
58             1;
59              
60             __END__