# New Ticket Created by  Joshua Hoblitt 
# Please include the string:  [perl #37477]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37477 >


This transaction appears to have no content
This patch splits the probes for lex & yacc into there own files and
detects if they are respectively flex or bison.  If flex or bison is
detected the version number is recorded.  It also changes the probing
logic to be more sophisticated.  The precedence of which program to use
would be changed to: default -> probe -> environment -> option -> ask.

The files config/inter/lex.pl & config/inter/yacc.pl are almost
identical.  I thought about trying to split this logic into one or more
utility functions but I'm not sure if they could be made generic enough
to be useful for other probe scripts.

This change would be the first step in being able to declare version
requirements for which version of flex and bison are used.  Do so would
change Configures behavior significantly enough that I'd like to
introduce this one piece at a time.

Any objections?

-J

--
Index: lib/Parrot/Configure/RunSteps.pm
===================================================================
--- lib/Parrot/Configure/RunSteps.pm    (revision 9512)
+++ lib/Parrot/Configure/RunSteps.pm    (working copy)
@@ -31,6 +31,8 @@
     init/hints.pl
     init/headers.pl
     inter/progs.pl
+    inter/lex.pl
+    inter/yacc.pl
     auto/gcc.pl
     init/optimize.pl
     inter/shlibs.pl
Index: config/inter/lex.pl
===================================================================
--- config/inter/lex.pl (revision 0)
+++ config/inter/lex.pl (revision 0)
@@ -0,0 +1,85 @@
+# Copyright: 2001-2005 The Perl Foundation.  All Rights Reserved.
+# $Id$
+
+=head1 NAME
+
+config/auto/lex.pl - lexical analyzer generator
+
+=head1 DESCRIPTION
+
+Determines whether C<lex> is installed and if it's actually C<flex>.
+
+=cut
+
+package Configure::Step;
+
+use strict;
+
+use vars qw( $description @args $prompt $util );
+use Parrot::Configure::Step qw( :inter capture_output check_progs );
+
+$util           = 'lex';
+$description    = "Determining whether $util is installed";
+$prompt         = "Do you have a lexical analyzer generator like flex or lex?";
[EMAIL PROTECTED]           = qw( lex ask maintainer );
+
+sub runstep {
+    my %args;
+    @[EMAIL PROTECTED]@_;
+
+    # undef means we don't have flex... default to not having flex
+    Configure::Data->set(flex_version => undef);
+
+    unless ($args{maintainer}) {
+        Configure::Data->set( $util => $^O eq 'Win32' ? 'REM' : 'echo' );
+        $Configure::Step::result = 'skipped';
+        return undef;
+    }
+
+    my $prog;
+    # precedence of sources for the program:
+    # default -> probe -> environment -> option -> ask
+    $prog ||= $args{$util};
+    $prog ||= $ENV{uc($util)};
+
+    # never override the user.  If a non-existent program is specified then
+    # the user is responsible for the consequences.
+    if (defined $prog) {
+        Configure::Data->set($util => $prog);
+        $Configure::Step::result = 'yes';
+        return undef;
+    }
+
+    $prog = check_progs(['flex', 'lex']);
+
+    unless ($prog) {
+        # fall back to default
+        $Configure::Step::result = 'no';
+        return undef;
+    }
+
+    if ($args{ask}) {
+        $prog = prompt($prompt, $prog ? $prog : Configure::Data->get($util));
+    }
+
+    my ($stdout, $stderr, $ret) = capture_output($prog, '--version');
+
+    # don't override the user even if the program they provided appears to be
+    # broken
+    if ($ret == -1 and ! $args{ask}) {
+        # fall back to default
+        $Configure::Step::result = 'no';
+        return undef;
+    }
+
+    # if '--version' returns a string assume that this is flex.
+    # flex calls it self by $0 so it will claim to be lex if invoked as `lex`
+    if ($stdout =~ /f?lex \s+ (\d+) \. (\d+) \. (\d+)/x) {
+        Configure::Data->set(flex_version => [$1, $2, $3]);
+    }
+
+    Configure::Data->set($util => $prog);
+    $Configure::Step::result = 'yes';
+}
+
+1;
Index: config/inter/progs.pl
===================================================================
--- config/inter/progs.pl       (revision 9512)
+++ config/inter/progs.pl       (working copy)
@@ -109,21 +109,6 @@
     $debug='y'  if $args{debugging};
     $debug = prompt("Do you want a debugging build of Parrot?", $debug) if 
