| 1 | package Alien::Build::Plugin::PkgConfig::CommandLine; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use 5.008004; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Alien::Build::Plugin; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Capture::Tiny qw( capture_merged ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Probe system and determine library or tool properties using the pkg-config command line interface | ||||||||||||||||||||||||||||||||
| 11 | 7 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | has '+pkg_name' => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 15 | 0 | Carp::croak "pkg_name is a required property"; | |||||||||||||||||||||||||||||||
| 16 | 7 | }; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | # NOT used, for compat with other PkgConfig plugins | ||||||||||||||||||||||||||||||||
| 19 | 7 | has register_prereqs => 1; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub _supports_static { | ||||||||||||||||||||||||||||||
|
Subroutine
_supports_static: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 22 | 0 | my($bin) = @_; | |||||||||||||||||||||||||||||||
| 23 | # Some very old pkg-config implementations (e.g. the one still | ||||||||||||||||||||||||||||||||
| 24 | # found on some Solaris installs) predate the --static flag | ||||||||||||||||||||||||||||||||
| 25 | # entirely, and this plugin relies on it to gather the | ||||||||||||||||||||||||||||||||
| 26 | # {libs,cflags}_static properties. | ||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $help = capture_merged { system $bin, '--help' }; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | return $help =~ /--static\b/ ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 22 | ▶ | sub _bin_name { | ||||||||||||||||||||||||||||||
|
Subroutine
_bin_name: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | # We prefer pkgconf to pkg-config because it seems to be the future. | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 22 | require File::Which; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 22 | foreach my $bin ($ENV{PKG_CONFIG}, 'pkgconf', 'pkg-config') | |||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||
| 39 | 63 | ▶ | next unless $bin; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | 42 | ▶ | next unless File::Which::which($bin); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 5 | ▶ | next unless _supports_static($bin); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 5 | return $bin; | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 17 | undef; | |||||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 7 | has bin_name => \&_bin_name; | |||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 7 | has atleast_version => undef; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 7 | has exact_version => undef; | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 7 | has max_version => undef; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 7 | has minimum_version => undef; | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | sub _val | ||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_val: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 64 | 0 | my($build, $args, $prop_name) = @_; | |||||||||||||||||||||||||||||||
| 65 | 0 | my $string = $args->{out}; | |||||||||||||||||||||||||||||||
| 66 | 0 | chomp $string; | |||||||||||||||||||||||||||||||
| 67 | 0 | $string =~ s{^\s+}{}; | |||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if($prop_name =~ /version$/) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | 0 | { $string =~ s{\s*$}{} } | |||||||||||||||||||||||||||||||
| 70 | else | ||||||||||||||||||||||||||||||||
| 71 | 0 | { $string =~ s{\s*$}{ } } | |||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if($prop_name =~ /^(.*?)\.(.*?)\.(.*?)$/) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 0 | { $build->runtime_prop->{$1}->{$2}->{$3} = $string } | |||||||||||||||||||||||||||||||
| 74 | else | ||||||||||||||||||||||||||||||||
| 75 | 0 | { $build->runtime_prop->{$prop_name} = $string } | |||||||||||||||||||||||||||||||
| 76 | 0 | (); | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | sub available | ||||||||||||||||||||||||||||||||
| 81 | 19 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
available: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 82 | 19 | !!_bin_name(); | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | sub init | ||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=17 SCAR=42.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 87 | 2 | my($self, $meta) = @_; | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 2 | my @probe; | |||||||||||||||||||||||||||||||
| 90 | my @gather; | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 2 | my $pkgconf = $self->bin_name; | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | unless(defined $meta->prop->{env}->{PKG_CONFIG}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||
| 96 | 2 | $meta->prop->{env}->{PKG_CONFIG} = $pkgconf; | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my($pkg_name, @alt_names) = (ref $self->pkg_name) ? (@{ $self->pkg_name }) : ($self->pkg_name); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 2 | push @probe, map { [$pkgconf, '--exists', $_] } ($pkg_name, @alt_names); | |||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | if(defined $self->minimum_version) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||
| 105 | 1 | push @probe, [ $pkgconf, '--atleast-version=' . $self->minimum_version, $pkg_name ]; | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | elsif(defined $self->atleast_version) | ||||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||
| 109 | 0 | push @probe, [ $pkgconf, '--atleast-version=' . $self->atleast_version, $pkg_name ]; | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | if(defined $self->exact_version) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||
| 114 | 0 | push @probe, [ $pkgconf, '--exact-version=' . $self->exact_version, $pkg_name ]; | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | if(defined $self->max_version) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||||
| 119 | 0 | push @probe, [ $pkgconf, '--max-version=' . $self->max_version, $pkg_name ]; | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | push @probe, [ $pkgconf, '--modversion', $pkg_name, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 123 | 0 | my($build, $args) = @_; | |||||||||||||||||||||||||||||||
| 124 | 0 | my $version = $args->{out}; | |||||||||||||||||||||||||||||||
| 125 | 0 | $version =~ s{^\s+}{}; | |||||||||||||||||||||||||||||||
| 126 | 0 | $version =~ s{\s*$}{}; | |||||||||||||||||||||||||||||||
| 127 | 0 | $build->hook_prop->{version} = $version; | |||||||||||||||||||||||||||||||
| 128 | 2 | }]; | |||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | unshift @probe, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 131 | 0 | my($build) = @_; | |||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $build->runtime_prop->{legacy}->{name} ||= $pkg_name; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$build->runtime_prop->{"legacy"}{"name"} ||= $pkg_name
MC/DC0%0/2
$build->runtime_prop->{"legacy"}{"name"} ||= $pkg_name
$build->runtime_prop->{"legacy"}{"name"}
$pkg_name
Truth table0%0/3
A ||= B
A= $build->runtime_prop->{"legacy"}{"name"}B= $pkg_name
| |||||||||||||||||||||||||||||||||
| 133 | 0 | $build->hook_prop->{probe_class} = __PACKAGE__; | |||||||||||||||||||||||||||||||
| 134 | 0 | $build->hook_prop->{probe_instance_id} = $self->instance_id; | |||||||||||||||||||||||||||||||
| 135 | 2 | }; | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 2 | $meta->register_hook( | |||||||||||||||||||||||||||||||
| 138 | probe => \@probe | ||||||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | push @gather, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 142 | 0 | my($build) = @_; | |||||||||||||||||||||||||||||||
| 143 | die 'pkg-config command line probe does not match gather' if $build->hook_prop->{name} eq 'gather_system' | ||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | && ($build->install_prop->{system_probe_instance_id} || '') ne $self->instance_id; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$build->hook_prop->{"name"} eq "gather_system" and ($build->install_prop->{"system_probe_instance_id"} || "") ne $self->instance_id
$build->install_prop->{'system_probe_instance_id'} || ''
MC/DC0%0/2
$build->hook_prop->{"name"} eq "gather_system" and ($build->install_prop->{"system_probe_instance_id"} || "") ne $self->instance_id
$build->hook_prop->{"name"} eq "gather_system"
$build->install_prop->{'system_probe_instance_id'}
Truth table0%0/3
A and B
A= $build->hook_prop->{"name"} eq "gather_system"B= $build->install_prop->{'system_probe_instance_id'}
| |||||||||||||||||||||||||||||||||
| 145 | 2 | }; | |||||||||||||||||||||||||||||||
| 146 | 2 | push @gather, map { [ $pkgconf, '--exists', $_] } ($pkg_name, @alt_names); | |||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 2 | foreach my $prop_name (qw( cflags libs version )) | |||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||
| 150 | 6 | ▶ | my $flag = $prop_name eq 'version' ? '--modversion' : "--$prop_name"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | push @gather, | ||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | [ $pkgconf, $flag, $pkg_name, sub { _val @_, $prop_name } ]; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||
| 153 | 6 | ▶ | if(@alt_names) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||||||
| 155 | 0 | foreach my $alt ($pkg_name, @alt_names) | |||||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||||||
| 157 | push @gather, | ||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | [ $pkgconf, $flag, $alt, sub { _val @_, "alt.$alt.$prop_name" } ]; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | 2 | foreach my $prop_name (qw( cflags libs )) | |||||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||||||
| 165 | push @gather, | ||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | [ $pkgconf, '--static', "--$prop_name", $pkg_name, sub { _val @_, "${prop_name}_static" } ]; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||
| 167 | 4 | ▶ | if(@alt_names) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||||
| 169 | 0 | foreach my $alt ($pkg_name, @alt_names) | |||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||
| 171 | push @gather, | ||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | [ $pkgconf, '--static', "--$prop_name", $alt, sub { _val @_, "alt.$alt.${prop_name}_static" } ]; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | 2 | $meta->register_hook(gather_system => [@gather]); | |||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | 2 | ▶ | if($meta->prop->{platform}->{system_type} eq 'windows-mingw') | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 180 | { | ||||||||||||||||||||||||||||||||
| 181 | @gather = map { | ||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if(ref $_ eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 183 | 0 | my($pkgconf, @rest) = @$_; | |||||||||||||||||||||||||||||||
| 184 | 0 | [$pkgconf, '--dont-define-prefix', @rest], | |||||||||||||||||||||||||||||||
| 185 | } else { | ||||||||||||||||||||||||||||||||
| 186 | 0 | $_ | |||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||
| 188 | } @gather; | ||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 2 | $meta->register_hook(gather_share => [@gather]); | |||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | $meta->after_hook( | ||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | $_ => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 195 | 0 | my($build) = @_; | |||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if(keys %{ $build->runtime_prop->{alt} } < 2) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||
| 198 | 0 | delete $build->runtime_prop->{alt}; | |||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||
| 200 | }, | ||||||||||||||||||||||||||||||||
| 201 | 2 | ) for qw( gather_system gather_share ); | |||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 2 | $self; | |||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 7 | 1; | |||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | __END__ | ||||||||||||||||||||||||||||||||