Skip to content

Commit be1b58e

Browse files
committed
Liblist work with Config.libpth in place-with-space
1 parent 2c61b35 commit be1b58e

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

lib/ExtUtils/Liblist/Kid.pm

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,29 @@ use File::Basename;
2020
use File::Spec;
2121

2222
sub ext {
23-
if ( $^O eq 'VMS' ) { return &_vms_ext; }
24-
elsif ( $^O eq 'MSWin32' ) { return &_win32_ext; }
25-
else { return &_unix_os2_ext; }
23+
if ( $^O eq 'VMS' ) { goto &_vms_ext; }
24+
elsif ( $^O eq 'MSWin32' ) { goto &_win32_ext; }
25+
else { goto &_unix_os2_ext; }
26+
}
27+
28+
sub _space_dirs_split {
29+
my ($libpth) = @_;
30+
return if !length $libpth;
31+
my (@chunks, @ret);
32+
push @chunks, [$1,$2] while $libpth =~ /(\S+)(\s*)/g;
33+
CHUNK: while (@chunks) {
34+
my ($c, $ind) = (shift(@chunks), 0);
35+
if (-d $c->[0]) { push @ret, $c->[0]; next CHUNK; }
36+
my $sofar = join '', @$c;
37+
while ($ind < @chunks) {
38+
my ($this_word, $this_space) = @{ $chunks[$ind] };
39+
$sofar .= $this_word;
40+
if (-d $sofar) { push @ret, $sofar; next CHUNK; }
41+
$sofar .= $this_space;
42+
$ind++;
43+
}
44+
}
45+
@ret;
2646
}
2747

