r53949 - in /branches/upstream/libextutils-cchecker-perl/current: Changes META.yml Makefile.PL README lib/ExtUtils/CChecker.pm t/01run.t t/02assert.t

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Mon Mar 8 17:38:33 UTC 2010


Author: jawnsy-guest
Date: Mon Mar  8 17:38:25 2010
New Revision: 53949

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=53949
Log:
[svn-upgrade] Integrating new upstream version, libextutils-cchecker-perl (0.03)

Modified:
    branches/upstream/libextutils-cchecker-perl/current/Changes
    branches/upstream/libextutils-cchecker-perl/current/META.yml
    branches/upstream/libextutils-cchecker-perl/current/Makefile.PL
    branches/upstream/libextutils-cchecker-perl/current/README
    branches/upstream/libextutils-cchecker-perl/current/lib/ExtUtils/CChecker.pm
    branches/upstream/libextutils-cchecker-perl/current/t/01run.t
    branches/upstream/libextutils-cchecker-perl/current/t/02assert.t

Modified: branches/upstream/libextutils-cchecker-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libextutils-cchecker-perl/current/Changes?rev=53949&op=diff
==============================================================================
--- branches/upstream/libextutils-cchecker-perl/current/Changes (original)
+++ branches/upstream/libextutils-cchecker-perl/current/Changes Mon Mar  8 17:38:25 2010
@@ -1,4 +1,10 @@
 Revision history for ExtUtils-CChecker
+
+0.03    CHANGES:
+         * Support defining compiler symbols based on successful test runs,
+           so XS code can be conditional on it
+         * Line-terminate test C code to avoid (harmless) warnings from some
+           C compilers
 
 0.02    CHANGES:
          * Support automatic construction of a preconfigured Module::Build

Modified: branches/upstream/libextutils-cchecker-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libextutils-cchecker-perl/current/META.yml?rev=53949&op=diff
==============================================================================
--- branches/upstream/libextutils-cchecker-perl/current/META.yml (original)
+++ branches/upstream/libextutils-cchecker-perl/current/META.yml Mon Mar  8 17:38:25 2010
@@ -8,7 +8,7 @@
   Test::More: 0
 configure_requires:
   Module::Build: 0.36
-generated_by: 'Module::Build version 0.3601'
+generated_by: 'Module::Build version 0.3603'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -17,9 +17,9 @@
 provides:
   ExtUtils::CChecker:
     file: lib/ExtUtils/CChecker.pm
-    version: 0.02
+    version: 0.03
 requires:
   ExtUtils::CBuilder: 0
 resources:
   license: http://dev.perl.org/licenses/
-version: 0.02
+version: 0.03

Modified: branches/upstream/libextutils-cchecker-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libextutils-cchecker-perl/current/Makefile.PL?rev=53949&op=diff
==============================================================================
--- branches/upstream/libextutils-cchecker-perl/current/Makefile.PL (original)
+++ branches/upstream/libextutils-cchecker-perl/current/Makefile.PL Mon Mar  8 17:38:25 2010
@@ -1,4 +1,4 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.3601
+# Note: this file was auto-generated by Module::Build::Compat version 0.3603
     use Module::Build::Compat 0.02;
     
     Module::Build::Compat->run_build_pl(args => \@ARGV);

Modified: branches/upstream/libextutils-cchecker-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libextutils-cchecker-perl/current/README?rev=53949&op=diff
==============================================================================
--- branches/upstream/libextutils-cchecker-perl/current/README (original)
+++ branches/upstream/libextutils-cchecker-perl/current/README Mon Mar  8 17:38:25 2010
@@ -58,8 +58,8 @@
   $success = $cc->try_compile_run( %args )
   $success = $cc->try_compile_run( $source )
     Try to complile, link, and execute a C program whose source is given.
-    Returns true if the program compiled and linked, and exited sucessfully.
-    Returns false if any of these steps fail.
+    Returns true if the program compiled and linked, and exited
+    successfully. Returns false if any of these steps fail.
 
     Takes the following named arguments. If a single argument is given, that
     is taken as the source string.
@@ -76,6 +76,12 @@
     *       extra_linker_flags => ARRAY
 
             Optional. If specified, pass extra flags to the linker.
+
+    *       define => STRING
+
+            Optional. If specified, then the named symbol will be defined on
+            the C compiler commandline if the program ran successfully (by
+            passing an option "-D*SYMBOL*").
 
   $cc->assert_compile_run( %args )
     Calls "try_compile_run". If it fails, die with an "OS unsupported"
@@ -186,6 +192,55 @@
     "extra_linker_flags" value has been automatically passed into the new
     "Module::Build" object.
 
+  Testing For Optional Features
+    Sometimes a function or ability may be optionally provided by the OS, or
+    you may wish your module to be useable when only partial support is
+    provided, without requiring it all to be present. In these cases it is
+    traditional to detect the presence of this optional feature in the
+    Build.PL script, and define a symbol to declare this fact if it is
+    found. The XS code can then use this symbol to select between differing
+    implementations. For example, the Build.PL:
+
+     use Module::Build;
+     use ExtUtils::CChecker;
+
+     my $cc = ExtUtils::CChecker->new;
+
+     $cc->try_compile_run(
+        define => "HAVE_MANGO",
+        source => <<'EOF' );
+     #include <mango.h>
+     #include <unistd.h>
+     int main(void) {
+       if(mango() != 0)
+         exit(1);
+       exit(0);
+     }
+     EOF
+
+     $cc->new_module_build(
+        ...
+     )->create_build_script;
+
+    If the C code compiles and runs successfully, and exits with a true
+    status, the symbol "HAVE_MANGO" will be defined on the compiler
+    commandline. This allows the XS code to detect it, for example
+
+     int
+     mango()
+       CODE:
+     #ifdef HAVE_MANGO
+         RETVAL = mango();
+     #else
+         croak("mango() not implemented");
+     #endif
+       OUTPUT:
+         RETVAL
+
+    This module will then still compile even if the operating system lacks
+    this particular function. Trying to invoke the function at runtime will
+    simply throw an exception.
+
 AUTHOR
     Paul Evans <leonerd at leonerd.org.uk>
 

Modified: branches/upstream/libextutils-cchecker-perl/current/lib/ExtUtils/CChecker.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libextutils-cchecker-perl/current/lib/ExtUtils/CChecker.pm?rev=53949&op=diff
==============================================================================
--- branches/upstream/libextutils-cchecker-perl/current/lib/ExtUtils/CChecker.pm (original)
+++ branches/upstream/libextutils-cchecker-perl/current/lib/ExtUtils/CChecker.pm Mon Mar  8 17:38:25 2010
@@ -8,7 +8,7 @@
 use strict;
 use warnings;
 
-our $VERSION = '0.02';
+our $VERSION = '0.03';
 
 use Carp;
 
@@ -169,8 +169,8 @@
 =head2 $success = $cc->try_compile_run( $source )
 
 Try to complile, link, and execute a C program whose source is given. Returns
-true if the program compiled and linked, and exited sucessfully. Returns false
-if any of these steps fail.
+true if the program compiled and linked, and exited successfully. Returns
+false if any of these steps fail.
 
 Takes the following named arguments. If a single argument is given, that is
 taken as the source string.
@@ -188,6 +188,12 @@
 =item * extra_linker_flags => ARRAY
 
 Optional. If specified, pass extra flags to the linker.
+
+=item * define => STRING
+
+Optional. If specified, then the named symbol will be defined on the C
+compiler commandline if the program ran successfully (by passing an option
+C<-DI<SYMBOL>>).
 
 =back
 
@@ -245,6 +251,8 @@
    }
 
    unlink $test_exe;
+
+   push @{ $self->{extra_compiler_flags} }, "-D$args{define}" if defined $args{define};
 
    return 1;
 }
@@ -454,6 +462,56 @@
 By using the C<new_module_build> method, the detected C<extra_linker_flags>
 value has been automatically passed into the new C<Module::Build> object.
 
