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