$args{ask};
 
-    if ($args{'maintainer'}) {
-       $lex = integrate(Configure::Data->get('lex'), $args{lex});
-       $lex  = &$first_working($lex,  'flex', 'lex');
-       $yacc = integrate(Configure::Data->get('yacc'), $args{yacc});
-       $yacc = &$first_working($yacc, 'bison -v -y', 'yacc', 'byacc');
-    }
-    else {
-       $lex = $yacc = $null;
-    }
-    $lex = prompt("Do you have a lexical analyzer generator, like flex or 
lex?",$lex) if $args{ask};
-    Configure::Data->set(lex =>  $lex);
-
-    $yacc = prompt("Do you have a parser generator, like bison or 
yacc?",$yacc) if $args{ask};
-    Configure::Data->set(yacc =>  $yacc);
-
   if(!$debug || $debug =~ /n/i) {
     Configure::Data->set(
       cc_debug => '',
Index: config/inter/yacc.pl
===================================================================
--- config/inter/yacc.pl        (revision 0)
+++ config/inter/yacc.pl        (revision 0)
@@ -0,0 +1,85 @@
+# Copyright: 2001-2005 The Perl Foundation.  All Rights Reserved.
+# $Id$
+
+=head1 NAME
+
+config/auto/yacc.pl - parser generator
+
+=head1 DESCRIPTION
+
+Determines whether C<yacc> is installed and if it's actually C<bison>.
+
+=cut
+
+package Configure::Step;
+
+use strict;
+
+use vars qw( $description @args $prompt $util );
+use Parrot::Configure::Step qw( :inter capture_output check_progs );
+
+$util           = 'yacc';
+$description    = "Determining whether $util is installed";
+$prompt         = "Do you have a parser generator, like bison or yacc?";
[EMAIL PROTECTED] =          qw( yacc ask maintainer );
+
+sub runstep {
+    my %args;
+    @[EMAIL PROTECTED]@_;
+
+    # undef means we don't have bison... default to not having bison
+    Configure::Data->set(bison_version => undef);
+
+    unless ($args{maintainer}) {
+        Configure::Data->set( $util => $^O eq 'Win32' ? 'REM' : 'echo' );
+        $Configure::Step::result = 'skipped';
+        return undef;
+    }
+
+    my $prog;
+    # precedence of sources for the program:
+    # default -> probe -> environment -> option -> ask
+    $prog ||= $args{$util};
+    $prog ||= $ENV{uc($util)};
+
+    # never override the user.  If a non-existent program is specified then
+    # the user is responsible for the consequences.
+    if (defined $prog) {
+        Configure::Data->set($util => $prog);
+        $Configure::Step::result = 'yes';
+        return undef;
+    }
+
+    $prog = check_progs(['bison -v -y', 'yacc', 'byacc']);
+
+    unless ($prog) {
+        # fall back to default
+        $Configure::Step::result = 'no';
+        return undef;
+    }
+
+    if ($args{ask}) {
+        $prog = prompt($prompt, $prog ? $prog : Configure::Data->get($util));
+    }
+
+    my ($stdout, $stderr, $ret) = capture_output($prog, '--version');
+
+    # don't override the user even if the program they provided appears to be
+    # broken
+    if ($ret == -1 and ! $args{ask}) {
+        # fall back to default
+        $Configure::Step::result = 'no';
+        return undef;
+    }
+
+    # if '--version' returns a string assume that this is bison.
+    # if this is bison pretending to be yacc '--version' doesn't work
+    if ($stdout =~ /Bison .*? (\d+) \. (\d+) (\w)? /x) {
+        Configure::Data->set(bison_version => [$1, $2, $3]);
+    }
+
+    Configure::Data->set($util => $prog);
+    $Configure::Step::result = 'yes';
+}
+
+1;

Attachment: pgpdbz666fxEg.pgp
Description: PGP signature

Reply via email to