Changeset 2208


Ignore:
Timestamp:
12/28/08 01:17:23 (3 years ago)
Author:
adamk
Message:

Major refactoring of Makefile.PL.

Now uses all kinds of neat trickery to stop EU:MM trying to load modules, and to prevent the need to load Wx at all when looking for the wxWidgets version.

Might resolve all issues relating to Makefile.PL

Location:
trunk/Padre
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/Makefile.PL

    r2198 r2208  
     1# NOTE: inc::Module::Install::PRIVATE::Padre needs Perl 5.8, so make sure 
     2# that we force the Perl version check (and fail) early. 
     3# Unicode is also considered to finally be "stable" at 5.8.5, so we will 
     4# set our dependency on that. 
     5use 5.008005; 
    16use strict; 
    27use lib 'privinc'; 
    3 use inc::Module::Install; 
    4  
    5 # workaround for the fact that Module::Install loads the modules 
    6 # into memory and when Test::NoWarnings is loaded it will hide 
    7 # the warnings generated from that point. 
    8 eval  { 
    9     require Test::NoWarnings; 
    10     $SIG{__WARN__} = 'DEFAULT'; 
    11 }; 
     8use inc::Module::Install 0.77; 
    129 
    1310 
    14 use Config; 
    15 unless ( $Config{usethreads} ) { 
    16     warn "Padre requires a perl built using threads\n"; 
    17     exit 0; 
    18 } 
    1911 
    20 # Fedora and other rpm based build systems remove the DISPLAY by default 
    21 # which blows up when checking the Wx version. So we disable it. 
    22 # See  #170 
    23 if (win32 or $ENV{DISPLAY}) { 
    24     check_wx_version; 
    25 } 
     12 
     13 
     14##################################################################### 
     15# Normal Boring Commands 
     16 
     17# NOTE: Core modules that aren't dual-life should always have a version of 0 
    2618 
    2719name           'Padre'; 
     
    2921author         'Gabor Szabo'; 
    3022all_from       'lib/Padre.pm'; 
    31 requires       'perl'                    => '5.008001'; 
    32 requires       'Carp'                    => 0; 
    33 requires       'Class::Adapter'          => '1.05'; 
    34 requires       'Class::XSAccessor'       => '0.14'; 
    35 requires       'Cwd'                     => '3.2701'; 
    36 requires       'Data::Dumper'            => 0; 
    37 requires       'Digest::MD5'             => 0; 
    38 requires       'Encode'                  => '2.26'; 
    39 requires       'File::Spec'              => '3.2701'; 
    40 requires       'File::Spec::Functions'   => '3.2701'; 
    41 requires       'File::Basename'          => 0; 
    42 requires       'FindBin'                 => 0; 
    43 requires       'Getopt::Long'            => 0; 
    44 requires       'HTML::Parser'            => '3.58'; 
    45 requires       'HTML::Entities'          => '3.57'; 
    46 requires       'List::Util'              => '1.18'; 
    47 requires       'IO::Socket'              => '1.30'; 
    48 requires       'IPC::Cmd'                => '0.42'; # Requires IPC::Run on Win32 
    49 requires       'IPC::Run'                => '0.82' if win32; 
    50 requires       'IPC::Open3'              => '0'; # not dual-lived! 
    51 requires       'Term::ReadLine'          => 0; 
    52 requires       'Module::Refresh'         => '0.13'; 
    53 requires       'App::Ack'                => '1.86'; 
    54 requires       'Class::Autouse'          => '1.26'; 
    55 requires       'Class::Unload'           => '0.03'; 
    56 requires       'DBD::SQLite'             => '1.10'; 
    57 requires       'DBI'                     => '1.58'; 
    58 requires       'File::Copy::Recursive'   => '0.37'; 
    59 requires       'File::Find::Rule'        => '0.30'; 
    60 requires       'File::HomeDir'           => '0.82'; 
    61 requires       'File::ShareDir'          => '1.00'; 
    62 requires       'File::ShareDir::PAR'     => '0.03'; 
    63 requires       'File::Which'             => '0.05'; 
    64 requires       'IO::String'              => '1.08'; 
    65 requires       'Module::Inspector'       => '0.04'; 
    66 requires       'Module::Starter'         => '1.50'; 
    67 requires       'ORLite'                  => '0.15'; 
    68 requires       'ORLite::Migrate'         => '0.01'; 
    69 requires       'Params::Util'            => '0.33'; 
    70 requires       'PAR'                     => '0.970'; 
    71 requires       'Pod::POM'                => '0.17'; 
    72 requires       'Pod::Simple'             => '3.07'; 
    73 requires       'Pod::Simple::XHTML'      => '3.04'; 
    74 requires       'Probe::Perl'             => '0.01'; 
    75 requires       'PPI'                     => '1.203'; 
    76 requires       'Storable'                => '2.15'; 
    77 requires       'Text::Diff'              => '0.35'; 
    78 requires       'Text::FindIndent'        => '0.03'; 
    79 requires       'threads'                 => '1.71'; 
    80 requires       'threads::shared'         => '1.26'; 
    81 requires       'Thread::Queue'           => '2.11'; 
    82 requires       'YAML::Tiny'              => '1.32'; 
    83  
    84 # See #170 
    85 if (win32 or $ENV{DISPLAY}) { 
    86     requires       'Wx'                      => '0.89'; 
    87     requires       'Wx::Perl::Dialog'        => '0.04'; 
    88     requires       'Wx::Perl::ProcessStream' => '0.11'; 
    89 } 
    90  
    91 requires       'Parse::ErrorString::Perl'=> '0.08'; 
    92 test_requires  'Test::Compile'           => '0.08' unless win32; 
    93 test_requires  'Test::More'              => '0.47'; 
    94 test_requires  'Test::Script'            => '1.03'; 
    95 test_requires  'Test::Exception'         => '0.27'; 
    96 test_requires  'Test::NoWarnings'        => '0.084'; 
    97 test_requires  'Test::NeedsDisplay'      => '1.05'; 
    98 no_index       'directory'               => qw{ t xt eg share inc privinc}; 
     23requires       'perl'                     => '5.008001'; 
     24requires       'Carp'                     => 0; 
     25requires       'Class::Adapter'           => '1.05'; 
     26requires       'Class::XSAccessor'        => '0.14'; 
     27requires       'Cwd'                      => '3.2701'; 
     28requires       'Data::Dumper'             => 0; 
     29requires       'Digest::MD5'              => 0; 
     30requires       'Encode'                   => '2.26'; 
     31requires       'File::Spec'               => '3.2701'; 
     32requires       'File::Spec::Functions'    => '3.2701'; 
     33requires       'File::Basename'           => 0; 
     34requires       'FindBin'                  => 0; 
     35requires       'Getopt::Long'             => 0; 
     36requires       'HTML::Parser'             => '3.58'; 
     37requires       'HTML::Entities'           => '3.57'; 
     38requires       'List::Util'               => '1.18'; 
     39requires       'IO::Socket'               => '1.30'; 
     40requires       'IPC::Cmd'                 => '0.42'; 
     41requires       'IPC::Run'                 => '0.82' if win32; 
     42requires       'IPC::Open3'               => 0; 
     43requires       'Term::ReadLine'           => 0; 
     44requires       'Module::Refresh'          => '0.13'; 
     45requires       'App::Ack'                 => '1.86'; 
     46requires       'Class::Autouse'           => '1.26'; 
     47requires       'Class::Unload'            => '0.03'; 
     48requires       'DBD::SQLite'              => '1.10'; 
     49requires       'DBI'                      => '1.58'; 
     50requires       'File::Copy::Recursive'    => '0.37'; 
     51requires       'File::Find::Rule'         => '0.30'; 
     52requires       'File::HomeDir'            => '0.82'; 
     53requires       'File::ShareDir'           => '1.00'; 
     54requires       'File::ShareDir::PAR'      => '0.03'; 
     55requires       'File::Which'              => '0.05'; 
     56requires       'IO::String'               => '1.08'; 
     57requires       'Module::Inspector'        => '0.04'; 
     58requires       'Module::Starter'          => '1.50'; 
     59requires       'ORLite'                   => '0.15'; 
     60requires       'ORLite::Migrate'          => '0.01'; 
     61requires       'Params::Util'             => '0.33'; 
     62requires       'PAR'                      => '0.970'; 
     63requires       'Pod::POM'                 => '0.17'; 
     64requires       'Pod::Simple'              => '3.07'; 
     65requires       'Pod::Simple::XHTML'       => '3.04'; 
     66requires       'Probe::Perl'              => '0.01'; 
     67requires       'PPI'                      => '1.203'; 
     68requires       'Storable'                 => '2.15'; 
     69requires       'Text::Diff'               => '0.35'; 
     70requires       'Text::FindIndent'         => '0.03'; 
     71requires       'threads'                  => '1.71'; 
     72requires       'threads::shared'          => '1.26'; 
     73requires       'Thread::Queue'            => '2.11'; 
     74requires       'YAML::Tiny'               => '1.32'; 
     75requires       'Wx'                       => '0.89'; 
     76requires       'Wx::Perl::Dialog'         => '0.04'; 
     77requires       'Wx::Perl::ProcessStream'  => '0.11'; 
     78requires       'Parse::ErrorString::Perl' => '0.08'; 
     79test_requires  'Test::Compile'            => '0.08' unless win32; 
     80test_requires  'Test::More'               => '0.47'; 
     81test_requires  'Test::Script'             => '1.03'; 
     82test_requires  'Test::Exception'          => '0.27'; 
     83test_requires  'Test::NoWarnings'         => '0.084'; 
     84test_requires  'Test::NeedsDisplay'       => '1.05'; 
     85no_index       'directory'                => qw{ t xt eg share inc privinc }; 
    9986homepage       'http://padre.perlide.org/'; 
    10087bugtracker     'http://padre.perlide.org/'; 
    10188repository     'http://svn.perlide.org/padre/trunk/Padre/'; 
     89# MailingList  'http://mail.perlide.org/mailman/listinfo/padre-dev'; 
    10290install_script 'script/padre'; 
    10391install_share; 
    10492 
    105 #MailingList => 'http://mail.perlide.org/mailman/listinfo/padre-dev', 
    10693 
     94 
     95 
     96 
     97##################################################################### 
     98# Padre-Specific Oddities 
     99 
     100# Padre requires threads 
     101use Config; 
     102unless ( $Config{usethreads} ) { 
     103    warn("Padre requires a perl built using threads\n"); 
     104    exit(0); 
     105} 
     106 
     107# The check_wx_version command SHOULD (hopefully) now be able to verify the 
     108# wxWidgets version WITHOUT having to have DISPLAY. 
     109check_wx_version; 
     110 
     111# Add the make exe target 
    107112setup_padre; 
    108113 
     114# EU:MM incorrectly attempts to load all the dependencies. 
     115# To prevent this happening we populate the %INC hash and create 
     116# a VERSION method for each module, so that we can prevent loading 
     117# any modules while convincing EU:MM that we have the right version. 
     118# This has to be called immediately before calling WriteAll. 
     119trick_eumm; 
     120 
    109121WriteAll; 
  • trunk/Padre/privinc/Module/Install/PRIVATE/Padre.pm

    r1848 r2208  
    11package Module::Install::PRIVATE::Padre; 
     2 
     3use 5.008; 
    24use strict; 
    35use warnings; 
    46use Module::Install::Base; 
    57 
    6 use FindBin (); 
    7 use File::Spec; 
     8use FindBin    (); 
    89use File::Find (); 
    910 
    10 our @ISA = qw(Module::Install::Base); 
    1111our $VERSION = '0.20'; 
     12our @ISA     = qw{Module::Install::Base}; 
    1213 
    1314sub setup_padre { 
    14     my $self = shift; 
    15     my $inc_class = join('::', @{$self->_top}{qw(prefix name)}); 
    16     my $class = __PACKAGE__; 
     15    my $self      = shift; 
     16    my $inc_class = join( '::', @{ $self->_top }{ qw(prefix name) } ); 
     17    my $class     = __PACKAGE__; 
    1718 
    1819    $self->postamble(<<"END_MAKEFILE"); 
     
    2728 
    2829sub check_wx_version { 
    29     # Missing Wx should be dealt by the standard prereq system 
    30     eval { require Wx }; 
    31     return if $@; 
    32  
    33     my $version = Wx::wxVERSION_STRING(); 
    34     nono("Could not find Wx::wxVERSION_STRING") if not defined $version; 
    35  
    36     print "Found $version\n"; 
    37     print "Found Wx.pm     $Wx::VERSION\n"; 
    38     $version =~ s/wxWidgets\s+//; 
    39     nono("Sorry we don't known this wxWidgets version format: '$version'") 
    40       if $version !~ /^\d+\.\d+(\.\d+)?$/; 
    41     my ($major, $minor, $way_too_minor) = split /\./, $version; 
    42     nono("Padre needs at least version 2.8.8 of wxWidgets. this is version $version") 
    43       if $major < 2 or $minor < 8; 
     30    # Can we find Wx.pm 
     31    my $wxfile = _module_file('Wx'); 
     32    my $wxpath = _file_path($wxfile); 
     33    unless ( $wxpath ) { 
     34        # Wx.pm is not installed. 
     35        # Allow EU:MM to do it's thing as normal 
     36        return; 
     37    } 
     38    my $wx_pm = _path_version($wxpath); 
     39    print "Found Wx.pm     $wx_pm\n"; 
     40 
     41    # Do we have the alien package 
     42    eval { 
     43        require Alien::wxWidgets; 
     44        Alien::wxWidgets->import; 
     45    }; 
     46    if ( $@ ) { 
     47        # If we don't have the alien package, 
     48        # we should just pass through to EU:MM 
     49        return; 
     50    } 
     51 
     52    # Find the wxWidgets version from the alien 
     53    my $widgets = Alien::wxWidgets->version; 
     54    unless ( $widgets ) { 
     55        nono("Alien::wxWidgets was unable to determine the wxWidgets version"); 
     56    } 
     57    my $widgets_human = $widgets; 
     58    $widgets_human =~ s/^(\d\.\d\d\d)(\d\d\d)$/$1.$2/; 
     59    $widgets_human =~ s/0//g; 
     60    print "Found wxWidgets $widgets_human\n"; 
     61    unless ( $widgets >= 2.008008 ) { 
     62        nono("Padre needs at least version 2.8.8 of wxWidgets. You have wxWidgets $widgets_human"); 
     63    } 
    4464 
    4565    return; 
     
    4969    my $msg = shift; 
    5070    print STDERR "$msg\n"; 
    51     exit 0; 
    52 } 
    53  
     71    exit(0); 
     72} 
    5473 
    5574sub make_exe { 
     
    5978    eval "use Module::ScanDeps 0.88; 1;" or die $@; 
    6079 
    61     my @libs    = get_libs(); 
     80    my @libs    = get_libs(); 
    6281    my @modules = get_modules(); 
    6382    my $exe  = $^O =~ /win32/i ? 'padre.exe' : 'padre'; 
    64     if (-e $exe) { 
     83    if ( -e $exe ) { 
    6584        unlink $exe or die "Cannot remove '$exe' $!"; 
    6685    } 
    67     my @cmd  = ('pp', '-o', $exe, qw(-I lib script/padre)); 
    68     push @cmd, @modules, @libs; 
    69     if ($^O =~ /win32/i) { 
     86    my @cmd = ( 'pp', '-o', $exe, qw{ -I lib script/padre } ); 
     87    push @cmd, @modules; 
     88    push @cmd, @libs; 
     89    if ( $^O =~ /win32/i ) { 
    7090        push @cmd, '-M', 'Tie::Hash::NamedCapture'; 
    7191    } 
    7292 
    73     print "@cmd\n"; 
     93    print join( ' ', @cmd ) . "\n"; 
    7494    system(@cmd); 
    7595 
     
    7797} 
    7898 
    79  
    8099sub get_libs { 
     100    # Run-time "use" the Alien module 
    81101    require Alien::wxWidgets; 
    82     Alien::wxWidgets->import(); # needed to make it work 
     102    Alien::wxWidgets->import; 
     103 
     104    # Extract the settings we need from the Alient 
     105    my $prefix = Alien::wxWidgets->prefix; 
     106    my %libs   = map { ($_, 0) } Alien::wxWidgets->shared_libraries( 
     107        qw(stc xrc html adv core base)  
     108    ); 
     109 
    83110    require File::Find; 
    84     my @libs = Alien::wxWidgets->shared_libraries( 
    85       qw(stc xrc html adv core base)  
     111    File::Find::find( 
     112        sub { 
     113            if ( exists $libs{$_} ) { 
     114                $libs{$_} = $File::Find::name; 
     115            } 
     116        }, 
     117        $prefix 
    86118    ); 
    87119 
    88 # formerly, we needed to put the libs verbatim: 
    89 #   qw( 
    90 #               libwx_gtk2_adv-2.8.so.0 
    91 #               libwx_gtk2_core-2.8.so.0 
    92 #               libwx_base-2.8.so.0 
    93 #               libwx_base_net-2.8.so.0 
    94 #               libwx_gtk2_stc-2.8.so.0 
    95 #               libwx_gtk2_html-2.8.so.0 
    96 #   ); 
    97  
    98     my %libs = map {($_,0)} @libs; 
    99     my $prefix = Alien::wxWidgets->prefix; 
    100      
    101     File::Find::find( 
    102       sub { 
    103           if (exists $libs{$_}) { 
    104             $libs{$_} = $File::Find::name; 
    105           } 
    106       }, 
    107       $prefix 
    108     ); 
    109  
    110     my @missing = grep {!$libs{$_}} keys %libs; 
    111     warn "Could not find shared library on disk for $_" 
    112       for @missing; 
    113  
    114     my @libs_args; 
    115     push @libs_args, "-l", $_ for values %libs; 
    116  
    117     return @libs_args; 
    118 } 
    119  
     120    my @missing = grep { ! $libs{$_} } keys %libs; 
     121    foreach ( @missing ) { 
     122        warn("Could not find shared library on disk for $_"); 
     123    } 
     124 
     125    return map { ('-l', $_) } values %libs; 
     126} 
    120127 
    121128sub get_modules { 
    122  
    123129    my @modules; 
    124130    my @files; 
    125  
    126     open my $fh, '<', 'MANIFEST' or die "Do you need to run 'make manifest'? Could not open MANIFEST for reading: $!"; 
    127     while (my $line = <$fh>) { 
     131    local *FILE; 
     132    unless ( open(FILE, '<', 'MANIFEST') ) { 
     133        die("Do you need to run 'make manifest'? Could not open MANIFEST for reading: $!"); 
     134    } 
     135    while ( my $line = <FILE> ) { 
    128136        chomp $line; 
    129         if ($line =~ m{^lib/}) { 
     137        if ( $line =~ m{^lib/} ) { 
    130138            $line = substr($line, 4, -3); 
    131139            $line =~ s{/}{::}g; 
    132140            push @modules, $line; 
    133141        } 
    134         if ($line =~ m{^share/}) { 
     142        if ( $line =~ m{^share/} ) { 
    135143            push @files, $line; 
    136144        } 
    137145    } 
     146 
    138147    my @args; 
    139148    push @args, "-M", $_ for @modules; 
    140149    push @args, "-a", $_ for @files; 
    141  
    142150    return @args; 
    143151} 
    144152 
    145  
    146  
    147  
     153# To prevent EU:MM loading modules, we hijack %INC and then set $VERSION 
     154# into all of the packages so that EU:MM still gets the versions it wants. 
     155sub trick_eumm { 
     156    my $self     = shift; 
     157    my @requires = map { $_ ? @$_ : () } ( 
     158        $self->configure_requires, 
     159        $self->build_requires, 
     160        $self->test_requires, 
     161        $self->requires, 
     162    ); 
     163    foreach my $module ( map { $_->[0] } @requires ) { 
     164        # If the module is already loaded leave it alone 
     165        my $file = _module_file($module); 
     166        next if $INC{$file}; 
     167 
     168        # What version of the module is installed 
     169        my $found = _file_path($file); 
     170        unless ( defined $found ) { 
     171            # Leave it to EU:MM to not find as well 
     172            next; 
     173        } 
     174 
     175        # Parse out the version for the currently installed version 
     176        my $version = _path_version($found); 
     177 
     178        # Make the module look like it is loaded, 
     179        # and set the version to match the one on disk. 
     180        $INC{$file} = __PACKAGE__; 
     181        no strict 'refs'; 
     182        *{"${module}::VERSION"} = sub { $version }; 
     183    } 
     184    return 1; 
     185} 
     186 
     187sub _module_file { 
     188    my $module = shift; 
     189    $module =~ s/::/\//g; 
     190    $module .= '.pm'; 
     191    return $module; 
     192} 
     193 
     194sub _file_path { 
     195    my $file  = shift; 
     196    my @found = grep { -f $_ } map { "$_/$file" } @INC; 
     197    return $found[0]; 
     198} 
     199 
     200sub _path_version { 
     201    require ExtUtils::MM_Unix; 
     202    ExtUtils::MM_Unix->parse_version($_[0]); 
     203} 
    148204 
    1492051; 
Note: See TracChangeset for help on using the changeset viewer.