Changeset 1974

Show
Ignore:
Timestamp:
12/04/07 21:25:54 (7 months ago)
Author:
karpet
Message:

fix bug that MakeMaker? 6.38 revealed. see http://rt.cpan.org/Public/Bug/Display.html?id=31205 . Also ran through perltidy for fun

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • swish-e/trunk/perl/Makefile.PL

    r1743 r1974  
    33use strict; 
    44use ExtUtils::MakeMaker; 
    5 use Config;         # for path separator 
    6 use File::Spec;     # for catpath 
    7 use File::Basename; # for locating swish-e binary based on location of swish-config 
     5use Config;        # for path separator 
     6use File::Spec;    # for catpath 
     7use File::Basename 
     8    ;    # for locating swish-e binary based on location of swish-config 
    89 
    910# $Id$ 
     
    1314 
    1415my %make_maker_opts = ( 
    15     NAME            => 'SWISH::API', 
    16     VERSION_FROM    => 'API.pm', 
    17     AUTHOR          => 'Bill Moseley', 
    18     ABSTRACT        => 'Perl interface to the swish-e search library', 
     16    NAME         => 'SWISH::API', 
     17    VERSION_FROM => 'API.pm', 
     18    AUTHOR       => 'Bill Moseley', 
     19    ABSTRACT     => 'Perl interface to the swish-e search library', 
    1920 
    2021    # Set LIBS and INC from swish-confg 
    2122 
    22     NORECURS        => 1,          # keep it from recursing into subdirectories 
    23     DIR             => [], 
    24     XSPROTOARG      => '-noprototypes', 
    25     PREREQ_PM       => { 
    26         'File::Spec'    => '0.8', 
    27     }, 
    28     test          => { 
    29         TESTS         => 't/*.t', 
    30     }, 
    31     clean           => { 
    32         FILES            => join( ' ', qw( 
    33             t/index.swish-e 
    34             t/index.swish-e.prop 
    35         )), 
     23    NORECURS   => 1,              # keep it from recursing into subdirectories 
     24    DIR        => [], 
     25    XSPROTOARG => '-noprototypes', 
     26    PREREQ_PM => { 'File::Spec' => '0.8', }, 
     27    test  => { TESTS => 't/*.t', }, 
     28    clean => { 
     29        FILES => join( 
     30            ' ', qw( 
     31                t/index.swish-e 
     32                t/index.swish-e.prop 
     33                ) 
     34        ), 
    3635    }, 
    3736); 
    38  
    3937 
    4038my $SWISH_BINARY = 'swish-e'; 
     
    4240my $MIN_VERSION  = '2.4.3'; 
    4341 
    44  
    45 my @valid_params = qw/  
     42my @valid_params = qw/ 
    4643    SWISHBINDIR SWISHHELP SWISHIGNOREVER SWISHSKIPTEST 
    4744    SWISHLIBS SWISHINC SWISHVERSION 
    48 /; 
    49  
    50  
    51  
     45    /; 
    5246 
    5347my $help = <<EOF; 
     
    8175EOF 
    8276 
    83 $SIG{__DIE__} = sub { 
    84     print STDERR "\n  ** ERROR: ", @_; 
    85     print STDERR "  Run perl Makefile.PL SWISHHELP for options\n\n"; 
    86     exit 1; 
    87 }; 
     77END { 
     78    print STDERR "Run perl Makefile.PL SWISHHELP for options\n\n" if $?; 
     79
    8880 
    8981#---------------------------------------------------------------------------------- 
     
    9284# Swish variables get placed in $ENV. 
    9385 
    94 my %config = load_command_line( @valid_params ); 
     86my %config = load_command_line(@valid_params); 
    9587 
    9688if ( exists $ENV{SWISHHELP} ) { 
     
    9991} 
    10092 
    101  
    10293# Get LIBS INC and VERSION from either swish-config or command line/$ENV 
    10394 
     
    10697$config{$_} ||= $swish_config{$_} for qw/ LIBS INC /; 
    10798 
    108  
    10999test_version( $swish_config{VERSION}, $MIN_VERSION ) 
    110     or die "Swish version $swish_config{VERSION} is older than required version $MIN_VERSION\n"; 
    111  
    112  
     100    or die 
     101    "Swish version $swish_config{VERSION} is older than required version $MIN_VERSION\n"; 
    113102 
    114103# Create test index -- needed for make test 
    115104 
    116  
    117105unless ( exists $ENV{SWISHSKIPTEST} ) { 
    118106 
    119     my $swish_binary = File::Spec->catdir( $swish_config{BINDIR}, $SWISH_BINARY ); 
    120     create_index( $swish_binary ); 
    121  
    122 } else { 
     107    my $swish_binary 
     108        = File::Spec->catdir( $swish_config{BINDIR}, $SWISH_BINARY ); 
     109    create_index($swish_binary); 
     110 
     111
     112else { 
    123113    $config{test}{TESTS} = 't/dummy.t'; 
    124114} 
    125115 
    126  
    127  
    128  
    129116WriteMakefile( %make_maker_opts, %config ); 
    130  
    131117 
    132118#---------------------------------------------------------------------------------- 
     
    139125    return 1 if exists $ENV{SWISHIGNOREVER}; 
    140126 
    141     my @tags = qw/ running_swish_version  required_version /; 
     127    my @tags     = qw/ running_swish_version  required_version /; 
    142128    my @versions = qw/ major minor release /; 
    143129 
    144130    @versions{@tags} = @_; 
    145131 
    146  
    147     for ( @tags ) { 
     132    for (@tags) { 
    148133        die "Failed to find version for $_\n" unless $versions{$_}; 
    149134        die "Failed to parse version ($versions{$_}) for $_\n" 
    150135            unless $versions{$_} =~ /(\d+)\.(\d+)\.(\d+)/; 
    151136 
    152         @{$split_vers{$_}}{@versions} = ( $1, $2, $3 ); 
    153     } 
    154  
    155     for ( @versions ) { 
    156         return 1 if $split_vers{running_swish_version}{$_} > $split_vers{required_version}{$_}; 
    157         return 0 if $split_vers{running_swish_version}{$_} < $split_vers{required_version}{$_}; 
    158     } 
    159     return 1;  # same version. 
     137        @{ $split_vers{$_} }{@versions} = ( $1, $2, $3 ); 
     138    } 
     139 
     140    for (@versions) { 
     141        return 1 
     142            if $split_vers{running_swish_version}{$_} 
     143                > $split_vers{required_version}{$_}; 
     144        return 0 
     145            if $split_vers{running_swish_version}{$_} 
     146                < $split_vers{required_version}{$_}; 
     147    } 
     148    return 1;    # same version. 
    160149} 
    161150 
     
    181170    # Otherwise, read from swish-config 
    182171 
    183  
    184     my $swish_config_path = find_swish_config( $SWISH_CONFIG ); 
    185     return read_swish_config( $swish_config_path ); 
    186 
    187  
    188  
     172    my $swish_config_path = find_swish_config($SWISH_CONFIG); 
     173    return read_swish_config($swish_config_path); 
     174
    189175 
    190176#---------------------------------------------------------------------------------- 
     
    194180    my $prog = shift; 
    195181 
    196     my $binary = find_program( $prog ); 
     182    my $binary = find_program($prog); 
    197183 
    198184    if ( $ENV{SWISHBINDIR} ) { 
     
    202188 
    203189        my $p = find_program( $prog, $ENV{SWISHBINDIR} ); 
    204         die "Failed to find [$prog] in directory $ENV{SWISHBINDIR}: $!" unless $p; 
    205  
    206         print "Using config program [$p], but also noticed you have $binary available in \$PATH\n" 
     190        die "Failed to find [$prog] in directory $ENV{SWISHBINDIR}: $!" 
     191            unless $p; 
     192 
     193        print 
     194            "Using config program [$p], but also noticed you have $binary available in \$PATH\n" 
    207195            if $binary; 
    208196 
    209197        $binary = $p; 
    210198    } 
    211  
    212199 
    213200    die "Failed to find [$prog] in PATH\n" unless $binary; 
     
    224211 
    225212    my %config; 
    226     $config{VERSION} = backtick( "$binary --version" ); 
    227     $config{LIBS}    = backtick( "$binary --libs" ); 
    228     $config{INC}     = backtick( "$binary --cflags" ); 
    229     $config{BINDIR } = dirname( $binary ); 
     213    $config{VERSION} = backtick("$binary --version"); 
     214    $config{LIBS}    = backtick("$binary --libs"); 
     215    $config{INC}     = backtick("$binary --cflags"); 
     216    $config{BINDIR}  = dirname($binary); 
    230217 
    231218    return %config; 
    232219} 
    233  
    234220 
    235221#---------------------------------------------------------------------------------- 
     
    242228 
    243229    my %config; 
    244     while( $_ = shift @ARGV ) { 
     230    while ( $_ = shift @ARGV ) { 
    245231        if ( $_ eq 'SWISHHELP' ) { 
    246232            $ENV{SWISHHELP} = 'y'; 
     
    253239            die "Invalid option '$param'\n" unless $valid{$param}; 
    254240            $ENV{$param} = $value || ''; 
    255         } else { 
     241        } 
     242        else { 
    256243            $config{$param} = $value || ''; 
    257244        } 
     
    261248} 
    262249 
    263  
    264  
    265250#---------------------------------------------------------------------------------- 
    266251# Find a program in either $PATH or path/directory passed in. 
     
    271256    $search_path ||= $ENV{PATH} || ''; 
    272257 
    273     for my $dir ( split /$Config{path_sep}/, $search_path ) { 
     258    for my $dir ( split /$Config{path_sep}/, $search_path ) { 
    274259        my $path = File::Spec->catfile( $dir, $name ); 
    275260 
    276261        for my $extension ( '', '.exe' ) { 
    277262            my $file = $path . $extension; 
    278             return $file if -x $file && !-d _; 
     263            return $file if -x $file && !-d _; 
    279264        } 
    280265    } 
     
    282267} 
    283268 
    284  
    285269#---------------------------------------------------------------------------------- 
    286270# Run a program with backtics, checking for errors 
     
    288272 
    289273sub backtick { 
    290     my ( $command ) = @_; 
     274    my ($command) = @_; 
    291275 
    292276    my $output = `$command`; 
    293277 
    294     my $status = $? == 0 
    295                 ? '' 
    296                 : $? == -1 
    297                     ? "Failed to execute: $!" 
    298                     : $? & 127 
    299                         ? sprintf("Child died with signal %d, %s corefile", ($? & 127),  ($? & 128) ? 'with' : 'without' ) 
    300                         : sprintf("chiled exited with value %d", $? >> 8); 
     278    my $status 
     279        = $? == 0  ? '' 
     280        : $? == -1 ? "Failed to execute: $!" 
     281        : $? & 127 ? sprintf( 
     282        "Child died with signal %d, %s corefile", 
     283        ( $? & 127 ), 
     284        ( $? & 128 ) ? 'with' : 'without' 
     285        ) 
     286        : sprintf( "chiled exited with value %d", $? >> 8 ); 
    301287 
    302288    die "Failed to run program [$command]: $status\n" if $status; 
     
    306292} 
    307293 
    308  
    309  
    310294sub create_index { 
    311295    my ($swish) = @_; 
     
    315299 
    316300    my $index = 't/index.swish-e'; 
    317     my $conf = 't/test.conf'; 
    318  
     301    my $conf  = 't/test.conf'; 
    319302 
    320303    unlink $index if -e $index; 
    321304 
    322     my @command = ( $swish,  '-c', $conf, '-f', $index, '-v','0' ); 
    323  
     305    my @command = ( $swish, '-c', $conf, '-f', $index, '-v', '0' ); 
    324306 
    325307    print "Creating index...'@command'\n\n";