Skip to content

Commit

Permalink
Put Inline::CPP::Config replacement in share.
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Dec 21, 2014
1 parent 03c3d3d commit c02d961
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 3 deletions.
1 change: 1 addition & 0 deletions Meta
Expand Up @@ -17,6 +17,7 @@ author:

requires:
perl: 5.8.1
File::Share: 0
Inline: 0
Inline::C: 0

Expand Down
53 changes: 50 additions & 3 deletions lib/Inline/Module.pm
Expand Up @@ -3,10 +3,11 @@ package Inline::Module;
our $VERSION = '0.26';
our $API_VERSION = 'v2';

use Carp 'croak';
use Config();
use File::Path();
use File::Find();
use Carp 'croak';
use File::Path();
use File::Spec();

my $inline_build_path = './blib/Inline';

Expand Down Expand Up @@ -307,7 +308,9 @@ sub add_to_distdir {
push @$manifest, "inc/$module.pm";
}
for my $module (@$included_modules) {
my $code = $class->read_local_module($module);
my $code = $module eq 'Inline::CPP::Config'
? $class->read_share_cpp_config
: $class->read_local_module($module);
$class->write_module("$distdir/inc", $module, $code);
$module =~ s!::!/!g;
push @$manifest, "inc/$module.pm";
Expand All @@ -331,6 +334,18 @@ sub read_local_module {
return $code;
}

sub read_share_cpp_config {
my ($class) = @_;
require File::Share;
my $dir = File::Share::dist_dir('Inline-Module');
my $path = File::Spec->catfile($dir, 'CPPConfig.pm');
open IN, '<', $path
or die "Can't open '$path' for input:\n$!";
my $code = do {local $/; <IN>};
close IN;
return $code;
}

sub proxy_module {
my ($class, $module) = @_;

Expand Down Expand Up @@ -407,4 +422,36 @@ sub add_to_manifest {
}
}

sub smoke_system_info_dump {
my ($class, @msg) = @_;
my $msg = sprintf(@msg);
chomp $msg;
require Data::Dumper;
local $Data::Dumper::Sortkeys = 1;
local $Data::Dumper::Terse = 1;
local $Data::Dumper::Indent = 1;

my @path_files;
File::Find::find({
wanted => sub {
push @path_files, $File::Find::name if -f;
},
}, File::Spec->path());
my $dump = Data::Dumper::Dumper(
{
'ENV' => \%ENV,
'Config' => \%Config::Config,
'Path Files' => \@path_files,
},
);
Carp::confess <<"..."
Error: $msg
System Data:
$dump
Error: $msg
...
}

1;
51 changes: 51 additions & 0 deletions share/CPPConfig.pm
@@ -0,0 +1,51 @@
# This module comes from Inline::Module share file: 'CPPConfig.pm'

use strict; use warnings;
package Inline::CPP::Config;

use Config;
# use ExtUtils::CppGuess;

our ($compiler, $libs, $iostream_fn, $cpp_flavor_defs) = cpp_guess();

my $cpp_info;
BEGIN {
my $default_headers = <<'.';
#define __INLINE_CPP_STANDARD_HEADERS 1
#define __INLINE_CPP_NAMESPACE_STD 1
.
my @default_info = (
'g++ -xc++',
'-lstdc++',
'iostream',
$default_headers,
);
$cpp_info = {
'cygwin' => [ @default_info ],
'darwin' => [ @default_info ],
'linux' => [ @default_info ],
'MSWin32' => [ @default_info ],
};
}

sub throw;
sub cpp_guess {
my $key = $Config::Config{osname};
if (my $config = $cpp_info->{$key}) {
$config->[0] .= ' -D_FILE_OFFSET_BITS=64',
if $Config::Config{ccflags} =~ /-D_FILE_OFFSET_BITS=64/;
return @$config;
}

throw "Unsupported OS/Compiler for Inline::Module+Inline::CPP '$key'";
}

sub throw {
die "@_" unless
$ENV{PERL5_MINISMOKEBOX} ||
$ENV{PERL_CR_SMOKER_CURRENT};
eval 'use lib "inc"; use Inline::Module; 1' or die $@;
Inline::Module->smoke_system_info_dump();
}

1;

0 comments on commit c02d961

Please sign in to comment.