Alien-wxWidgets

 view release on metacpan or  search on metacpan

inc/My/Build/Base.pm  view on Meta::CPAN

package My::Build::Base;

use strict;
use base qw(Module::Build);
use My::Build::Utility qw(awx_arch_file awx_touch);
use Alien::wxWidgets::Utility qw(awx_sort_config awx_grep_config);
use File::Path ();
use File::Basename ();
use Fatal qw(open close unlink);
use Data::Dumper;
use File::Glob qw(bsd_glob);
use Carp;
use lib '.';

# Ensure deterministic output
$Data::Dumper::Sortkeys = 1;

# use the system version of a module if present; in theory this could lead to
# compatibility problems (if the latest version of one of the dependencies,
# installed in @INC is incompatible with the bundled version of a module)
sub _load_bundled_modules {
    # the load order is important: all dependencies must be loaded
    # before trying to load a module
    require inc::latest;

    inc::latest->import( $_ )
        foreach qw(version
                   Locale::Maketext::Simple
                   Params::Check
                   Module::Load
                   Module::Load::Conditional
                   IPC::Cmd
                   Archive::Extract
                   File::Fetch);
}

sub ACTION_build {
    my $self = shift;
    # try to make "perl Makefile.PL && make test" work
    # but avoid doubly building wxWidgets when doing
    # "perl Makefile.PL && make && make test"
    unlink 'configured' if -f 'configured';
    $self->SUPER::ACTION_build;
}

sub ACTION_code {
    my $self = shift;

    $self->SUPER::ACTION_code;
    # install_only is set when a wxWidgets build is already configured
    # with Alien::wxWidgets
    return if $self->notes( 'install_only' );
    # see comment in ACTION_build for why 'configured' is used
    return if -f 'configured';
    $self->depends_on( 'build_wx' );
    $self->create_config_file( awx_arch_file( 'Config/Config.pm' ) );
    $self->install_wxwidgets;
    # see comment in ACTION_build for why 'configured' is used
    awx_touch( 'configured' );
    $self->add_to_cleanup( 'configured' );
}

sub ACTION_build_wx {
    my $self = shift;

    if( $self->notes( 'build_wx' ) ) {
        $self->fetch_wxwidgets;
        $self->extract_wxwidgets;
        $self->massage_environment;
        $self->build_wxwidgets;
        $self->massage_environment; # twice on purpose
    }
}

sub ACTION_build_perl {
    my $self = shift;

    $self->SUPER::ACTION_build;
    $self->massage_environment;
    $self->create_config_file( awx_arch_file( 'Config/Config.pm' ) );
}

sub ACTION_install_wx {
    my $self = shift;

    $self->depends_on( 'build_perl' );
    $self->install_wxwidgets;
}

sub ACTION_install {
    my $self = shift;

    $self->SUPER::ACTION_install;
    $self->install_system_wxwidgets;
}

sub _check_data_file {
    my( $self, $file, $manifest ) = @_;

    require File::Spec::Unix;

    my $data = do {
        package main;
        our( $TYPE, $URL );
        local $TYPE = 'dummy';
        local $URL = 'dummy';

        do $file;
    };
    die "Unable to load data file '$file': $@" unless $data;

    foreach my $p ( qw(msw mac unix) ) {
        next unless exists $data->{$p};

        foreach my $c ( qw(unicode ansi) ) {
            next unless exists $data->{$p}{$c};

            foreach my $f ( @{$data->{$p}{$c}} ) {
                my $file = File::Spec->catfile( 'patches', $f );
                my $manifest_file = File::Spec::Unix->catfile( 'patches', $f );

                die 'Missing patch file: ', $file, "\n" unless -f $file;
                die 'Patch file ', $file, ' not in MANIFEST'
                  unless exists $manifest->{$manifest_file};
            }
        }
    }
}

sub _check_data_files {
    my( $self ) = @_;

    require ExtUtils::Manifest;
    my $files = ExtUtils::Manifest::maniread();

    foreach my $data ( grep m{^patches/data}, keys %$files ) {
        print "Checking $data\n";
        $self->_check_data_file( $data, $files );
    }
}

sub ACTION_distcheck {
    my $self = shift;

    $self->SUPER::ACTION_distcheck;
    $self->_check_data_files;
}

sub ACTION_dist {
    my $self = shift;

    $self->_check_data_files;
    $self->SUPER::ACTION_dist;
}

sub awx_key {
    my( $self ) = @_;

    die unless $self->{awx_key};

    return $self->{awx_key};
}

sub _version_2_dec {
    my( $class, $ver ) = @_;
    my $dec;

    $ver =~ m/^(\d)(\d)$/ and
      $dec = $1 + $2 / 1000;
    $ver =~ m/^(\d)(\d)(\d+)$/ and
      $dec = $1 + $2 / 1000 + $3 / 1000000;
    $ver =~ m/^(\d)(\d+)_(\d+)$/ and
      $dec = $1 + $2 / 1000 + $3 / 1000000;
    $ver =~ m/^(\d+)\.(\d+)\.(\d+)$/ and
      $dec = $1 + $2 / 1000 + $3 / 1000000;

    return sprintf( "%.6f", $dec );
}

sub _init_config {
    my( $self ) = @_;
    my %config = $self->awx_configure;
    my $ver = $self->awx_wx_config_data->{version};

    $self->{awx_config} = \%config;

    $config{version} = $self->_version_2_dec( $ver );

    $config{compiler} = $ENV{CXX} || $self->awx_wx_config_data->{cxx};
    $config{linker} = $self->awx_wx_config_data->{ld};
    $config{config}{compiler_kind} = $self->notes( 'compiler_kind' ) ||
        $self->awx_compiler_kind( $config{compiler} );
    $config{config}{compiler_version} = $self->notes( 'compiler_version' ) ||
      $self->awx_compiler_version( $config{compiler} );
    $self->notes( 'compiler_kind' => $config{config}{compiler_kind} );
    $self->notes( 'compiler_version' => $config{config}{compiler_version} );

    my $base = $self->awx_get_name
      ( toolkit          => $config{config}{toolkit},
        version          => $config{version},
        debug            => $self->awx_is_debug,
        unicode          => $self->awx_is_unicode,
        mslu             => $self->awx_is_mslu,
        compiler         => $config{config}{compiler_kind},
        compiler_version => $config{config}{compiler_version},
      );

    $self->{awx_key} = $base;

    $config{wx_base_directory} = $self->awx_wx_config_data->{wxdir}
      if $self->awx_wx_config_data->{wxdir};
    $config{alien_base} = $self->{awx_base} = $base;
    $config{alien_package} = "Alien::wxWidgets::Config::${base}";



( run in 2.306 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )