Skip to content

Commit 9c1cd8c

Browse files
committed
Cache is_make_type
1 parent 45d80dc commit 9c1cd8c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/ExtUtils/MM_Any.pm

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,28 @@ Returns true if C<<$self->make>> is the given type; possibilities are:
205205
206206
=cut
207207

208+
my %maketype2true;
209+
# undocumented - so t/cd.t can still do its thing
210+
sub _clear_maketype_cache { %maketype2true = () }
211+
208212
sub is_make_type {
209213
my($self, $type) = @_;
214+
return $maketype2true{$type} if defined $maketype2true{$type};
210215
(undef, undef, my $make_basename) = $self->splitpath($self->make);
211-
return 1 if $make_basename =~ /\b$type\b/i; # executable's filename
212-
return 0 if $make_basename =~ /\b(dmake|nmake)\b/i; # Never fall through for dmake/nmake
216+
return $maketype2true{$type} = 1
217+
if $make_basename =~ /\b$type\b/i; # executable's filename
218+
return $maketype2true{$type} = 0
219+
if $make_basename =~ /\b(dmake|nmake|gmake)\b/i; # Never fall through for dmake/nmake/gmake
213220
# now have to run with "-v" and guess
214221
my $redirect = $self->can_redirect_error ? '2>&1' : '';
215222
my $make = $self->make || $self->{MAKE};
216223
my $minus_v = `"$make" -v $redirect`;
217-
return 1 if $type eq 'gmake' and $minus_v =~ /GNU make/i;
218-
return 1 if $type eq 'bsdmake'
224+
return $maketype2true{$type} = 1
225+
if $type eq 'gmake' and $minus_v =~ /GNU make/i;
226+
return $maketype2true{$type} = 1
227+
if $type eq 'bsdmake'
219228
and $minus_v =~ /^usage: make \[-BeikNnqrstWwX\]/im;
220-
0; # it wasn't whatever you asked
229+
$maketype2true{$type} = 0; # it wasn't whatever you asked
221230
}
222231

223232

t/cd.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ my @cd_args = ($dir, "command1", "command2");
2727

2828
{
2929
local *make = sub { "nmake" };
30+
$mm->_clear_maketype_cache;
3031

3132
my @dirs = (File::Spec->updir) x 2;
3233
my $expected_updir = File::Spec->catdir(@dirs);
@@ -40,6 +41,7 @@ qq{cd $dir
4041

4142
{
4243
local *make = sub { "dmake" };
44+
$mm->_clear_maketype_cache;
4345

4446
::is $mm->cd(@cd_args),
4547
qq{cd $dir && command1

0 commit comments

Comments
 (0)