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