Ticket #1957: tt1957.init.optimize.patch

File tt1957.init.optimize.patch, 3.7 KB (added by jkeenan, 4 years ago)

corrected handling of command-line options; more thorough testing

  • config/init/optimize.pm

    diff --git a/config/init/optimize.pm b/config/init/optimize.pm
    index ff97e57..c2d88e8 100644
    a b  
    3535 
    3636    # A plain --optimize means use perl5's $Config{optimize}.  If an argument 
    3737    # is given, however, use that instead. 
    38     my $request_optimize = $conf->options->get('optimize'); 
     38    my $request_optimize = $conf->options->get('optimize') || ''; 
    3939 
    40     if (! defined $request_optimize) { 
     40    if (! $request_optimize) { 
    4141        $self->set_result('no'); 
    4242        $conf->debug("(none requested) "); 
    4343        return 1; 
    4444    } 
    4545 
    46     $self->set_result('yes'); 
    47     my $gccversion = $conf->data->get( 'gccversion' ); 
    48  
    49     my $options; 
    50     if ( $request_optimize ) { 
     46    my $optimization_level; 
     47    if ( $request_optimize eq '1' ) { 
     48        # i.e., if command-line has '--optimize', 
    5149        # start with perl5's flags ... 
    52         $options = $conf->data->get('optimize_provisional'); 
     50        $optimization_level = $conf->data->get('optimize_provisional'); 
    5351 
    5452        # ... but gcc 4.1 doesn't like -mcpu=xx, i.e. it's deprecated 
     53        my $gccversion = $conf->data->get( 'gccversion' ); 
    5554        if ( defined $gccversion and $gccversion > 3.3 ) { 
    56             $options =~ s/-mcpu=/-march=/; 
     55            $optimization_level =~ s/-mcpu=/-march=/; 
    5756        } 
    5857    } 
    5958    else { 
    60         # use the command line verbatim 
    61         $options = $request_optimize; 
     59        # Otherwise, use the command-line verbatim, e.g. '--optimize=O3' 
     60        $optimization_level = $request_optimize; 
    6261    } 
    6362 
    6463    # save the options, however we got them. 
    65     $conf->data->set( optimize => $options ); 
    66     $conf->debug("optimize options: ", $options, "\n"); 
     64    $conf->data->set( optimize => $optimization_level ); 
     65    $conf->debug("optimize options: ", $optimization_level, "\n"); 
    6766 
    6867    # disable debug flags. 
    6968    $conf->data->set( cc_debug => '' ); 
     
    7372    if ($conf->data->get('cpuarch') eq 'amd64') { 
    7473        $conf->data->set('optimize::src/gc/system.c',''); 
    7574    } 
     75    $self->set_result('yes'); 
    7676 
    7777    return 1; 
    7878} 
  • t/steps/init/optimize-01.t

    diff --git a/t/steps/init/optimize-01.t b/t/steps/init/optimize-01.t
    index 39c37bb..f2a6502 100644
    a b  
    33# init/optimize-01.t 
    44use strict; 
    55use warnings; 
    6 use Test::More tests => 28; 
     6use Test::More tests => 34; 
    77use Carp; 
    88use lib qw( lib t/configure/testlib ); 
    99use_ok('config::init::optimize'); 
     
    6868 
    6969$conf->replenish($serialized); 
    7070 
     71########## --optimize  ########## 
     72 
     73# 'bare' --optimize should mean: default to what Perl 5 uses (typically, -O2), 
     74# but perhaps with some manipulation due to GCC variations 
     75($args, $step_list_ref) = process_options( { 
     76    argv => [q{--optimize}], 
     77    mode => q{configure}, 
     78} ); 
     79$conf->options->set( %{$args} ); 
     80$step = test_step_constructor_and_description($conf); 
     81$ret = $step->runstep($conf); 
     82ok( defined $ret, "runstep() returned defined value" ); 
     83my $perl5_setting = $conf->data->get('optimize_provisional'); 
     84like( $conf->data->get('optimize'), 
     85   qr/$perl5_setting/, 
     86   "Simple '--optimize' defaulted to Perl 5 optimization level" ); 
     87 
     88$conf->replenish($serialized); 
     89 
    7190########## --optimize=O2  ########## 
    7291 
    7392($args, $step_list_ref) = process_options( { 
    74     argv => [q{--optimize=O2}], 
     93    argv => [q{--optimize=-O3}], 
    7594    mode => q{configure}, 
    7695} ); 
    7796$conf->options->set( %{$args} ); 
    7897$step = test_step_constructor_and_description($conf); 
    7998$ret = $step->runstep($conf); 
    8099ok( defined $ret, "runstep() returned defined value" ); 
     100is( $conf->data->get('optimize'), '-O3', 
     101   "Got optimization level explicitly requested" );  
    81102 
    82103$conf->replenish($serialized); 
    83104