Author: dagolden
Date: Thu Jul 30 08:27:23 2009
New Revision: 13149

Added:
   ExtUtils-CBuilder/trunk/t/03-cplusplus.t   (contents, props changed)
Modified:
   ExtUtils-CBuilder/trunk/Changes
   ExtUtils-CBuilder/trunk/MANIFEST
   ExtUtils-CBuilder/trunk/MANIFEST.SKIP
   ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder.pm
   ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder/Base.pm
   ExtUtils-CBuilder/trunk/t/00-have-compiler.t

Log:
add cursory C++ support

Modified: ExtUtils-CBuilder/trunk/Changes
==============================================================================
--- ExtUtils-CBuilder/trunk/Changes     (original)
+++ ExtUtils-CBuilder/trunk/Changes     Thu Jul 30 08:27:23 2009
@@ -2,6 +2,9 @@
 
 0.26_04 - 
 
+ Enhancements:
+ - Added 'have_cplusplus()' method to check for C++ support
+
 0.2603 - Sat Jul 18 06:56:06 EDT 2009
 
  Bugs fixed:

Modified: ExtUtils-CBuilder/trunk/MANIFEST
==============================================================================
--- ExtUtils-CBuilder/trunk/MANIFEST    (original)
+++ ExtUtils-CBuilder/trunk/MANIFEST    Thu Jul 30 08:27:23 2009
@@ -18,3 +18,4 @@
 t/00-have-compiler.t
 t/01-basic.t
 t/02-link.t
+t/03-cplusplus.t

Modified: ExtUtils-CBuilder/trunk/MANIFEST.SKIP
==============================================================================
--- ExtUtils-CBuilder/trunk/MANIFEST.SKIP       (original)
+++ ExtUtils-CBuilder/trunk/MANIFEST.SKIP       Thu Jul 30 08:27:23 2009
@@ -37,3 +37,4 @@
 doc_check.pl$
 ^[^/]+\.patch$
 ^devtools
+^cover_db

Modified: ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder.pm
==============================================================================
--- ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder.pm    (original)
+++ ExtUtils-CBuilder/trunk/lib/ExtUtils/CBuilder.pm    Thu Jul 30 08:27:23 2009
@@ -133,6 +133,10 @@
 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 have_cplusplus
+
+Just like have_compiler but for C++ instead of C.
+
 =item compile
 
 Compiles a C source file and produces an object file.  The name of the
@@ -161,6 +165,11 @@
 this is not possible, as a string containing all the arguments
 together.
 
+=item C<C++>
+
+Specifies that the source file is a C++ source file and sets appropriate
+compiler flags
+
 =back
 
 The operation of this method is also affected by the

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       Thu Jul 30 
08:27:23 2009
@@ -98,6 +98,7 @@
   my @extra_compiler_flags = 
$self->split_like_shell($args{extra_compiler_flags});
   my @cccdlflags = $self->split_like_shell($cf->{cccdlflags});
   my @ccflags = $self->split_like_shell($cf->{ccflags});
+  push @ccflags, qw/-x c++/ if $args{'C++'};
   my @optimize = $self->split_like_shell($cf->{optimize});
   my @flags = (@include_dirs, @defines, @cccdlflags, @extra_compiler_flags,
               $self->arg_nolink,
@@ -114,7 +115,7 @@
 }
 
 sub have_compiler {
-  my ($self) = @_;
+  my ($self, $is_cplusplus) = @_;
   return $self->{have_compiler} if defined $self->{have_compiler};
 
   my $result;
@@ -125,6 +126,7 @@
     # don't clobber existing files (rare, but possible)
     my $rand = int(rand(2**31));
     my $tmpfile = File::Spec->catfile($dir, "compilet-$rand.c");
+    $tmpfile .= "c" if $is_cplusplus;
     if ( -e $tmpfile ) {
       redo DIR if $attempts--;
       next DIR;
@@ -132,13 +134,18 @@
 
     {
       my $FH = IO::File->new("> $tmpfile") or die "Can't create $tmpfile: $!";
-      print $FH "int boot_compilet() { return 1; }\n";
+      if ( $is_cplusplus ) {
+        print $FH "class Bogus { public: int boot_compilet() { return 1; } 
};\n";
+      }
+      else {
+        print $FH "int boot_compilet() { return 1; }\n";
+      }
     }
 
     my ($obj_file, @lib_files);
     eval {
       local $^W = 0;
-      $obj_file = $self->compile(source => $tmpfile);
+      $obj_file = $self->compile('C++' => $is_cplusplus, source => $tmpfile);
       @lib_files = $self->link(objects => $obj_file, module_name => 
'compilet');
     };
     $result = $@ ? 0 : 1;
@@ -152,6 +159,11 @@
   return $self->{have_compiler} = $result;
 }
 