2848
sub _unix_os2_ext {
@@ -51,18 +71,18 @@ sub _unix_os2_ext {
5171

5272
require Text::ParseWords;
5373

54-
my ( @searchpath ); # from "-L/path" entries in $potential_libs
55-
my ( @libpath ) = Text::ParseWords::shellwords( $Config{'libpth'} || '' );
74+
my @searchpath; # from "-L/path" entries in $potential_libs
75+
my @libpath = _space_dirs_split($Config{libpth} || '');
5676
my ( @ldloadlibs, @bsloadlibs, @extralibs, @ld_run_path, %ld_run_path_seen );
5777
my ( @libs, %libs_seen );
5878
my ( $fullname, @fullname );
5979
my ( $pwd ) = cwd(); # from Cwd.pm
6080
my ( $found ) = 0;
61-
if ($Config{gccversion}) {
62-
chomp(my @incpath = grep s/^ //, grep { /^#include </ .. /^End of search / } `$Config{cc} -E -v - </dev/null 2>&1 >/dev/null`);
63-
unshift @libpath, map { s{/include[^/]*}{/lib}; $_ } @incpath
64-
}
65-
@libpath = grep -d, @libpath;
81+
if ($Config{gccversion}) {
82+
chomp(my @incpath = grep s/^ //, grep { /^#include </ .. /^End of search / } `$Config{cc} -E -v - </dev/null 2>&1 >/dev/null`);
83+
unshift @libpath, map { s{/include[^/]*}{/lib}; $_ } @incpath
84+
}
85+
@libpath = grep -d, @libpath;
6686

6787
if ($^O eq 'darwin') {
6888
# 'escape' Mach-O ld -framework and -F flags, so they aren't dropped later on
@@ -374,7 +394,7 @@ sub _win32_default_search_paths {
374394
my $libpth = $Config{'libpth'} || '';
375395
$libpth =~ s,\\,/,g; # normalize to forward slashes
376396

377-
my @libpath = Text::ParseWords::quotewords( '\s+', 0, $libpth );
397+
my @libpath = _space_dirs_split($libpth);
378398
push @libpath, "$Config{installarchlib}/CORE"; # add "$Config{installarchlib}/CORE" to default search path
379399

380400
push @libpath, split /;/, $ENV{LIB} if $VC and $ENV{LIB};

lib/ExtUtils/MM_Any.pm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,10 +2435,9 @@ sub init_others {
24352435
foreach my $libs ( @{$self->{LIBS}} ){
24362436
$libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
24372437
my(@libs) = $self->extliblist($libs);
2438-
if ($libs[0] or $libs[1] or $libs[2]){
2438+
if (grep $_, @libs[0..2]) {
24392439
# LD_RUN_PATH now computed by ExtUtils::Liblist
2440-
($self->{EXTRALIBS}, $self->{BSLOADLIBS},
2441-
$self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
2440+
@$self{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS LD_RUN_PATH)} = @libs;
24422441
last;
24432442
}
24442443
}

t/Liblist_Kid.t

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ sub conf_reset {
4545
my @save_keys = qw{ so dlsrc osname };
4646
my %save_config;
4747
@save_config{ @save_keys } = @Config{ @save_keys };
48-
delete $Config{$_} for keys %Config;
4948
%Config = %save_config;
5049
# The following are all used and always are defined in the real world.
5150
# Define them to something here to avoid spewing uninitialized value warnings.
@@ -136,6 +135,11 @@ sub test_kid_unix_os2 {
136135
my $curr_dirspace = File::Spec->rel2abs( 'di r' );
137136
my $cmd_frag = '-L'.quote($curr_dirspace) . ' -ldir_test';
138137
is_deeply [ _ext( '-L"di r" -ldir_test' ) ], [ $cmd_frag, '', $cmd_frag, $curr_dirspace ], '-L directories with spaces work';
138+
{
139+
local $Config{libpth} = 'di r';
140+
my @got = _ext( '-ldir_test' );
141+
is_deeply \@got, [ '-ldir_test', '', '-ldir_test', 'di r' ], 'Config.libpth directories with spaces work' or diag explain \@got;
142+
}
139143
}
140144

141145
sub test_kid_win32 {
@@ -147,7 +151,7 @@ sub test_kid_win32 {
147151
is_deeply( [ _ext( 'c_test' ) ], [ double(quote('lib\CORE\c_test.lib'), '') ], '$Config{installarchlib}/CORE is the default search dir aside from cwd' );
148152
is_deeply( [ _ext( 'double' ) ], [ double(quote('double.lib'), '') ], 'once an instance of a lib is found, the search stops' );
149153
is_deeply( [ _ext( 'test.lib' ) ], [ double(quote('test.lib'), '') ], 'the extension is not tacked on twice' );
150-
is_deeply( [ _ext( 'test.a' ) ], [ double(quote('test.a.lib'), '') ], 'but it will be tacked onto filenamess with other kinds of library extension' );
154+
is_deeply( [ _ext( 'test.a' ) ], [ double(quote('test.a.lib'), '') ], 'but it will be tacked onto filenames with other kinds of library extension' );
151155
is_deeply( [ _ext( 'test test2' ) ], [ double(quote(qw(test.lib test2.lib)), '') ], 'multiple existing files end up separated by spaces' );
152156
is_deeply( [ _ext( 'test test2 unreal_test' ) ], [ double(quote(qw(test.lib test2.lib)), '') ], "some existing files don't cause false positives" );
153157
is_deeply( [ _ext( '-l_test' ) ], [ double(quote('lib_test.lib'), '') ], 'prefixing a lib with -l triggers a second search with prefix "lib" when gcc is not in use' );
@@ -179,9 +183,13 @@ sub test_kid_win32 {
179183
is_deeply( [ _ext( 'unreal_test :nodefault' ) ], [ ('') x 4 ], ':nodefault flag prevents $Config{perllibs} from being added' );
180184
delete $Config{perllibs};
181185

182-
$Config{libpth} = 'libpath';
183-
is_deeply( [ _ext( 'lp_test' ) ], [ double(quote('libpath\lp_test.lib'), '') ], '$Config{libpth} adds extra search paths' );
184-
delete $Config{libpth};
186+
{
187+
local $Config{libpth} = 'libpath';
188+
is_deeply( [ _ext( 'lp_test' ) ], [ double(quote('libpath\lp_test.lib'), '') ], '$Config{libpth} adds extra search paths' );
189+
$Config{libpth} = 'di r';
190+
my @got = _ext( '-ldir_test' );
191+
is_deeply \@got, [double('"di r\\dir_test.lib"', '')], 'Config.libpth directories with spaces work' or diag explain \@got;
192+
}
185193

186194
$Config{lib_ext} = '.meep';
187195
is_deeply( [ _ext( 'test' ) ], [ double(quote('test.meep'), '') ], '$Config{lib_ext} changes the lib extension to be searched for' );

0 commit comments

Comments
 (0)