Skip to content

Commit a70ef13

Browse files
ppisarLeont
authored andcommitted
Do not require a compiler if c_source is an empty list
1 parent 7e5aefa commit a70ef13

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

lib/Module/Build/API.pod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ created by Module::Build.
209209

210210
[version 0.04]
211211

212-
An optional C<c_source> argument specifies a directory which contains
213-
C source files that the rest of the build may depend on. Any C<.c>
214-
files in the directory will be compiled to object files. The
215-
directory will be added to the search path during the compilation and
212+
An optional C<c_source> argument specifies a directory or a reference to array
213+
of directories which contain C source files that the rest of the build may
214+
depend on. Any C<.c> files in the directory will be compiled to object files.
215+
The directory will be added to the search path during the compilation and
216216
linking phases of any C or XS files.
217217

218218
[version 0.3604]

lib/Module/Build/Base.pm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,11 @@ sub auto_require {
15201520
if ( $self->pureperl_only && $self->allow_pureperl ) {
15211521
$self->needs_compiler( 0 );
15221522
} else {
1523-
$self->needs_compiler( keys %$xs_files || defined $self->c_source );
1523+
$self->needs_compiler( keys %$xs_files ||
1524+
( defined $self->c_source &&
1525+
( ref($self->c_source) ne 'ARRAY' || @{$self->c_source} )
1526+
)
1527+
);
15241528
}
15251529
}
15261530
if ($self->needs_compiler) {

t/properties/needs_compiler.t

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use lib 't/lib';
55
use MBTest;
66
use DistGen;
77

8-
plan tests => 19;
8+
plan tests => 27;
99

1010
# Ensure any Module::Build modules are loaded from correct directory
1111
blib_load('Module::Build');
@@ -24,7 +24,7 @@ ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
2424
);
2525

2626
#--------------------------------------------------------------------------#
27-
# try with c_source
27+
# try with c_source as a string
2828
#--------------------------------------------------------------------------#
2929
$dist->change_build_pl({
3030
module_name => $dist->name,
@@ -34,7 +34,7 @@ $dist->change_build_pl({
3434
$dist->regen;
3535
stderr_of(sub {
3636
ok( $mb = $dist->new_from_context,
37-
"Build.PL with c_source"
37+
"Build.PL with string c_source"
3838
);
3939
});
4040
is( $mb->c_source, 'src', "c_source is set" );
@@ -43,6 +43,46 @@ ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
4343
"ExtUtils::CBuilder was added to build_requires"
4444
);
4545

46+
#--------------------------------------------------------------------------#
47+
# try with c_source as an array
48+
#--------------------------------------------------------------------------#
49+
$dist->change_build_pl({
50+
module_name => $dist->name,
51+
license => 'perl',
52+
c_source => ['src'],
53+
});
54+
$dist->regen;
55+
stderr_of(sub {
56+
ok( $mb = $dist->new_from_context,
57+
"Build.PL with non-empty array c_source"
58+
);
59+
});
60+
is_deeply( $mb->c_source, ['src'], "c_source is set" );
61+
ok( $mb->needs_compiler, "needs_compiler is true" );
62+
ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
63+
"ExtUtils::CBuilder was added to build_requires"
64+
);
65+
66+
#--------------------------------------------------------------------------#
67+
# try with c_source as an empty array
68+
#--------------------------------------------------------------------------#
69+
$dist->change_build_pl({
70+
module_name => $dist->name,
71+
license => 'perl',
72+
c_source => [],
73+
});
74+
$dist->regen;
75+
stderr_of(sub {
76+
ok( $mb = $dist->new_from_context,
77+
"Build.PL with empty array c_source"
78+
);
79+
});
80+
is_deeply( $mb->c_source, [], "c_source is set" );
81+
ok( ! $mb->needs_compiler, "needs_compiler is false" );
82+
ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
83+
"ExtUtils::CBuilder is not in build_requires"
84+
);
85+
4686
#--------------------------------------------------------------------------#
4787
# try with xs files
4888
#--------------------------------------------------------------------------#

0 commit comments

Comments
 (0)