Author: jkeenan
Date: Tue Aug  5 19:50:54 2008
New Revision: 30045

Added:
   branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/Shared.pm
      - copied, changed from r30044, 
/branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/CLI.pm
Modified:
   branches/scriptconfigure/Configure.pl
   branches/scriptconfigure/MANIFEST
   branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/CLI.pm
   branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/File.pm

Log:
[configure] Extract those options which are valid either on the command-line
or inside a configuration file and place them in
@Parrot::Configure::Options::Conf::Shared::valid_shared_options.  Import this
into Parrot::Configure::Options::Conf::CLI and
Parrot::Configure::Options::Conf::File.  Provide for a more robust
configuration file.  Still need to allow for multiple steps designated as
verbose-step or fatal-step. 


Modified: branches/scriptconfigure/Configure.pl
==============================================================================
--- branches/scriptconfigure/Configure.pl       (original)
+++ branches/scriptconfigure/Configure.pl       Tue Aug  5 19:50:54 2008
@@ -7,6 +7,7 @@
 use strict;
 use warnings;
 use lib 'lib';
+use Data::Dumper;$Data::Dumper::Indent = 1;
 
 use Parrot::Configure;
 use Parrot::Configure::Options qw( process_options );
@@ -41,6 +42,7 @@
         argv => [EMAIL PROTECTED],
     }
 );
+#print STDERR Dumper ($args, $steps_list_ref);
 exit(1) unless defined $args;
 
 my $opttest = Parrot::Configure::Options::Test->new($args);

Modified: branches/scriptconfigure/MANIFEST
==============================================================================
--- branches/scriptconfigure/MANIFEST   (original)
+++ branches/scriptconfigure/MANIFEST   Tue Aug  5 19:50:54 2008
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Mon Aug  4 00:45:21 2008 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Wed Aug  6 02:47:31 2008 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -2693,6 +2693,7 @@
 lib/Parrot/Configure/Options/Conf.pm                        [devel]
 lib/Parrot/Configure/Options/Conf/CLI.pm                    [devel]
 lib/Parrot/Configure/Options/Conf/File.pm                   [devel]
+lib/Parrot/Configure/Options/Conf/Shared.pm                 [devel]
 lib/Parrot/Configure/Options/Reconf.pm                      [devel]
 lib/Parrot/Configure/Options/Test.pm                        [devel]
 lib/Parrot/Configure/Options/Test/Prepare.pm                [devel]

Modified: branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/CLI.pm
==============================================================================
--- branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/CLI.pm   
(original)
+++ branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/CLI.pm   Tue Aug 
 5 19:50:54 2008
@@ -20,77 +20,12 @@
     print_help
     print_version
 );
+use Parrot::Configure::Options::Conf::Shared qw(
+    @shared_valid_options
+);
 use Parrot::Configure::Step::List qw( get_steps_list );
 
-our @valid_options = qw{
-    ask
-    bindir
-    cage
-    cc
-    ccflags
-    ccwarn
-    cgoto
-    configure_trace
-    cxx
-    datadir
-    debugging
-    define
-    exec-prefix
-    execcapable
-    fatal
-    fatal-step
-    floatval
-    gc
-    help
-    icu-config
-    icuheaders
-    icushared
-    includedir
-    infodir
-    inline
-    intval
-    jitcapable
-    languages
-    ld
-    ldflags
-    lex
-    libdir
-    libexecdir
-    libs
-    link
-    linkflags
-    localstatedir
-    m
-    make
-    maintainer
-    mandir
-    miniparrot
-    nomanicheck
-    oldincludedir
-    opcode
-    ops
-    optimize
-    parrot_is_shared
-    pmc
-    prefix
-    profile
-    sbindir
-    sharedstatedir
-    silent
-    sysconfdir
-    test
-    verbose
-    verbose-step
-    version
-    without-gdbm
-    without-opengl
-    without-pcre
-    without-crypto
-    without-gettext
-    without-gmp
-    without-icu
-    yacc
-};
+our @valid_options = ( 'ask', @shared_valid_options );
 
 my %short_circuits = (
     help    => \&print_help,

Modified: branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/File.pm
==============================================================================
--- branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/File.pm  
(original)
+++ branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/File.pm  Tue Aug 
 5 19:50:54 2008
@@ -12,8 +12,10 @@
     $parrot_version
     $svnid
 );
