Alien-Build
view release on metacpan or search on metacpan
lib/Alien/Build/Plugin/Core/Setup.pm view on Meta::CPAN
package Alien::Build::Plugin::Core::Setup;
use strict;
use warnings;
use 5.008004;
use Alien::Build::Plugin;
use Config;
use File::Which qw( which );
# ABSTRACT: Core setup plugin
our $VERSION = '2.84'; # VERSION
sub init
{
my($self, $meta) = @_;
$meta->prop->{platform} ||= {};
$self->_platform($meta->prop->{platform});
}
sub _platform
{
my(undef, $hash) = @_;
if($^O eq 'MSWin32' && $Config{ccname} eq 'cl')
{
$hash->{compiler_type} = 'microsoft';
}
else
{
$hash->{compiler_type} = 'unix';
}
if($^O eq 'MSWin32')
{
$hash->{system_type} = 'windows-unknown';
if(defined &Win32::BuildNumber)
{
$hash->{system_type} = 'windows-activestate';
}
elsif($Config{myuname} =~ /strawberry-perl/)
{
$hash->{system_type} = 'windows-strawberry';
}
elsif($hash->{compiler_type} eq 'microsoft')
{
$hash->{system_type} = 'windows-microsoft';
}
else
{
my $uname_exe = which('uname');
if($uname_exe)
{
my $uname = `$uname_exe`;
if($uname =~ /^(MINGW)(32|64)_NT/)
{
$hash->{system_type} = 'windows-' . lc $1;
}
}
}
}
elsif($^O =~ /^(VMS)$/)
{
# others probably belong in here...
$hash->{system_type} = lc $^O;
}
else
{
$hash->{system_type} = 'unix';
}
$hash->{cpu}{count} =
exists $ENV{ALIEN_CPU_COUNT} && $ENV{ALIEN_CPU_COUNT} > 0
? $ENV{ALIEN_CPU_COUNT}
: _cpu_count();
$hash->{cpu}{arch} = _cpu_arch(\%Config);
}
# Retrieve number of available CPU cores. Adopted from
# <https://metacpan.org/release/MARIOROY/MCE-1.879/source/lib/MCE/Util.pm#L49>
# which is in turn adopted from Test::Smoke::Util with improvements.
sub _cpu_count {
local $ENV{PATH} = $ENV{PATH};
if( $^O ne 'MSWin32' ) {
$ENV{PATH} = "/usr/sbin:/sbin:/usr/bin:/bin:$ENV{PATH}";
}
$ENV{PATH} =~ /(.*)/; $ENV{PATH} = $1; ## Remove tainted'ness
my $ncpu = 1;
OS_CHECK: {
local $_ = lc $^O;
/linux/ && do {
my ( $count, $fh );
if ( open $fh, '<', '/proc/stat' ) {
$count = grep { /^cpu\d/ } <$fh>;
close $fh;
}
$ncpu = $count if $count;
last OS_CHECK;
};
/bsd|darwin|dragonfly/ && do {
chomp( my @output = `sysctl -n hw.ncpu 2>/dev/null` );
$ncpu = $output[0] if @output;
last OS_CHECK;
};
/aix/ && do {
my @output = `lparstat -i 2>/dev/null | grep "^Online Virtual CPUs"`;
if ( @output ) {
$output[0] =~ /(\d+)\n$/;
$ncpu = $1 if $1;
}
if ( !$ncpu ) {
@output = `pmcycles -m 2>/dev/null`;
if ( @output ) {
$ncpu = scalar @output;
} else {
@output = `lsdev -Cc processor -S Available 2>/dev/null`;
$ncpu = scalar @output if @output;
}
}
last OS_CHECK;
};
/gnu/ && do {
( run in 1.352 second using v1.01-cache-2.11-cpan-df04353d9ac )