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