[svn:ExtUtils-CBuilder] r12936 - in ExtUtils-CBuilder/trunk: . lib/ExtUtils lib/ExtUtils/CBuilder

[email protected]
Newsgroups perl.module.build.checkins
Message-ID <[email protected]>
Author: dagolden
Date: Sat Jun 27 16:26:09 2009
New Revision: 12936

Modified:
   ExtUtils-CBuilder/trunk/Changes
   ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder.pm
   ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder/Base.pm

Log:
have_compiler will try current dir if tmpdir fails

Modified: ExtUtils-CBuilder/trunk/Changes
==============================================================================
--- ExtUtils-CBuilder/trunk/Changes	(original)
+++ ExtUtils-CBuilder/trunk/Changes	Sat Jun 27 16:26:09 2009
@@ -1,6 +1,15 @@
 Revision history for Perl extension ExtUtils::CBuilder.
 
-0.25_01 - 
+0.25_01 -
+
+ - 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
 
 0.25 - Fri Jun 26 16:18:13 EDT 2009
 

Modified: ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder.pm
==============================================================================
--- ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder.pm	(original)
+++ ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder.pm	Sat Jun 27 16:26:09 2009
@@ -130,7 +130,8 @@
 
 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
 

Modified: ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder/Base.pm
==============================================================================
--- ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder/Base.pm	(original)
+++ ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder/Base.pm	Sat Jun 27 16:26:09 2009
@@ -117,22 +117,36 @@
   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 $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 ($obj_file, @lib_files);
-  eval {
-    local $^W = 0;
-    $obj_file = $self->compile(source => $tmpfile);
-    @lib_files = $self->link(objects => $obj_file, module_name => 'compilet');
-  };
-  my $result = $@ ? 0 : 1;
+    {
+      my $FH = IO::File->new("> $tmpfile") or die "Can't create $tmpfile: $!";
+      print $FH "int boot_compilet() { return 1; }\n";
+    }
 
-  foreach (grep defined, $tmpfile, $obj_file, @lib_files) {
-    1 while unlink;
+    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 $self->{have_compiler} = $result;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.