develooper Front page | perl.perl5.porters | Postings from June 2009

[PATCH] Updating ExtUtils::CBuilder to 0.26

Thread Next
From:
David Golden
Date:
June 29, 2009 17:27
Subject:
[PATCH] Updating ExtUtils::CBuilder to 0.26
Message ID:
1246321586-11823-1-git-send-email-dagolden@cpan.org
0.26 - Mon Jun 29 20:11:52 EDT 2009

 - No changes from 0.25_01

0.25_01 - Sat Jun 27 23:13:20 EDT 2009

 - Changed test library to Test::More

 - Added tests for have_compiler

 - Skips tests that need a compiler if have_compiler is false

 - have_compiler will try to compile in the current directory
   if compiling in tmpdir fails for whatever reason
---
 MANIFEST                                   |    1 +
 Porting/Maintainers.pl                     |    6 +-
 lib/ExtUtils/CBuilder.pm                   |    5 +-
 lib/ExtUtils/CBuilder/Base.pm              |   51 +++++++++++++-------
 lib/ExtUtils/CBuilder/Platform/Unix.pm     |    2 +-
 lib/ExtUtils/CBuilder/Platform/VMS.pm      |    2 +-
 lib/ExtUtils/CBuilder/Platform/Windows.pm  |    2 +-
 lib/ExtUtils/CBuilder/Platform/aix.pm      |    2 +-
 lib/ExtUtils/CBuilder/Platform/cygwin.pm   |    2 +-
 lib/ExtUtils/CBuilder/Platform/darwin.pm   |    2 +-
 lib/ExtUtils/CBuilder/Platform/dec_osf.pm  |    2 +-
 lib/ExtUtils/CBuilder/Platform/os2.pm      |    2 +-
 lib/ExtUtils/CBuilder/t/00-have-compiler.t |   41 +++++++++++++++++
 lib/ExtUtils/CBuilder/t/01-basic.t         |   56 +++++++++++++----------
 lib/ExtUtils/CBuilder/t/02-link.t          |   68 +++++++++++++++++-----------
 15 files changed, 162 insertions(+), 82 deletions(-)
 create mode 100644 lib/ExtUtils/CBuilder/t/00-have-compiler.t

diff --git a/MANIFEST b/MANIFEST
index 773e8e9..cd942f0 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -2148,6 +2148,7 @@ lib/ExtUtils/CBuilder/Platform/Unix.pm	CBuilder methods for Unix
 lib/ExtUtils/CBuilder/Platform/VMS.pm	CBuilder methods for VMS
 lib/ExtUtils/CBuilder/Platform/Windows.pm	CBuilder methods for Windows
 lib/ExtUtils/CBuilder.pm	Compile and link C code for Perl modules
+lib/ExtUtils/CBuilder/t/00-have-compiler.t	ExtUtils::CBuilder tests
 lib/ExtUtils/CBuilder/t/01-basic.t	tests for ExtUtils::CBuilder
 lib/ExtUtils/CBuilder/t/02-link.t	tests for ExtUtils::CBuilder
 lib/ExtUtils/Changes		MakeMaker change log
diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl
index 0175b66..7a69216 100755
--- a/Porting/Maintainers.pl
+++ b/Porting/Maintainers.pl
@@ -610,11 +610,11 @@ package Maintainers;
     'ExtUtils::CBuilder' =>
 	{
 	'MAINTAINER'	=> 'kwilliams',
-	'DISTRIBUTION'	=> 'DAGOLDEN/ExtUtils-CBuilder-0.25.tar.gz',
+	'DISTRIBUTION'	=> 'DAGOLDEN/ExtUtils-CBuilder-0.26.tar.gz',
 	'FILES'		=> q[lib/ExtUtils/CBuilder.pm lib/ExtUtils/CBuilder],
-	'EXCLUDED'	=> [ qw{bleadcheck.pl}, ],
+	'EXCLUDED'	=> [ qw{devtools} ],
 	'CPAN'		=> 1,
-	'UPSTREAM'	=> undef,
+	'UPSTREAM'	=> 'cpan',
 	},
 
     'ExtUtils::Command' =>
diff --git a/lib/ExtUtils/CBuilder.pm b/lib/ExtUtils/CBuilder.pm
index b6ee7c0..246a43c 100644
--- a/lib/ExtUtils/CBuilder.pm
+++ b/lib/ExtUtils/CBuilder.pm
@@ -5,7 +5,7 @@ use File::Path ();
 use File::Basename ();
 
 use vars qw($VERSION @ISA);