+use Data::Dumper;$Data::Dumper::Indent = 1;
 use File::Spec;
 use lib qw( lib );
+use Parrot::BuildUtil;
 use Parrot::Configure::Options::Conf qw(
     $script
     $parrot_version
@@ -21,6 +23,9 @@
     print_help
     print_version
 );
+use Parrot::Configure::Options::Conf::Shared qw(
+    @shared_valid_options
+);
 
 our @valid_options = qw{
     help
@@ -45,40 +50,105 @@
     my $data = shift;
     $data->{debugging} = 1;
     $data->{maintainer} = undef;
-    open my $IN, '<', $data->{file}
-        or die "Unable to open configuration data file $data->{file} for 
reading: $!";
+    my %valid_step_options = map {$_ => 1} @shared_valid_options;
+    my $file_str = Parrot::BuildUtil::slurp_file($data->{file});
+    my $steps_list_ref;
+    if ($file_str =~ m/==variables\s*?\n
+        (.*?)
+        \s*\n
+        ==general\s*?\n
+        (.*?)
+        \s*\n
+        ==steps\s*?\n
+        (.*?)
+        \s*\n
+        ==cut
+        /sx ) {
+        my ($variables, $general, $steps) = ($1,$2,$3);
+        my $substitutions = _get_substitutions($variables);
+        $data = _set_general($data, $substitutions, $general,
+            \%valid_step_options);
+        ($data, $steps_list_ref) =
+            _set_steps($data, $steps, \%valid_step_options);
+    }
+    else {
+        die "Configuration file $data->{file} did not parse correctly: $!";
+    }
+    return ($data, $steps_list_ref);;
+}
+
+sub _get_substitutions {
+    my $variables = shift;
+    my @variables = split /\n/, $variables;
+    my %substitutions;
+    foreach my $v (@variables) {
+        next unless $v =~ m/^(\w+)=([^=]+)$/;
+        my ($k, $v) = ($1, $2);
+        $substitutions{$k} = $v;
+    }
+    return \%substitutions;
+}
+
+sub _set_general {
+    my ($data, $substitutions, $general, $optsref) = @_;
+    my @general = split /\n/, $general;
+    foreach my $g (@general) {
+        next unless $g =~ m/^(\w+)=(\$?[^\s\$]+)$/;
+        my ($k, $v, $prov, $var);
+        ($k, $prov) = ($1, $2);
+        if ($prov =~ m/^\$(.+)/) {
+            $var = $1;
+            if ($substitutions->{$var}) {
+                $v = $substitutions->{$var};
+            }
+            else {
+                die "Bad variable substitution in $data->{file}: $!";
+            }
+        }
+        else {
+            $v = $prov;
+        }
+        if (! $optsref->{$k}) {
+            die "Invalid general option $k in $data->{file}: $!";
+        }
+        else {
+            $data->{$k} = $v;
+        }
+    }
+    return $data;
+}
+
+sub _set_steps {
+    my ($data, $steps, $optsref) = @_;;
+    my @steplines = split /\n/, $steps;
     my @steps_list = ();
-    LINE: while ( my $line = <$IN> ) {
-        chomp $line;
-        next if $line =~ /^(\s*$|#)/o;
-        if ($line =~ /^(\w+::\w+)(?:\s+(\S+\s+)*(\S+))?$/) {
-            my $step = $1;
-            push @steps_list, $step;
-            next LINE unless $3;
-            my $opts_string = $2 ? qq{$2$3} : $3;
-            my @opts = split /\s+/, $opts_string;
-            foreach my $el (@opts) {
-                my ( $key, $value );
-                if ($el =~ m/([-\w]+)(?:=(.*))?/) {
-                    ( $key, $value ) = ($1, $2);
-                }
-                if (! defined $key) {
-                    die "Unable to process key $key in step $step in 
configuration data file $data->{file}: $!"
-                }
-                # We'll have to check here for valid options, which now more
-                # closely resemble those in Conf::CLI.
-#        unless ( $valid_opts{$key} ) {
-#            die qq/Invalid option "$key". See "perl $file --help" for valid 
options\n/;
-#        }
-                $value = 1 unless defined $value;
-                $data->{$key} = $value;
+    LINE: foreach my $line (@steplines) {
+        next unless ($line =~ /^(\w+::\w+)(?:\s+(\S+\s+)*(\S+))?$/);
+        my $step = $1;
+        push @steps_list, $step;
+        next LINE unless $3;
+        my $opts_string = $2 ? qq{$2$3} : $3;
+        my @opts = split /\s+/, $opts_string;
+        foreach my $el (@opts) {
+            my ( $key, $value );
+            if ($el =~ m/([-\w]+)(?:=(.*))?/) {
+                ( $key, $value ) = ($1, $2);
+            }
+            if (! defined $key) {
+                die "Unable to process key $key in step $step in configuration 
data file $data->{file}: $!"
+            }
+            unless ( $optsref->{$key} ) {
+                die qq/Invalid option "$key". See "perl Configure.pl --help" 
for options valid within a configuration file\n/;
             }
+            # This will have to be fixed to allow for possibility that >1 step
+            # might be declared a verbose-step or a fatal-step.
+            $value = $step if $key eq 'verbose-step';
+            $value = $step if $key eq 'fatal-step';
+            $value = 1 unless defined $value;
+            $data->{$key} = $value;
         }
     }
-    $data->{configured_from_file} = File::Spec->rel2abs($data->{file});
-    close $IN
-        or die "Unable to close configuration data file $data->{file} after 
reading: $!";
-    return ($data, [EMAIL PROTECTED]);;
+    return ($data, [EMAIL PROTECTED]);
 }
 
 1;

Copied: branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/Shared.pm 
(from r30044, 
/branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/CLI.pm)
==============================================================================
--- /branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/CLI.pm  
(original)
+++ branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/Shared.pm        
Tue Aug  5 19:50:54 2008
@@ -1,29 +1,15 @@
 # Copyright (C) 2007-2008, The Perl Foundation.
 # $Id$
-package Parrot::Configure::Options::Conf::CLI;
+package Parrot::Configure::Options::Conf::Shared;
 
 use strict;
 use warnings;
 use base qw( Exporter );
 our @EXPORT_OK = qw(
-    @valid_options
-    $script
-    %options_components
-    $parrot_version
-    $svnid
+    @shared_valid_options
 );
-use lib qw( lib );
-use Parrot::Configure::Options::Conf qw(
-    $script
-    $parrot_version
-    $svnid
-    print_help
-    print_version
-);
-use Parrot::Configure::Step::List qw( get_steps_list );
 
-our @valid_options = qw{
-    ask
+our @shared_valid_options = qw{
     bindir
     cage
     cc
@@ -92,28 +78,50 @@
     yacc
 };
 
-my %short_circuits = (
-    help    => \&print_help,
-    version => \&print_version,
-);
+################### DOCUMENTATION ###################
 
-our %options_components = (
-    'valid_options'  => [EMAIL PROTECTED],
-    'script'         => $script,
-    'short_circuits' => \%short_circuits,
-    'conditionals'   => \&conditional_assignments,
-);
+=head1 NAME
+
+Parrot::Configure::Options::Conf::Shared
+
+=head1 SYNOPSIS
+
+    use Parrot::Configure::Options::Conf::Shared qw(
+        @shared_valid_options
+    );
+    our @valid_options = ( 'ask', @shared_valid_options );
+
+=head1 DESCRIPTION
+
+This package exports a single variable, C<@shared_valid_options()>, which
+holds the list of options which may be used either on:
+
+=over 4
+
+=item *
+
+the L<Configure.pl>
+command-line (corresponding to use of C<mode => configure> in
+C<Parrot::Configure::Options::process_options()>); or
+
+=item *
+
+inside a configuration file where L<Configure.pl> is called with the
+C<--file=path/to/configfile> option (corresponding to use of C<mode => file>
+in C<Parrot::Configure::Options::process_options()>).
+
+=back
+
+=head1 AUTHOR
+
+Refactored from earlier code by James E Keenan.
+
+Parrot::Configure::Options.  Parrot::Configure::Options::Conf::CLI.
+Parrot::Configure::Options::Conf::File.  Configure.pl.
+
+=head1 SEE ALSO
 
-sub conditional_assignments {
-    my $argsref = shift;
-    $argsref->{debugging} = 1
-        unless ( ( exists $argsref->{debugging} ) && !$argsref->{debugging} );
-    $argsref->{maintainer} = 1
-        if defined $argsref->{lex}
-            or defined $argsref->{yacc};
-    my @steps_list = get_steps_list();
-    return ( $argsref, [ @steps_list ] );
-}
+=cut
 
 1;
 

Reply via email to