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