| 1 | package Alien::Build::Plugin::PkgConfig::PP; | ||||||||||||||||||||||||||||||||
| 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 Carp (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use File::Which (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Env qw( @PKG_CONFIG_PATH ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | # ABSTRACT: Probe system and determine library or tool properties using PkgConfig.pm | ||||||||||||||||||||||||||||||||
| 12 | 7 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | has '+pkg_name' => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 16 | 0 | Carp::croak "pkg_name is a required property"; | |||||||||||||||||||||||||||||||
| 17 | 7 | }; | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 7 | has atleast_version => undef; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 7 | has exact_version => undef; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 7 | has max_version => undef; | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 7 | has minimum_version => undef; | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 7 | ▶ | use constant _min_version => '0.14026'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | # private for now, used by negotiator | ||||||||||||||||||||||||||||||||
| 35 | 7 | has register_prereqs => 1; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | sub available | ||||||||||||||||||||||||||||||||
| 38 | 18 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
available: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 39 | 18 | !!eval { require PkgConfig; PkgConfig->VERSION(_min_version) }; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | sub _cleanup | ||||||||||||||||||||||||||||||||
| 43 | 16 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_cleanup: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 44 | 16 | my($value) = @_; | |||||||||||||||||||||||||||||||
| 45 | 16 | $value =~ s{\s*$}{ }; | |||||||||||||||||||||||||||||||
| 46 | 16 | $value; | |||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | sub init | ||||||||||||||||||||||||||||||||
| 50 | 28 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 51 | 28 | my($self, $meta) = @_; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 28 | ▶ | unless(defined $meta->prop->{env}->{PKG_CONFIG}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||||||
| 55 | # TODO: Better would be to to "execute" lib/PkgConfig.pm | ||||||||||||||||||||||||||||||||
| 56 | # as that should always be available, and will match the | ||||||||||||||||||||||||||||||||
| 57 | # exact version of PkgConfig.pm that we are using here. | ||||||||||||||||||||||||||||||||
| 58 | # there are a few corner cases to deal with before we | ||||||||||||||||||||||||||||||||
| 59 | # can do this. What is here should handle most use cases. | ||||||||||||||||||||||||||||||||
| 60 | 28 | ▶ | my $command_line = | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 61 | File::Which::which('ppkg-config') | ||||||||||||||||||||||||||||||||
| 62 | ? 'ppkg-config' | ||||||||||||||||||||||||||||||||
| 63 | : File::Which::which('pkg-config.pl') | ||||||||||||||||||||||||||||||||
| 64 | ? 'pkg-config.pl' | ||||||||||||||||||||||||||||||||
| 65 | : File::Which::which('pkg-config') | ||||||||||||||||||||||||||||||||
| 66 | ? 'pkg-config' | ||||||||||||||||||||||||||||||||
| 67 | : undef; | ||||||||||||||||||||||||||||||||
| 68 | 28 | ▶ | $meta->prop->{env}->{PKG_CONFIG} = $command_line | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | if defined $command_line; | ||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 28 | ▶ | if($self->register_prereqs) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||
| 74 | 21 | $meta->add_requires('configure' => 'PkgConfig' => _min_version); | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 28 | ▶ | my($pkg_name, @alt_names) = (ref $self->pkg_name) ? (@{ $self->pkg_name }) : ($self->pkg_name); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | $meta->register_hook( | ||||||||||||||||||||||||||||||||
| 80 | 20 | ▶ | probe => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||
| 81 | 20 | my($build) = @_; | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 20 | ▶ | $build->runtime_prop->{legacy}->{name} ||= $pkg_name; | ||||||||||||||||||||||||||||||
|
Condition33%1/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 table33%1/3
A ||= B
A= $build->runtime_prop->{"legacy"}{"name"}B= $pkg_name
| |||||||||||||||||||||||||||||||||
| 84 | 20 | $build->hook_prop->{probe_class} = __PACKAGE__; | |||||||||||||||||||||||||||||||
| 85 | 20 | $build->hook_prop->{probe_instance_id} = $self->instance_id; | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 20 | require PkgConfig; | |||||||||||||||||||||||||||||||
| 88 | 20 | my $pkg = PkgConfig->find($pkg_name); | |||||||||||||||||||||||||||||||
| 89 | 20 | ▶ | die "package @{[ $pkg_name ]} not found" if $pkg->errmsg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 17 | $build->hook_prop->{version} = $pkg->pkg_version; | |||||||||||||||||||||||||||||||
| 92 | 17 | my $version = PkgConfig::Version->new($pkg->pkg_version); | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 17 | my $atleast_version = $self->atleast_version; | |||||||||||||||||||||||||||||||
| 95 | 17 | ▶ | $atleast_version = $self->minimum_version unless defined $atleast_version; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 17 | ▶ | if(defined $atleast_version) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||
| 98 | 7 | my $need = PkgConfig::Version->new($atleast_version); | |||||||||||||||||||||||||||||||
| 99 | 7 | ▶ | if($version < $need) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||||||
| 101 | 2 | die "package @{[ $pkg_name ]} is @{[ $pkg->pkg_version ]}, but at least $atleast_version is required."; | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 15 | ▶ | if(defined $self->exact_version) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||
| 107 | 4 | my $need = PkgConfig::Version->new($self->exact_version); | |||||||||||||||||||||||||||||||
| 108 | 4 | ▶ | if($version != $need) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||
| 110 | 3 | die "package @{[ $pkg_name ]} is @{[ $pkg->pkg_version ]}, but exactly @{[ $self->exact_version ]} is required."; | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 12 | ▶ | if(defined $self->max_version) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||
| 116 | 5 | my $need = PkgConfig::Version->new($self->max_version); | |||||||||||||||||||||||||||||||
| 117 | 5 | ▶ | if($version > $need) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||||
| 119 | 2 | die "package @{[ $pkg_name ]} is @{[ $pkg->pkg_version ]}, but max of @{[ $self->max_version ]} is required."; | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 10 | foreach my $alt (@alt_names) | |||||||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||||||
| 125 | 1 | my $pkg = PkgConfig->find($alt); | |||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | die "package $alt not found" if $pkg->errmsg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 10 | 'system'; | |||||||||||||||||||||||||||||||
| 130 | }, | ||||||||||||||||||||||||||||||||
| 131 | 28 | ); | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | $meta->register_hook( | ||||||||||||||||||||||||||||||||
| 134 | 4 | ▶ | $_ => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.9
| |||||||||||||||||||||||||||||||||
| 135 | 4 | my($build) = @_; | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | return if $build->hook_prop->{name} eq 'gather_system' | ||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | && ($build->install_prop->{system_probe_instance_id} || '') ne $self->instance_id; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/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/DC100%2/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 table100%3/3
A and B
A= $build->hook_prop->{"name"} eq "gather_system"B= $build->install_prop->{'system_probe_instance_id'}
| |||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 3 | require PkgConfig; | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 3 | foreach my $name ($pkg_name, @alt_names) | |||||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||||||
| 144 | 4 | require PkgConfig; | |||||||||||||||||||||||||||||||
| 145 | 4 | my $pkg = PkgConfig->find($name, search_path => [@PKG_CONFIG_PATH]); | |||||||||||||||||||||||||||||||
| 146 | 4 | ▶ | if($pkg->errmsg) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||
| 148 | 0 | $build->log("Trying to load the pkg-config information from the source code build"); | |||||||||||||||||||||||||||||||
| 149 | 0 | $build->log("of your package failed"); | |||||||||||||||||||||||||||||||
| 150 | 0 | $build->log("You are currently using the pure-perl implementation of pkg-config"); | |||||||||||||||||||||||||||||||
| 151 | 0 | $build->log("(AB Plugin is named PkgConfig::PP, which uses PkgConfig.pm"); | |||||||||||||||||||||||||||||||
| 152 | 0 | $build->log("It may work better with the real pkg-config."); | |||||||||||||||||||||||||||||||
| 153 | 0 | $build->log("Try installing your OS' version of pkg-config or unset ALIEN_BUILD_PKG_CONFIG"); | |||||||||||||||||||||||||||||||
| 154 | 0 | die "second load of PkgConfig.pm @{[ $name ]} failed: @{[ $pkg->errmsg ]}" | |||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | 4 | my %prop; | |||||||||||||||||||||||||||||||
| 157 | 4 | $prop{cflags} = _cleanup scalar $pkg->get_cflags; | |||||||||||||||||||||||||||||||
| 158 | 4 | $prop{libs} = _cleanup scalar $pkg->get_ldflags; | |||||||||||||||||||||||||||||||
| 159 | 4 | $prop{version} = $pkg->pkg_version; | |||||||||||||||||||||||||||||||
| 160 | 4 | $pkg = PkgConfig->find($name, static => 1, search_path => [@PKG_CONFIG_PATH]); | |||||||||||||||||||||||||||||||
| 161 | 4 | $prop{cflags_static} = _cleanup scalar $pkg->get_cflags; | |||||||||||||||||||||||||||||||
| 162 | 4 | $prop{libs_static} = _cleanup scalar $pkg->get_ldflags; | |||||||||||||||||||||||||||||||
| 163 | 4 | $build->runtime_prop->{alt}->{$name} = \%prop; | |||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | 3 | foreach my $key (keys %{ $build->runtime_prop->{alt}->{$pkg_name} }) | |||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||
| 167 | 15 | $build->runtime_prop->{$key} = $build->runtime_prop->{alt}->{$pkg_name}->{$key}; | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | if(keys %{ $build->runtime_prop->{alt} } == 1) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||
| 171 | 2 | delete $build->runtime_prop->{alt}; | |||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||
| 174 | 28 | ) for qw( gather_system gather_share ); | |||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | 28 | $self; | |||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | 7 | 1; | |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | __END__ | ||||||||||||||||||||||||||||||||