| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Build::Plugin::Core::Gather; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 47 |  |  | 47 |  | 2375 | use strict; | 
|  | 47 |  |  |  |  | 97 |  | 
|  | 47 |  |  |  |  | 1349 |  | 
| 4 | 47 |  |  | 47 |  | 259 | use warnings; | 
|  | 47 |  |  |  |  | 105 |  | 
|  | 47 |  |  |  |  | 1010 |  | 
| 5 | 47 |  |  | 47 |  | 701 | use 5.008004; | 
|  | 47 |  |  |  |  | 152 |  | 
| 6 | 47 |  |  | 47 |  | 711 | use Alien::Build::Plugin; | 
|  | 47 |  |  |  |  | 125 |  | 
|  | 47 |  |  |  |  | 362 |  | 
| 7 | 47 |  |  | 47 |  | 1380 | use Env qw( @PATH @PKG_CONFIG_PATH ); | 
|  | 47 |  |  |  |  | 2990 |  | 
|  | 47 |  |  |  |  | 428 |  | 
| 8 | 47 |  |  | 47 |  | 10654 | use Path::Tiny (); | 
|  | 47 |  |  |  |  | 111 |  | 
|  | 47 |  |  |  |  | 731 |  | 
| 9 | 47 |  |  | 47 |  | 918 | use File::chdir; | 
|  | 47 |  |  |  |  | 3486 |  | 
|  | 47 |  |  |  |  | 5561 |  | 
| 10 | 47 |  |  | 47 |  | 335 | use Alien::Build::Util qw( _mirror _destdir_prefix ); | 
|  | 47 |  |  |  |  | 120 |  | 
|  | 47 |  |  |  |  | 2574 |  | 
| 11 | 47 |  |  | 47 |  | 1256 | use JSON::PP (); | 
|  | 47 |  |  |  |  | 15544 |  | 
|  | 47 |  |  |  |  | 39851 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | # ABSTRACT: Core gather plugin | 
| 14 |  |  |  |  |  |  | our $VERSION = '2.45'; # VERSION | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub init | 
| 18 |  |  |  |  |  |  | { | 
| 19 | 322 |  |  | 322 | 1 | 892 | my($self, $meta) = @_; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | $meta->default_hook( | 
| 22 |  |  |  | 23 |  |  | $_ => sub {}, | 
| 23 | 322 |  |  |  |  | 2197 | ) for qw( gather_system gather_share ); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | $meta->around_hook( | 
| 26 |  |  |  |  |  |  | gather_share => sub { | 
| 27 | 30 |  |  | 30 |  | 101 | my($orig, $build) = @_; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 30 |  |  |  |  | 200 | local $ENV{PATH} = $ENV{PATH}; | 
| 30 | 30 |  |  |  |  | 156 | local $ENV{PKG_CONFIG_PATH} = $ENV{PKG_CONFIG_PATH}; | 
| 31 | 30 | 100 |  |  |  | 635 | unshift @PATH, Path::Tiny->new('bin')->absolute->stringify | 
| 32 |  |  |  |  |  |  | if -d 'bin'; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 30 |  |  |  |  | 1012 | for my $dir (qw(share lib)) { | 
| 35 | 60 | 100 |  |  |  | 1113 | unshift @PKG_CONFIG_PATH, Path::Tiny->new("$dir/pkgconfig")->absolute->stringify | 
| 36 |  |  |  |  |  |  | if -d "$dir/pkgconfig"; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 30 |  |  |  |  | 767 | $orig->($build) | 
| 40 |  |  |  |  |  |  | } | 
| 41 | 322 |  |  |  |  | 2154 | ); | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 322 |  |  |  |  | 940 | foreach my $type (qw( share ffi )) | 
| 44 |  |  |  |  |  |  | { | 
| 45 |  |  |  |  |  |  | $meta->around_hook( | 
| 46 |  |  |  |  |  |  | "gather_$type" => sub { | 
| 47 | 60 |  |  | 60 |  | 244 | my($orig, $build) = @_; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 60 | 100 |  |  |  | 228 | if($build->meta_prop->{destdir}) | 
| 50 |  |  |  |  |  |  | { | 
| 51 | 12 |  |  |  |  | 37 | my $destdir = $ENV{DESTDIR}; | 
| 52 | 12 | 100 |  |  |  | 257 | if(-d $destdir) | 
| 53 |  |  |  |  |  |  | { | 
| 54 | 8 |  |  |  |  | 55 | my $src = Path::Tiny->new(_destdir_prefix($ENV{DESTDIR}, $build->install_prop->{prefix})); | 
| 55 | 8 |  |  |  |  | 743 | my $dst = Path::Tiny->new($build->install_prop->{stage}); | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 8 |  |  |  |  | 204 | my $res = do { | 
| 58 | 8 |  |  |  |  | 30 | local $CWD = "$src"; | 
| 59 | 8 |  |  |  |  | 485 | $orig->($build); | 
| 60 |  |  |  |  |  |  | }; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 8 |  |  |  |  | 320 | $build->log("mirror $src => $dst"); | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 8 |  |  |  |  | 59 | $dst->mkpath; | 
| 65 |  |  |  |  |  |  | # Please note: _mirror and Alien::Build::Util are ONLY | 
| 66 |  |  |  |  |  |  | # allowed to be used by core plugins.  If you are writing | 
| 67 |  |  |  |  |  |  | # a non-core plugin it may be removed.  That is why it | 
| 68 |  |  |  |  |  |  | # is private. | 
| 69 |  |  |  |  |  |  | _mirror("$src", "$dst", { | 
| 70 |  |  |  |  |  |  | verbose => 1, | 
| 71 | 8 | 100 |  |  |  | 557 | filter => $build->meta_prop->{$type eq 'share' ? 'destdir_filter' : 'destdir_ffi_filter'}, | 
| 72 |  |  |  |  |  |  | }); | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 8 |  |  |  |  | 79 | return $res; | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  | else | 
| 77 |  |  |  |  |  |  | { | 
| 78 | 4 | 50 |  |  |  | 47 | die "nothing was installed into destdir" if $type eq 'share'; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  | else | 
| 82 |  |  |  |  |  |  | { | 
| 83 | 48 |  |  |  |  | 152 | local $CWD = $build->install_prop->{stage}; | 
| 84 | 48 |  |  |  |  | 2392 | my $ret = $orig->($build); | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | # if we are not doing a double staged install we want to substitute the install | 
| 87 |  |  |  |  |  |  | # prefix with the runtime prefix. | 
| 88 | 48 |  |  |  |  | 196 | my $old = $build->install_prop->{prefix}; | 
| 89 | 48 |  |  |  |  | 169 | my $new = $build->runtime_prop->{prefix}; | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 48 |  |  |  |  | 168 | foreach my $flag (qw( cflags cflags_static libs libs_static )) | 
| 92 |  |  |  |  |  |  | { | 
| 93 | 192 | 100 |  |  |  | 386 | next unless defined $build->runtime_prop->{$flag}; | 
| 94 | 40 |  |  |  |  | 102 | $build->runtime_prop->{$flag} =~ s{(-I|-L|-LIBPATH:)\Q$old\E}{$1 . $new}eg; | 
|  | 0 |  |  |  |  | 0 |  | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 | 48 |  |  |  |  | 223 | return $ret; | 
| 98 |  |  |  |  |  |  | } | 
| 99 |  |  |  |  |  |  | } | 
| 100 | 644 |  |  |  |  | 4389 | ); | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | $meta->after_hook( | 
| 104 |  |  |  |  |  |  | $_ => sub { | 
| 105 | 42 |  |  | 42 |  | 141 | my($build) = @_; | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | die "stage is not defined.  be sure to call set_stage on your Alien::Build instance" | 
| 108 | 42 | 50 |  |  |  | 200 | unless $build->install_prop->{stage}; | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 42 |  |  |  |  | 164 | my $stage = Path::Tiny->new($build->install_prop->{stage}); | 
| 111 | 42 |  |  |  |  | 1503 | $build->log("mkdir -p $stage/_alien"); | 
| 112 | 42 |  |  |  |  | 303 | $stage->child('_alien')->mkpath; | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | # drop a alien.json file for the runtime properties | 
| 115 | 42 |  |  |  |  | 9458 | $stage->child('_alien/alien.json')->spew( | 
| 116 |  |  |  |  |  |  | JSON::PP->new->pretty->canonical(1)->ascii->encode($build->runtime_prop) | 
| 117 |  |  |  |  |  |  | ); | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | # copy the alienfile, if we managed to keep it around. | 
| 120 | 42 | 50 | 33 |  |  | 61032 | if($build->meta->filename                 && | 
|  |  |  | 33 |  |  |  |  | 
|  |  |  | 33 |  |  |  |  | 
| 121 |  |  |  |  |  |  | -r $build->meta->filename              && | 
| 122 |  |  |  |  |  |  | $build->meta->filename !~ /\.(pm|pl)$/ && | 
| 123 |  |  |  |  |  |  | ! -d $build->meta->filename) | 
| 124 |  |  |  |  |  |  | { | 
| 125 | 42 |  |  |  |  | 243 | Path::Tiny->new($build->meta->filename) | 
| 126 |  |  |  |  |  |  | ->copy($stage->child('_alien/alienfile')); | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 42 | 100 | 66 |  |  | 53567 | if($build->install_prop->{patch} && -d $build->install_prop->{patch}) | 
| 130 |  |  |  |  |  |  | { | 
| 131 |  |  |  |  |  |  | # Please note: _mirror and Alien::Build::Util are ONLY | 
| 132 |  |  |  |  |  |  | # allowed to be used by core plugins.  If you are writing | 
| 133 |  |  |  |  |  |  | # a non-core plugin it may be removed.  That is why it | 
| 134 |  |  |  |  |  |  | # is private. | 
| 135 |  |  |  |  |  |  | _mirror($build->install_prop->{patch}, | 
| 136 | 1 |  |  |  |  | 6 | $stage->child('_alien/patch')->stringify); | 
| 137 |  |  |  |  |  |  | } | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | }, | 
| 140 | 322 |  |  |  |  | 2703 | ) for qw( gather_share gather_system ); | 
| 141 |  |  |  |  |  |  | } | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | 1; | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | __END__ |