Peter Lobsinger wrote:


I intend to merge this soon after the 2.10 release is cut.

Peter, please see the attached patch, which I have pushed to the gsoc_nci branch.

As the branch stood, config/auto/libffi.pm failed to gracefully handle the case where libffi was installed but pkg-config was not. I discovered this the hard way: After submitting one smoke report from linux/i386 without having libffi installed, I installed the libffi debian packages needed. But I didn't know that pkg-config was also needed, so 'make' failed horribly. Once I installed pkg-config, everything DWIMmed. I refactored some code to make the internal method testing for pkg-config itself be testable in t/steps/auto/libffi-01.t.

Also, there was an error in the number of tests in the plan for config/init/defaults.pm.

Thank you very much.
kid51
diff --git a/config/auto/libffi.pm b/config/auto/libffi.pm
index bb1fe30..12c4eb2 100644
--- a/config/auto/libffi.pm
+++ b/config/auto/libffi.pm
@@ -1,12 +1,14 @@
-# Copyright (C) 2005-2010, Parrot Foundation.
+# Copyright (C) 2010, Parrot Foundation.
 # $Id$
 
 =head1 NAME
 
-config/auto/libffi - Check whether libffi
+config/auto/libffi - Check whether libffi is installed
 
 =head1 DESCRIPTION
 
+Note: The program F<pkg-config> is also required.
+
 =cut
 
 package auto::libffi;