+sub have_cplusplus {
+  push @_, 1;
+  goto &have_compiler;
+}
+
 sub lib_file {
   my ($self, $dl_file) = @_;
   $dl_file =~ s/\.[^.]+$//;

Modified: ExtUtils-CBuilder/trunk/t/00-have-compiler.t
==============================================================================
--- ExtUtils-CBuilder/trunk/t/00-have-compiler.t        (original)
+++ ExtUtils-CBuilder/trunk/t/00-have-compiler.t        Thu Jul 30 08:27:23 2009
@@ -22,22 +22,30 @@
   }
 }
 
-plan tests => 4;
+plan tests => 6;
 
 require_ok "ExtUtils::CBuilder";
 
 my $b = eval { ExtUtils::CBuilder->new(quiet => 1) };
 ok( $b, "got CBuilder object" ) or diag $@;
 
+my $bogus_path = 'djaadjfkadjkfajdf';
+my $run_perl = "$perl -e1 --";
 # test missing compiler
-$b->{config}{cc} = 'djaadjfkadjkfajdf';
-$b->{config}{ld} = 'djaadjfkadjkfajdf';
+$b->{config}{cc} = $bogus_path;
+$b->{config}{ld} = $bogus_path;
+
+$b->{have_compiler} = undef;
 is( $b->have_compiler, 0, "have_compiler: fake missing cc" );
+$b->{have_compiler} = undef;
+is( $b->have_cplusplus, 0, "have_cplusplus: fake missing c++" );
 
 # test found compiler
+$b->{config}{cc} = $run_perl;
+$b->{config}{ld} = $run_perl;
 $b->{have_compiler} = undef;
-$b->{config}{cc} = "$perl -e1 --";
-$b->{config}{ld} = "$perl -e1 --";
 is( $b->have_compiler, 1, "have_compiler: fake present cc" );
+$b->{have_compiler} = undef;
+is( $b->have_cplusplus, 1, "have_cpp_compiler: fake present c++" );
 
-
+# test missing cpp compiler

Added: ExtUtils-CBuilder/trunk/t/03-cplusplus.t
==============================================================================
--- (empty file)
+++ ExtUtils-CBuilder/trunk/t/03-cplusplus.t    Thu Jul 30 08:27:23 2009
@@ -0,0 +1,73 @@
+#! 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;
+BEGIN { 
+  if ($^O eq 'VMS') {
+    # So we can get the return value of system()
+    require vmsish;
+    import vmsish;
+  }
+}
+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, $lib_file);
+
+my $b = ExtUtils::CBuilder->new(quiet => $quiet);
+
+# test plan
+if ( ! $b->have_cplusplus ) {
+  plan skip_all => "no compiler available for testing";
+}
+else {
+  plan tests => 7;
+}
+
+ok $b, "created EU::CB object";
+
+ok $b->have_cplusplus, "have_cplusplus";
+
+$source_file = File::Spec->catfile('t', 'compilet.cc');
+{
+  local *FH;
+  open FH, "> $source_file" or die "Can't create $source_file: $!";
+  print FH "class Bogus { public: int boot_compilet() { return 1; } };\n";
+  close FH;
+}
+ok -e $source_file, "source file '$source_file' created";
+
+$object_file = $b->object_file($source_file);
+ok 1;
+
+is $object_file, $b->compile(source => $source_file, 'C++' => 1);
+
+$lib_file = $b->lib_file($object_file);
+ok 1;
+
+my ($lib, @temps) = $b->link(objects => $object_file,
+                             module_name => 'compilet');
+$lib =~ tr/"'//d;
+is $lib_file, $lib;
+
+for ($source_file, $object_file, $lib_file) {
+  tr/"'//d;
+  1 while unlink;
+}
+
+if ($^O eq 'VMS') {
+   1 while unlink 'COMPILET.LIS';
+   1 while unlink 'COMPILET.OPT';
+}
+

Reply via email to