-$VERSION = '0.25';
+$VERSION = '0.26';
 $VERSION = eval $VERSION;
 
 # Okay, this is the brute-force method of finding out what kind of
@@ -130,7 +130,8 @@ commands before executing them:
 
 Returns true if the current system has a working C compiler and
 linker, false otherwise.  To determine this, we actually compile and
-link a sample C library.
+link a sample C library.  The sample will be compiled in the system
+tempdir or, if that fails for some reason, in the current directory.
 
 =item compile
 
diff --git a/lib/ExtUtils/CBuilder/Base.pm b/lib/ExtUtils/CBuilder/Base.pm
index ed58384..0c78b97 100644
--- a/lib/ExtUtils/CBuilder/Base.pm
+++ b/lib/ExtUtils/CBuilder/Base.pm
@@ -9,7 +9,7 @@ use Text::ParseWords;
 use IO::File;
 
 use vars qw($VERSION);
-$VERSION = '0.25';
+$VERSION = '0.26';
 
 sub new {
   my $class = shift;
@@ -116,25 +116,40 @@ sub compile {
 sub have_compiler {
   my ($self) = @_;
   return $self->{have_compiler} if defined $self->{have_compiler};
-  
-  my $tmpfile = File::Spec->catfile(File::Spec->tmpdir, 'compilet.c');
-  {
-    my $FH = IO::File->new("> $tmpfile") or die "Can't create $tmpfile: $!";
-    print $FH "int boot_compilet() { return 1; }\n";
-  }
 
-  my ($obj_file, @lib_files);
-  eval {
-    $obj_file = $self->compile(source => $tmpfile);
-    @lib_files = $self->link(objects => $obj_file, module_name => 'compilet');
-  };
-  warn $@ if $@;
-  my $result = $self->{have_compiler} = $@ ? 0 : 1;
-  
-  foreach (grep defined, $tmpfile, $obj_file, @lib_files) {
-    1 while unlink;
+  my $result;
+  my $attempts = 3;
+  # tmpdir has issues for some people so fall back to current dir
+  DIR: for my $dir ( File::Spec->tmpdir, '.' ) {
+
+    # don't clobber existing files (rare, but possible)
+    my $rand = int(rand(2**31));
+    my $tmpfile = File::Spec->catfile($dir, "compilet-$rand.c");
+    if ( -e $tmpfile ) {
+      redo DIR if $attempts--;
+      next DIR;
+    }
+
+    {
+      my $FH = IO::File->new("> $tmpfile") or die "Can't create $tmpfile: $!";
+      print $FH "int boot_compilet() { return 1; }\n";
+    }
+
+    my ($obj_file, @lib_files);
+    eval {
+      local $^W = 0;
+      $obj_file = $self->compile(source => $tmpfile);
+      @lib_files = $self->link(objects => $obj_file, module_name => 'compilet');
+    };
+    $result = $@ ? 0 : 1;
+
+    foreach (grep defined, $tmpfile, $obj_file, @lib_files) {
+      1 while unlink;
+    }
+    last DIR if $result;
   }
-  return $result;
+
+  return $self->{have_compiler} = $result;
 }
 
 sub lib_file {
diff --git a/lib/ExtUtils/CBuilder/Platform/Unix.pm b/lib/ExtUtils/CBuilder/Platform/Unix.pm
index 5671057..876fd42 100644
--- a/lib/ExtUtils/CBuilder/Platform/Unix.pm
+++ b/lib/ExtUtils/CBuilder/Platform/Unix.pm
@@ -4,7 +4,7 @@ use strict;
 use ExtUtils::CBuilder::Base;
 
 use vars qw($VERSION @ISA);
-$VERSION = '0.25';
+$VERSION = '0.26';
 @ISA = qw(ExtUtils::CBuilder::Base);
 
 sub link_executable {
diff --git a/lib/ExtUtils/CBuilder/Platform/VMS.pm b/lib/ExtUtils/CBuilder/Platform/VMS.pm
index 740356a..b0c3489 100644
--- a/lib/ExtUtils/CBuilder/Platform/VMS.pm
+++ b/lib/ExtUtils/CBuilder/Platform/VMS.pm
@@ -4,7 +4,7 @@ use strict;
 use ExtUtils::CBuilder::Base;
 
 use vars qw($VERSION @ISA);
-$VERSION = '0.25';
+$VERSION = '0.26';
 @ISA = qw(ExtUtils::CBuilder::Base);
 
 use File::Spec::Functions qw(catfile catdir);
diff --git a/lib/ExtUtils/CBuilder/Platform/Windows.pm b/lib/ExtUtils/CBuilder/Platform/Windows.pm
index db15838..eeaa58c 100644
--- a/lib/ExtUtils/CBuilder/Platform/Windows.pm
+++ b/lib/ExtUtils/CBuilder/Platform/Windows.pm
@@ -10,7 +10,7 @@ use ExtUtils::CBuilder::Base;
 use IO::File;
 
 use vars qw($VERSION @ISA);
-$VERSION = '0.25';
+$VERSION = '0.26';
 @ISA = qw(ExtUtils::CBuilder::Base);
 
 sub new {
diff --git a/lib/ExtUtils/CBuilder/Platform/aix.pm b/lib/ExtUtils/CBuilder/Platform/aix.pm
index cb273e0..73e5c6c 100644
--- a/lib/ExtUtils/CBuilder/Platform/aix.pm
+++ b/lib/ExtUtils/CBuilder/Platform/aix.pm
@@ -5,7 +5,7 @@ use ExtUtils::CBuilder::Platform::Unix;
 use File::Spec;
 
 use vars qw($VERSION @ISA);
-$VERSION = '0.25';
+$VERSION = '0.26';
 @ISA = qw(ExtUtils::CBuilder::Platform::Unix);
 
 sub need_prelink { 1 }
diff --git a/lib/ExtUtils/CBuilder/Platform/cygwin.pm b/lib/ExtUtils/CBuilder/Platform/cygwin.pm
index ade91a2..ccc05c9 100644
--- a/lib/ExtUtils/CBuilder/Platform/cygwin.pm
+++ b/lib/ExtUtils/CBuilder/Platform/cygwin.pm
@@ -5,7 +5,7 @@ use File::Spec;
 use ExtUtils::CBuilder::Platform::Unix;
 
 use vars qw($VERSION @ISA);
-$VERSION = '0.25';
+$VERSION = '0.26';
 @ISA = qw(ExtUtils::CBuilder::Platform::Unix);
 
 sub link_executable {
diff --git a/lib/ExtUtils/CBuilder/Platform/darwin.pm b/lib/ExtUtils/CBuilder/Platform/darwin.pm
index e4c5811..1d70568 100644
--- a/lib/ExtUtils/CBuilder/Platform/darwin.pm
+++ b/lib/ExtUtils/CBuilder/Platform/darwin.pm
@@ -4,7 +4,7 @@ use strict;
 use ExtUtils::CBuilder::Platform::Unix;
 
 use vars qw($VERSION @ISA);
-$VERSION = '0.25';
+$VERSION = '0.26';
 @ISA = qw(ExtUtils::CBuilder::Platform::Unix);
 
 sub compile {
diff --git a/lib/ExtUtils/CBuilder/Platform/dec_osf.pm b/lib/ExtUtils/CBuilder/Platform/dec_osf.pm
index ae92b2c..624d805 100644
--- a/lib/ExtUtils/CBuilder/Platform/dec_osf.pm
+++ b/lib/ExtUtils/CBuilder/Platform/dec_osf.pm
@@ -6,7 +6,7 @@ use File::Spec;
 
 use vars qw($VERSION @ISA);
 @ISA = qw(ExtUtils::CBuilder::Platform::Unix);
-$VERSION = '0.25';
+$VERSION = '0.26';
 
 sub link_executable {
   my $self = shift;
diff --git a/lib/ExtUtils/CBuilder/Platform/os2.pm b/lib/ExtUtils/CBuilder/Platform/os2.pm
index 02d6780..bbe4dc4 100644
--- a/lib/ExtUtils/CBuilder/Platform/os2.pm
+++ b/lib/ExtUtils/CBuilder/Platform/os2.pm
@@ -4,7 +4,7 @@ use strict;
 use ExtUtils::CBuilder::Platform::Unix;
 
 use vars qw($VERSION @ISA);
-$VERSION = '0.25';
+$VERSION = '0.26';
 @ISA = qw(ExtUtils::CBuilder::Platform::Unix);
 
 sub need_prelink { 1 }
diff --git a/lib/ExtUtils/CBuilder/t/00-have-compiler.t b/lib/ExtUtils/CBuilder/t/00-have-compiler.t
new file mode 100644
index 0000000..1ba22f8
--- /dev/null
+++ b/lib/ExtUtils/CBuilder/t/00-have-compiler.t
@@ -0,0 +1,41 @@
+#! perl -w
+
+BEGIN {
+  if ($ENV{PERL_CORE}) {
+    chdir 't' if -d 't';
+    chdir '../lib/ExtUtils/CBuilder'
+      or die "Can't chdir to lib/ExtUtils/CBuilder: $!";
+    @INC = qw(../..);
+  }
+}
+
+use strict;
+use Test::More;
+use File::Spec;
+BEGIN { 
+  if ($^O eq 'VMS') {
+    # So we can get the return value of system()
+    require vmsish;
+    import vmsish;
+  }
+}
+
+plan tests => 4;
+
+require_ok "ExtUtils::CBuilder";
+
+my $b = eval { ExtUtils::CBuilder->new(quiet => 1) };
+ok( $b, "got CBuilder object" ) or diag $@;
+
+# test missing compiler
+$b->{config}{cc} = 'djaadjfkadjkfajdf';
+$b->{config}{ld} = 'djaadjfkadjkfajdf';
+is( $b->have_compiler, 0, "have_compiler: fake missing cc" );
+
+# test found compiler
+$b->{have_compiler} = undef;
+$b->{config}{cc} = "$^X -e1 --";
+$b->{config}{ld} = "$^X -e1 --";
+is( $b->have_compiler, 1, "have_compiler: fake present cc" );
+
+
diff --git a/lib/ExtUtils/CBuilder/t/01-basic.t b/lib/ExtUtils/CBuilder/t/01-basic.t
index 3968a37..5f9ad87 100644
--- a/lib/ExtUtils/CBuilder/t/01-basic.t
+++ b/lib/ExtUtils/CBuilder/t/01-basic.t
@@ -10,42 +10,56 @@ BEGIN {
 }
 
 use strict;
-use Test;
-BEGIN { plan tests => 11 }
-
+use Test::More;
+BEGIN { 
+  if ($^O eq 'VMS') {
+    # So we can get the return value of system()
+    require vmsish;
+    import vmsish;
+  }
+}
 use ExtUtils::CBuilder;
 use File::Spec;
-ok 1;
 
 # TEST doesn't like extraneous output
 my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
+my ($source_file, $object_file, $lib_file);
 
 my $b = ExtUtils::CBuilder->new(quiet => $quiet);
-ok $b;
 
-ok $b->have_compiler;
+# test plan
+if ( ! $b->have_compiler ) {
+  plan skip_all => "no compiler available for testing";
+}
+else {
+  plan tests => 10;
+}
+
+ok $b, "created EU::CB object";
 
-my $source_file = File::Spec->catfile('t', 'compilet.c');
+ok $b->have_compiler, "have_compiler";
+
+$source_file = File::Spec->catfile('t', 'compilet.c');
 {
   local *FH;
   open FH, "> $source_file" or die "Can't create $source_file: $!";
   print FH "int boot_compilet(void) { return 1; }\n";
   close FH;
 }
-ok -e $source_file;
+ok -e $source_file, "source file '$source_file' created";
 
-my $object_file = $b->object_file($source_file);
+$object_file = $b->object_file($source_file);
 ok 1;
 
-ok $object_file, $b->compile(source => $source_file);
+is $object_file, $b->compile(source => $source_file);
 
-my $lib_file = $b->lib_file($object_file);
+$lib_file = $b->lib_file($object_file);
 ok 1;
 
 my ($lib, @temps) = $b->link(objects => $object_file,
                              module_name => 'compilet');
 $lib =~ tr/"'//d;
-ok $lib_file, $lib;
+is $lib_file, $lib;
 
 for ($source_file, $object_file, $lib_file) {
   tr/"'//d;
@@ -54,15 +68,9 @@ for ($source_file, $object_file, $lib_file) {
 
 my @words = $b->split_like_shell(' foo bar');
 
-skip(
-    $^O =~ m/MSWin/ ? "Skip under MSWindows" : 0,  # whether to skip
-    @words, 2
-  );
-skip(
-    $^O =~ m/MSWin/ ? "Skip under MSWindows" : 0,  # whether to skip
-    $words[0], 'foo'
-);
-skip(
-    $^O =~ m/MSWin/ ? "Skip under MSWindows" : 0,  # whether to skip
-    $words[1], 'bar'
-);
+SKIP: {
+  skip "MSWindows", 3 if $^O =~ m/MSWin/;
+  is( @words, 2 );
+  is( $words[0], 'foo' );
+  is( $words[1], 'bar' );
+}
diff --git a/lib/ExtUtils/CBuilder/t/02-link.t b/lib/ExtUtils/CBuilder/t/02-link.t
index 49b9274..d2bacf7 100644
--- a/lib/ExtUtils/CBuilder/t/02-link.t
+++ b/lib/ExtUtils/CBuilder/t/02-link.t
@@ -10,60 +10,74 @@ BEGIN {
 }
 
 use strict;
-use Test;
+use Test::More;
 BEGIN { 
-  if ($^O eq 'MSWin32') {
-    print "1..0 # Skipped: link_executable() is not implemented yet on Win32\n";
-    exit;
-  }
   if ($^O eq 'VMS') {
     # So we can get the return value of system()
     require vmsish;
     import vmsish;
   }
-  plan tests => 5;
 }
-
 use ExtUtils::CBuilder;
 use File::Spec;
 
 # TEST doesn't like extraneous output
 my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
+my ($source_file, $object_file, $exe_file);
 
 my $b = ExtUtils::CBuilder->new(quiet => $quiet);
-ok $b;
 
-my $source_file = File::Spec->catfile('t', 'compilet.c');
+# test plan
+if ($^O eq 'MSWin32') {
+  plan skip_all => "link_executable() is not implemented yet on Win32";
+}
+elsif ( ! $b->have_compiler ) {
+  plan skip_all => "no compiler available for testing";
+}
+else {
+  plan tests => 7;
+}
+
+ok $b, "created EU::CB object";
+
+$source_file = File::Spec->catfile('t', 'compilet.c');
 {
   local *FH;
   open FH, "> $source_file" or die "Can't create $source_file: $!";
   print FH "int main(void) { return 11; }\n";
   close FH;
 }
-ok -e $source_file;
+ok -e $source_file, "generated '$source_file'";
 
 # Compile
-my $object_file;
-ok $object_file = $b->compile(source => $source_file);
+eval { $object_file = $b->compile(source => $source_file) };
+is $@, q{}, "no exception from compilation";
+ok -e $object_file, "found object file";
 
 # Link
-my ($exe_file, @temps);
-($exe_file, @temps) = $b->link_executable(objects => $object_file);
-ok -e $exe_file;
+SKIP: {
+  skip "error compiling source", 3
+    unless -e $object_file;
 
-if ($^O eq 'os2') {		# Analogue of LDLOADPATH...
-	# Actually, not needed now, since we do not link with the generated DLL
-  my $old = OS2::extLibpath();	# [builtin function]
-  $old = ";$old" if defined $old and length $old;
-  # To pass the sanity check, components must have backslashes...
-  OS2::extLibpath_set(".\\$old");
-}
+  my @temps;
+  eval { ($exe_file, @temps) = $b->link_executable(objects => $object_file) };
+  is $@, q{}, "no exception from linking";
+  ok -e $exe_file, "found executable file";
 
-# Try the executable
-my $ec = my_system($exe_file);
-ok $ec, 11
-  or print( $? == -1 ? "# Could not run '$exe_file'\n" 
-                     : "# Unexpected exit code '$ec'\n");
+  if ($^O eq 'os2') {		# Analogue of LDLOADPATH...
+          # Actually, not needed now, since we do not link with the generated DLL
+    my $old = OS2::extLibpath();	# [builtin function]
+    $old = ";$old" if defined $old and length $old;
+    # To pass the sanity check, components must have backslashes...
+    OS2::extLibpath_set(".\\$old");
+  }
+
+  # Try the executable
+  my $ec = my_system($exe_file);
+  is $ec, 11, "got expected exit code from executable"
+    or print( $? == -1 ? "# Could not run '$exe_file'\n" 
+                      : "# Unexpected exit code '$ec'\n");
+}
 
 # Clean up
 for ($source_file, $object_file, $exe_file) {
-- 
1.5.6.3


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About