@@ -51,19 +53,27 @@ sub runstep {
     my $osname = $conf->data->get('osname');
     print "\n" if $verbose;
     my $pkgconfig_exec = check_progs([ @pkgconfig_variations ], $verbose);
+    unless ($pkgconfig_exec) {
+        print "Program 'pkg-config' needed for libffi\n" if $verbose;
+        $conf->data->set( HAS_LIBFFI => undef );
+        $conf->data->set( has_libffi => undef );
+        $self->set_result('lack pkg-config');
+        return 1;
+    }
+    my $rv = $self->_handle_pkgconfig_exec($conf, $pkgconfig_exec, $verbose);
+    return 1 unless $rv;
 
     my $libffi_options_cflags = '';
     my $libffi_options_libs = '';
     my $libffi_options_linkflags = '';
 
-    if ($pkgconfig_exec) {
-        $libffi_options_linkflags = capture_output($pkgconfig_exec, 'libffi --libs-only-L');
-        chomp $libffi_options_linkflags;
-        $libffi_options_libs = capture_output($pkgconfig_exec, 'libffi --libs-only-l');
-        chomp $libffi_options_libs;
-        $libffi_options_cflags = capture_output($pkgconfig_exec, 'libffi --cflags');
-        chomp $libffi_options_cflags;
-    }
+    $libffi_options_linkflags =
+        capture_output($pkgconfig_exec, 'libffi --libs-only-L');
+    chomp $libffi_options_linkflags;
+    $libffi_options_libs = capture_output($pkgconfig_exec, 'libffi --libs-only-l');
+    chomp $libffi_options_libs;
+    $libffi_options_cflags = capture_output($pkgconfig_exec, 'libffi --cflags');
+    chomp $libffi_options_cflags;
 
     my $extra_libs = $self->_select_lib( {
         conf            => $conf,
@@ -108,6 +118,20 @@ sub _evaluate_cc_run {
     return $has_libffi;
 }
 
+sub _handle_pkgconfig_exec {
+    my ($self, $conf, $pkgconfig_exec, $verbose) = @_;
+    if (! $pkgconfig_exec) {
+        print "Program 'pkg-config' needed for libffi\n" if $verbose;
+        $conf->data->set( HAS_LIBFFI => undef );
+        $conf->data->set( has_libffi => undef );
+        $self->set_result('lack pkg-config');
+        return;
+    }
+    else {
+        return 1;
+    }
+}
+
 1;
 
 =head1 AUTHOR
diff --git a/t/steps/auto/libffi-01.t b/t/steps/auto/libffi-01.t
index 83ac23c..38bd449 100644
--- a/t/steps/auto/libffi-01.t
+++ b/t/steps/auto/libffi-01.t
@@ -1,11 +1,11 @@
 #!perl
-# Copyright (C) 2001-2007, Parrot Foundation.
+# Copyright (C) 2010, Parrot Foundation.
 # $Id$
-# auto/ctags-01.t
+# auto/libffi-01.t
 
 use strict;
 use warnings;
-use Test::More tests => 19;
+use Test::More tests => 28;
 use Carp;
 use lib qw( lib t/configure/testlib );
 use_ok('config::auto::libffi');
@@ -38,14 +38,11 @@ $conf->options->set(%{$args});
 $step = test_step_constructor_and_description($conf);
 
 ok( $step->runstep($conf), 'runstep() returned true value' );
-like( $step->result(), qr/^yes|no$/, "Result was set" );
-like( $conf->data->get( 'HAS_LIBFFI' ),
-    qr/^1|0$/,
-    "Plausible value for 'HAS_LIBFFI'"
-);
+ok( defined( $step->result ), 'result defined' );
 # Prepare for next tests
 $step->set_result( undef );
 $conf->data->set( HAS_LIBFFI => undef );
+$conf->data->set( has_libffi => undef );
 
 $conf->replenish($serialized);
 
@@ -65,16 +62,13 @@ $step = test_step_constructor_and_description($conf);
         \$stdout
     );
     ok( $ret, "runstep() returned true value" );
-    like( $step->result(), qr/^yes|no$/, "Result was set" );
-    like( $conf->data->get( 'HAS_LIBFFI' ),
-        qr/^1|0$/,
-        "Plausible value for 'HAS_LIBFFI'"
-    );
+    ok( defined( $step->result ), 'result defined' );
     ok( $stdout, 'Some verbose output captured' );
 }
 # Prepare for next tests
 $step->set_result( undef );
 $conf->data->set( HAS_LIBFFI => undef );
+$conf->data->set( has_libffi => undef );
 
 ########## --without-libffi ##########
 
@@ -95,6 +89,48 @@ ok(auto::libffi::_evaluate_cc_run('libffi worked'),
 ok(! auto::libffi::_evaluate_cc_run('libffi did not worked'),
     "'_evaluate_cc_run able to return false value");
 
+# Prepare for next tests
+$step->set_result(undef);
+$conf->data->set( HAS_LIBFFI => undef );
+$conf->data->set( has_libffi => undef );
+
+##### _handle_pkgconfig_exec #####
+
+my ($pkgconfig_exec, $verbose);
+
+$pkgconfig_exec = 1;
+$verbose = 0;
+$ret = $step->_handle_pkgconfig_exec( $conf, $pkgconfig_exec, $verbose);
+ok( $ret, '_handle_pkgconfig_exec() returned true' );
+ok( ! defined($step->result), 'result undefined as expected' );
+
+$pkgconfig_exec = 0;
+$verbose = 0;
+$ret = $step->_handle_pkgconfig_exec( $conf, $pkgconfig_exec, $verbose);
+ok( ! defined($ret), '_handle_pkgconfig_exec() returned undefined value' );
+is( $step->result, 'lack pkg-config', 'Got expected result' );
+ok( ! defined($conf->data->get( 'HAS_LIBFFI')), 'HAS_LIBFFI undef as expected');
+ok( ! defined($conf->data->get( 'has_libffi')), 'has_libffi undef as expected');
+
+{
+    my ($stdout, $stderr);
+    $pkgconfig_exec = 0;
+    $verbose = 1;
+    capture(
+        sub { $ret =
+            $step->_handle_pkgconfig_exec( $conf, $pkgconfig_exec, $verbose);
+        },
+        \$stdout,
+        \$stderr,
+    );
+    ok( ! defined($ret), '_handle_pkgconfig_exec() returned undefined value' );
+    is( $step->result, 'lack pkg-config', 'Got expected result' );
+    ok( ! defined($conf->data->get( 'HAS_LIBFFI')), 'HAS_LIBFFI undef as expected');
+    ok( ! defined($conf->data->get( 'has_libffi')), 'has_libffi undef as expected');
+    like( $stdout, qr/Program 'pkg-config' needed for libffi/,
+        "Got expected verbose output when pkg-config not found" );
+}
+
 pass("Completed all tests in $0");
 
 ################### DOCUMENTATION ###################
@@ -113,9 +149,9 @@ The files in this directory test functionality used by F<Configure.pl>.
 
 The tests in this file test configuration step class auto::libffi
 
-=head1 AUTHOR
+=head1 AUTHORS
 
-John Harrison
+John Harrison; James E Keenan.
 
 =head1 SEE ALSO
 
diff --git a/t/steps/init/defaults-01.t b/t/steps/init/defaults-01.t
index ed005ff..a4f90fd 100644
--- a/t/steps/init/defaults-01.t
+++ b/t/steps/init/defaults-01.t
@@ -4,7 +4,7 @@
 
 use strict;
 use warnings;
-use Test::More tests => 49;
+use Test::More tests => 61;
 use Carp;
 use Cwd;
 use File::Copy;
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev

Reply via email to