Skip to content

Commit e04e45f

Browse files
committed
Win32 Liblist stop false positives on multi-LIB (RT-53676)
1 parent eb4427b commit e04e45f

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

lib/ExtUtils/Liblist/Kid.pm

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,9 @@ sub _win32_ext {
373373

374374
sub _win32_make_lib_search_list {
375375
my ( $potential_libs, $verbose ) = @_;
376-
377-
# If Config.pm defines a set of default libs, we always
378-
# tack them on to the user-supplied list, unless the user
379-
# specified :nodefault
380-
my $libs = $Config{'perllibs'};
381-
$potential_libs = join( ' ', $potential_libs, $libs ) if $libs and $potential_libs !~ /:nodefault/i;
382376
_debug( "Potential libraries are '$potential_libs':\n", $verbose );
383-
384377
$potential_libs =~ s,\\,/,g; # normalize to forward slashes
385-
386-
my @list = Text::ParseWords::quotewords( '\s+', 0, $potential_libs );
387-
388-
return @list;
378+
Text::ParseWords::quotewords( '\s+', 0, $potential_libs );
389379
}
390380

391381
sub _win32_default_search_paths {

lib/ExtUtils/MM_Any.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,9 +2432,9 @@ sub init_others {
24322432
$self->{LIBS} = $self->_fix_libs($self->{LIBS});
24332433

24342434
# Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
2435-
foreach my $libs ( @{$self->{LIBS}} ){
2435+
foreach my $libs ( @{$self->{LIBS}} ) {
24362436
$libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
2437-
my(@libs) = $self->extliblist($libs);
2437+
my @libs = $self->extliblist($libs);
24382438
if (grep $_, @libs[0..2]) {
24392439
# LD_RUN_PATH now computed by ExtUtils::Liblist
24402440
@$self{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS LD_RUN_PATH)} = @libs;

lib/ExtUtils/MM_Win32.pm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Using \ for Windows, except for "gmake" where it is /.
123123
sub init_DIRFILESEP {
124124
my($self) = shift;
125125

126-
# The ^ makes sure its not interpreted as an escape in nmake
126+
# The ^ makes sure it's not interpreted as an escape in nmake
127127
$self->{DIRFILESEP} = $self->is_make_type('nmake') ? '^\\' :
128128
$self->is_make_type('dmake') ? '\\\\' :
129129
$self->is_make_type('gmake') ? '/'
@@ -165,13 +165,26 @@ Adjustments are made for Borland's quirks needing -L to come first.
165165
166166
=cut
167167

168+
my @LIBS_VARNAMES = qw(EXTRALIBS BSLOADLIBS LDLOADLIBS LD_RUN_PATH);
168169
sub init_others {
169170
my $self = shift;
170171

171172
$self->{LD} ||= 'link';
172173
$self->{AR} ||= 'lib';
173174

174175
$self->SUPER::init_others;
176+
# If Config.pm defines a set of default libs,
177+
# add them to EXTRALIBS, BSLOADLIBS and LDLOADLIBS, unless the user
178+
# specified :nodefault or gave no LIBS
179+
if (grep /\S/ && !/:nodefault/i, @{$self->{LIBS}}) {
180+
my @libs = $self->extliblist($Config{perllibs});
181+
for my $ind (0..$#LIBS_VARNAMES) {
182+
next unless my $to_add = $libs[$ind];
183+
my $varname = $LIBS_VARNAMES[$ind];
184+
$self->{$varname} .= ' ' if $self->{$varname};
185+
$self->{$varname} .= $to_add;
186+
}
187+
}
175188

176189
$self->{LDLOADLIBS} ||= $Config{libs};
177190
# -Lfoo must come first for Borland, so we put it in LDDLFLAGS

t/Liblist_Kid.t

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use File::Spec;
77
use Cwd;
88
use File::Temp qw[tempdir];
99

10+
use ExtUtils::MakeMaker;
1011
use MakeMaker::Test::Utils;
1112

1213
# Liblist wants to be an object which has File::Spec capabilities, so we
@@ -42,7 +43,7 @@ test_kid_win32() if $OS eq 'win32';
4243
# system configuration does not affect the test results.
4344

4445
sub conf_reset {
45-
my @save_keys = qw{ so dlsrc osname };
46+
my @save_keys = qw{ so dlsrc osname make };
4647
my %save_config;
4748
@save_config{ @save_keys } = @Config{ @save_keys };
4849
%Config = %save_config;
@@ -129,7 +130,7 @@ sub test_kid_unix_os2 {
129130
my @out = _ext( '-L. -lfoo' );
130131
my $qlibre = qr/-L[^"]+\s+-lfoo/;
131132
like( $out[0], $qlibre, 'existing file results in quoted extralibs' );
132-
like( $out[2], $qlibre, 'existing file results in quotes ldloadlibs' );
133+
like( $out[2], $qlibre, 'existing file results in quoted ldloadlibs' );
133134
ok $out[3], 'existing file results in true LD_RUN_PATH';
134135
is_deeply [ _ext( '-L. -lnotthere' ) ], [ ('') x 4 ], 'non-present lib = empty';
135136
my $curr_dirspace = File::Spec->rel2abs( 'di r' );
@@ -140,6 +141,18 @@ sub test_kid_unix_os2 {
140141
my @got = _ext( '-ldir_test' );
141142
is_deeply \@got, [ '-ldir_test', '', '-ldir_test', 'di r' ], 'Config.libpth directories with spaces work' or diag explain \@got;
142143
}
144+
my $mm = WriteMakefile(
145+
NAME => 'Big::Dummy',
146+
VERSION => '1.00',
147+
LIBS => ['-L. -lfoo'],
148+
);
149+
like $mm->{LDLOADLIBS}, $qlibre, 'single LIBS works';
150+
$mm = WriteMakefile(
151+
NAME => 'Big::Dummy',
152+
VERSION => '1.00',
153+
LIBS => ['-L. -lnotthere', '-L. -lfoo'],
154+
);
155+
like $mm->{LDLOADLIBS}, $qlibre, 'two LIBS correctly gets second';
143156
}
144157

145158
sub test_kid_win32 {
@@ -178,10 +191,24 @@ sub test_kid_win32 {
178191
is_deeply( [ _ext( qq{"-Ldir" dir_test} ) ], [ double(quote("$curr\\dir\\dir_test.lib"), '') ], 'relative -L directories work' );
179192
is_deeply( [ _ext( '-L"di r" dir_test' ) ], [ double(quote($curr . '\di r\dir_test.lib'), '') ], '-L directories with spaces work' );
180193

181-
$Config{perllibs} = 'pl';
182-
is_deeply( [ _ext( 'unreal_test' ) ], [ double(quote('pl.lib'), '') ], '$Config{perllibs} adds extra libs to be searched' );
183-
is_deeply( [ _ext( 'unreal_test :nodefault' ) ], [ ('') x 4 ], ':nodefault flag prevents $Config{perllibs} from being added' );
184-
delete $Config{perllibs};
194+
{
195+
local $Config{perllibs} = 'pl';
196+
is_deeply( [ _ext( 'unreal_test' ) ], [ ('') x 4 ], '_ext not add $Config{perllibs}' );
197+
is_deeply( [ _ext( 'unreal_test :nodefault' ) ], [ ('') x 4 ], ':nodefault flag prevents $Config{perllibs} from being added' );
198+
my $mm = WriteMakefile(
199+
NAME => 'Big::Dummy',
200+
VERSION => '1.00',
201+
LIBS => ['-l_test'],
202+
);
203+
my $exp = '"lib_test.lib" "pl.lib"';
204+
is $mm->{LDLOADLIBS}, $exp, 'single LIBS works';
205+
$mm = WriteMakefile(
206+
NAME => 'Big::Dummy',
207+
VERSION => '1.00',
208+
LIBS => ['-L. -lnotthere', '-l_test'],
209+
);
210+
is $mm->{LDLOADLIBS}, $exp, 'two LIBS correctly gets second';
211+
}
185212

186213
{
187214
local $Config{libpth} = 'libpath';
@@ -219,6 +246,4 @@ sub test_kid_win32 {
219246

220247
$ENV{LIB} = 'vc';
221248
is_deeply( [ _ext( 'vctest.lib' ) ], [ double(quote('vc\vctest.lib'), '') ], '[vc] $ENV{LIB} adds search paths' );
222-
223-
return;
224249
}

0 commit comments

Comments
 (0)