+=head2 Testing For Optional Features
+
+Sometimes a function or ability may be optionally provided by the OS, or you
+may wish your module to be useable when only partial support is provided,
+without requiring it all to be present. In these cases it is traditional to
+detect the presence of this optional feature in the F<Build.PL> script, and
+define a symbol to declare this fact if it is found. The XS code can then use
+this symbol to select between differing implementations. For example, the
+F<Build.PL>:
+
+ use Module::Build;
+ use ExtUtils::CChecker;
+
+ my $cc = ExtUtils::CChecker->new;
+
+ $cc->try_compile_run(
+    define => "HAVE_MANGO",
+    source => <<'EOF' );
+ #include <mango.h>
+ #include <unistd.h>
+ int main(void) {
+   if(mango() != 0)
+     exit(1);
+   exit(0);
+ }
+ EOF
+
+ $cc->new_module_build(
+    ...
+ )->create_build_script;
+
+If the C code compiles and runs successfully, and exits with a true status,
+the symbol C<HAVE_MANGO> will be defined on the compiler commandline. This
+allows the XS code to detect it, for example
+
+ int
+ mango()
+   CODE:
+ #ifdef HAVE_MANGO
+     RETVAL = mango();
+ #else
+     croak("mango() not implemented");
+ #endif
+   OUTPUT:
+     RETVAL
+
+This module will then still compile even if the operating system lacks this
+particular function. Trying to invoke the function at runtime will simply
+throw an exception.
+
 =head1 AUTHOR
 
 Paul Evans <leonerd at leonerd.org.uk>

Modified: branches/upstream/libextutils-cchecker-perl/current/t/01run.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libextutils-cchecker-perl/current/t/01run.t?rev=53949&op=diff
==============================================================================
--- branches/upstream/libextutils-cchecker-perl/current/t/01run.t (original)
+++ branches/upstream/libextutils-cchecker-perl/current/t/01run.t Mon Mar  8 17:38:25 2010
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 5;
+use Test::More tests => 6;
 
 use ExtUtils::CChecker;
 
@@ -10,7 +10,14 @@
 ok( defined $cc, 'defined $cc' );
 isa_ok( $cc, "ExtUtils::CChecker", '$cc' );
 
-ok( $cc->try_compile_run( "int main(void) { return 0; }" ), 'Trivial C program compiles and runs' );
-ok( !$cc->try_compile_run( "int foo bar splot" ), 'Broken C program does not compile and run' );
+ok( $cc->try_compile_run( "int main(void) { return 0; }\n" ), 'Trivial C program compiles and runs' );
+ok( !$cc->try_compile_run( "int foo bar splot\n" ), 'Broken C program does not compile and run' );
 
-ok( $cc->try_compile_run( source => "int main(void) { return 0; }" ), 'source named argument' );
+ok( $cc->try_compile_run( source => "int main(void) { return 0; }\n" ), 'source named argument' );
+
+$cc->try_compile_run(
+   source => "int main(void) { return 0; }\n",
+   define => "HAVE_C",
+);
+
+is_deeply( $cc->extra_compiler_flags, [ "-DHAVE_C" ], 'HAVE_C defined' );

Modified: branches/upstream/libextutils-cchecker-perl/current/t/02assert.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libextutils-cchecker-perl/current/t/02assert.t?rev=53949&op=diff
==============================================================================
--- branches/upstream/libextutils-cchecker-perl/current/t/02assert.t (original)
+++ branches/upstream/libextutils-cchecker-perl/current/t/02assert.t Mon Mar  8 17:38:25 2010
@@ -9,12 +9,12 @@
 my $cc = ExtUtils::CChecker->new;
 
 lives_ok(
-   sub { $cc->assert_compile_run( source => "int main(void) { return 0; }", diag => "OK source" ); },
+   sub { $cc->assert_compile_run( source => "int main(void) { return 0; }\n", diag => "OK source" ); },
    'Trivial C program'
 );
 
 throws_ok(
-   sub { $cc->assert_compile_run( source => "int foo bar splot", diag => "broken source" ); },
+   sub { $cc->assert_compile_run( source => "int foo bar splot\n", diag => "broken source" ); },
    qr/^OS unsupported - broken source$/,
    'Broken C program does not compile and run'
 );




More information about the Pkg-perl-cvs-commits mailing list