Blame SOURCES/Module-Build-0.4224-Do-not-need-a-compiler-if-c_source-is-an-empty-list.patch

767212
From 6b096ea5670ed291abac632b296222b56d9fadb4 Mon Sep 17 00:00:00 2001
767212
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
767212
Date: Thu, 1 Mar 2018 14:44:40 +0100
767212
Subject: [PATCH] Do not need a compiler if c_source is an empty list
767212
MIME-Version: 1.0
767212
Content-Type: text/plain; charset=UTF-8
767212
Content-Transfer-Encoding: 8bit
767212
767212
c_source used to be string, then it allowed a reference to an array.
767212
But in case the array was empty, auto_require() still enabled
767212
needs_compiler property and thus implied probing a compiler and
767212
a failure if none was available.
767212
767212
Minilla generates these Build.PLs for pure-Perl distributions. See
767212
KAZUHO/Server-Starter-0.34.
767212
767212
This patch makes Module::Build not require C compiler for
767212
c_source = [].
767212
767212
Petr Písař: Ported to 0.4224.
767212
767212
Signed-off-by: Petr Písař <ppisar@redhat.com>
767212
---
767212
 lib/Module/Build/API.pod      |  8 ++++----
767212
 lib/Module/Build/Base.pm      |  6 +++++-
767212
 t/properties/needs_compiler.t | 46 ++++++++++++++++++++++++++++++++++++++++---
767212
 3 files changed, 52 insertions(+), 8 deletions(-)
767212
767212
diff --git a/lib/Module/Build/API.pod b/lib/Module/Build/API.pod
767212
index cd2021a..c9be539 100644
767212
--- a/lib/Module/Build/API.pod
767212
+++ b/lib/Module/Build/API.pod
767212
@@ -209,10 +209,10 @@ created by Module::Build.
767212
 
767212
 [version 0.04]
767212
 
767212
-An optional C<c_source> argument specifies a directory which contains
767212
-C source files that the rest of the build may depend on.  Any C<.c>
767212
-files in the directory will be compiled to object files.  The
767212
-directory will be added to the search path during the compilation and
767212
+An optional C<c_source> argument specifies a directory or a reference to array
767212
+of directories which contain C source files that the rest of the build may
767212
+depend on.  Any C<.c> files in the directory will be compiled to object files.
767212
+The directory will be added to the search path during the compilation and
767212
 linking phases of any C or XS files.
767212
 
767212
 [version 0.3604]
767212
diff --git a/lib/Module/Build/Base.pm b/lib/Module/Build/Base.pm
767212
index 984810a..a29c664 100644
767212
--- a/lib/Module/Build/Base.pm
767212
+++ b/lib/Module/Build/Base.pm
767212
@@ -1520,7 +1520,11 @@ sub auto_require {
767212
     if ( $self->pureperl_only && $self->allow_pureperl ) {
767212
       $self->needs_compiler( 0 );
767212
     } else {
767212
-      $self->needs_compiler( keys %$xs_files || defined $self->c_source );
767212
+      $self->needs_compiler( keys %$xs_files ||
767212
+        ( defined $self->c_source &&
767212
+          ( ref($self->c_source) ne 'ARRAY' || @{$self->c_source} )
767212
+        )
767212
+      );
767212
     }
767212
   }
767212
   if ($self->needs_compiler) {
767212
diff --git a/t/properties/needs_compiler.t b/t/properties/needs_compiler.t
767212
index f616dfc..c76d38f 100644
767212
--- a/t/properties/needs_compiler.t
767212
+++ b/t/properties/needs_compiler.t
767212
@@ -5,7 +5,7 @@ use lib 't/lib';
767212
 use MBTest;
767212
 use DistGen;
767212
 
767212
-plan tests => 19;
767212
+plan tests => 27;
767212
 
767212
 # Ensure any Module::Build modules are loaded from correct directory
767212
 blib_load('Module::Build');
767212
@@ -24,7 +24,7 @@ ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
767212
 );
767212
 
767212
 #--------------------------------------------------------------------------#
767212
-# try with c_source
767212
+# try with c_source as a string
767212
 #--------------------------------------------------------------------------#
767212
 $dist->change_build_pl({
767212
     module_name => $dist->name,
767212
@@ -34,7 +34,7 @@ $dist->change_build_pl({
767212
 $dist->regen;
767212
 stderr_of(sub {
767212
   ok( $mb = $dist->new_from_context,
767212
-    "Build.PL with c_source"
767212
+    "Build.PL with string c_source"
767212
   );
767212
 });
767212
 is( $mb->c_source, 'src', "c_source is set" );
767212
@@ -44,6 +44,46 @@ ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
767212
 );
767212
 
767212
 #--------------------------------------------------------------------------#
767212
+# try with c_source as an array
767212
+#--------------------------------------------------------------------------#
767212
+$dist->change_build_pl({
767212
+    module_name => $dist->name,
767212
+    license => 'perl',
767212
+    c_source => ['src'],
767212
+});
767212
+$dist->regen;
767212
+stderr_of(sub {
767212
+  ok( $mb = $dist->new_from_context,
767212
+    "Build.PL with non-empty array c_source"
767212
+  );
767212
+});
767212
+is_deeply( $mb->c_source, ['src'], "c_source is set" );
767212
+ok( $mb->needs_compiler, "needs_compiler is true" );
767212
+ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
767212
+  "ExtUtils::CBuilder was added to build_requires"
767212
+);
767212
+
767212
+#--------------------------------------------------------------------------#
767212
+# try with c_source as an empty array
767212
+#--------------------------------------------------------------------------#
767212
+$dist->change_build_pl({
767212
+    module_name => $dist->name,
767212
+    license => 'perl',
767212
+    c_source => [],
767212
+});
767212
+$dist->regen;
767212
+stderr_of(sub {
767212
+  ok( $mb = $dist->new_from_context,
767212
+    "Build.PL with empty array c_source"
767212
+  );
767212
+});
767212
+is_deeply( $mb->c_source, [], "c_source is set" );
767212
+ok( ! $mb->needs_compiler, "needs_compiler is false" );
767212
+ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
767212
+  "ExtUtils::CBuilder is not in build_requires"
767212
+);
767212
+
767212
+#--------------------------------------------------------------------------#
767212
 # try with xs files
767212
 #--------------------------------------------------------------------------#
767212
 $dist = DistGen->new(dir => 'MBTest', xs => 1);
767212
-- 
767212
2.13.6
767212