blib/lib/Alien/Build/Plugin/Build/Autoconf.pm

filter: Statementstmt 80.2% 73 / 91 Branchbran 45.4% 10 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 86.6% 13 / 15 Podpod 100% 1 / 1 totaltotal 75.1% 97 / 129 CC 13 SCAR 12.6
CC
13
Cov
73%
__ANON__
12.0
init
4.8
__ANON__
3.1
CRAP 3.5
« blib/lib/Alien/Build/Interpolate.pm ↑ Summary blib/lib/Alien/Build/Plugin/Build/Copy.pm »
1 package Alien::Build::Plugin::Build::Autoconf;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use constant _win => $^O eq 'MSWin32';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # ABSTRACT: Autoconf plugin for Alien::Build
12 4 our $VERSION = '2.88'; # VERSION
13  
14  
15 4 has with_pic => 1;
16 4 has ffi => 0;
17 4 has msys_version => undef;
18 8 ▶has config_site => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
19  
20 8 my $config_site = "# file automatically generated by @{[ __FILE__ ]}\n";
21 8 ▶ $config_site .= ". $ENV{CONFIG_SITE}\n" if defined $ENV{CONFIG_SITE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"CONFIG_SITE"} 0 8 8
22 8 ▶ $config_site .= ". $ENV{ALIEN_BUILD_SITE_CONFIG}\n" if defined $ENV{ALIEN_BUILD_SITE_CONFIG};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"ALIEN_BUILD_SITE_CONFIG"} 0 8 8
23  
24 # on some platforms autofools sorry I mean autotools likes to install into
25 # exec_prefix/lib64 or even worse exec_prefix/lib/64 but that messes everything
26 # else up so we try to nip that in the bud.
27 8 $config_site .= "libdir='\${prefix}/lib'\n";
28 8 $config_site;
29 4 };
30  
31 sub init
32 7 ▶{
Subroutine init: called CC=4 SCAR=15.6
Pod documented
33 7 my($self, $meta) = @_;
34  
35 7 ▶ $meta->apply_plugin('Build::MSYS',
Branch: 1 branch
BranchTrueFalseTotal
defined $self->msys_version ? : 0 7 7
36 (defined $self->msys_version ? (msys_version => $self->msys_version) : ()),
37 );
38  
39 7 $meta->prop->{destdir} = 1;
40 7 $meta->prop->{autoconf} = 1;
41  
42 7 my $intr = $meta->interpolator;
43  
44 2 ▶ my $set_autoconf_prefix = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
45 2 my($build) = @_;
46 2 my $prefix = $build->install_prop->{prefix};
47 2 ▶ die "Prefix is not set. Did you forget to run 'make alien_prefix'?"
Branch: 1 branch
BranchTrueFalseTotal
unless $prefix 0 2 2
48 unless $prefix;
49 2 if(_win)
50 {
51 $prefix = Path::Tiny->new($prefix)->stringify;
52 $prefix =~ s!^([a-z]):!/$1!i if _win;
53 }
54 2 $build->install_prop->{autoconf_prefix} = $prefix;
55 7 };
56  
57 7 $meta->before_hook(
58 build_ffi => $set_autoconf_prefix,
59 );
60  
61 # FFI mode undocumented for now...
62  
63 7 ▶ if($self->ffi)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ffi) 0 7 7
64 {
65 0 $meta->add_requires('configure', 'Alien::Build::Plugin::Build::Autoconf' => '0.41');
66 0 $meta->default_hook(
67 build_ffi => [
68 '%{configure} --enable-shared --disable-static "--libdir=%{.install.autoconf_prefix}/dynamic"',
69 '%{make}',
70 '%{make} install',
71 ]
72 );
73  
74 0 ▶ if($^O eq 'MSWin32')
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
75 {
76 # for whatever reason autohell puts the .dll files in bin, even if you
77 # point --bindir somewhere else.
78 $meta->after_hook(
79 0 ▶ build_ffi => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
80 0 my($build) = @_;
81 0 my $prefix = $build->install_prop->{autoconf_prefix};
82 0 my $bin = Path::Tiny->new($ENV{DESTDIR})->child($prefix)->child('bin');
83 0 my $lib = Path::Tiny->new($ENV{DESTDIR})->child($prefix)->child('dynamic');
84 0 ▶ if(-d $bin)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $bin) 0 0 0
85 {
86 0 foreach my $from (grep { $_->basename =~ /.dll$/i } $bin->children)
87 {
88 0 $lib->mkpath;
89 0 my $to = $lib->child($from->basename);
90 0 $build->log("copy $from => $to");
91 0 $from->copy($to);
92 }
93 }
94 }
95 0 );
96 }
97 }
98  
99 $meta->around_hook(
100 1 ▶ build => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
101 1 my $orig = shift;
102 1 my $build = shift;
103  
104 1 $set_autoconf_prefix->($build);
105 1 my $prefix = $build->install_prop->{autoconf_prefix};
106 1 ▶ die "Prefix is not set. Did you forget to run 'make alien_prefix'?"
Branch: 1 branch
BranchTrueFalseTotal
unless $prefix 0 1 1
107 unless $prefix;
108  
109 1 local $ENV{CONFIG_SITE} = do {
110 1 my $site_config = Path::Tiny->new(File::Temp::tempdir( CLEANUP => 1 ))->child('config.site');
111 1 $site_config->spew($self->config_site);
112 1 "$site_config";
113 };
114  
115 $intr->replace_helper(
116 1 ▶ configure => sub {
Subroutine __ANON__: called CC=3 SCAR=11.3
117 1 my $configure;
118  
119 1 ▶ if($build->meta_prop->{out_of_source})
Branch: 1 branch
BranchTrueFalseTotal
if ($build->meta_prop->{'out_of_source'}) { } 1 0 1
120 {
121 1 my $extract = $build->install_prop->{extract};
122 1 $configure = _win ? qq{sh "$extract/configure"} : "$extract/configure";
123 }
124 else
125 {
126 0 $configure = _win ? 'sh ./configure' : './configure';
127 }
128 1 $configure .= qq{ "--prefix=$prefix"};
129 1 $configure .= ' --disable-dependency-tracking';
130 1 ▶ $configure .= ' --with-pic' if $self->with_pic;
Branch: 1 branch
BranchTrueFalseTotal
if $self->with_pic 0 1 1
131 1 $configure;
132 }
133 1 );
134  
135 1 my $ret = $orig->($build, @_);
136  
137 1 if(_win)
138 {
139 my $real_prefix = Path::Tiny->new($build->install_prop->{prefix});
140 my @pkgconf_dirs;
141 push @pkgconf_dirs, Path::Tiny->new($ENV{DESTDIR})->child($prefix)->child("$_/pkgconfig") for qw(lib share);
142  
143 # for any pkg-config style .pc files that are dropped, we need
144 # to convert the MSYS /C/Foo style paths to C:/Foo
145 for my $pkgconf_dir (@pkgconf_dirs) {
146 if(-d $pkgconf_dir)
147 {
148 foreach my $pc_file ($pkgconf_dir->children)
149 {
150 0 ▶ $pc_file->edit(sub {s/\Q$prefix\E/$real_prefix->stringify/eg;});
Subroutine __ANON__: not called CC=1 SCAR=6.9
151 }
152 }
153 }
154 }
155  
156 1 $ret;
157 },
158 7 );
159  
160  
161 $intr->add_helper(
162 3 ▶ configure => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
163 3 my $configure = _win ? 'sh configure' : './configure';
164 3 ▶ $configure .= ' --with-pic' if $self->with_pic;
Branch: 1 branch
BranchTrueFalseTotal
if $self->with_pic 1 2 3
165 3 $configure;
166 },
167 7 );
168  
169 7 $meta->default_hook(
170 build => [
171 '%{configure} --disable-shared',
172 '%{make}',
173 '%{make} install',
174 ]
175 );
176  
177 7 $self;
178 }
179  
180 4 1;
181  
182 __END__
« blib/lib/Alien/Build/Interpolate.pm ↑ Summary blib/lib/Alien/Build/Plugin/Build/Copy.pm »