Skip Menu |

This queue is for tickets about the Devel-CheckLib CPAN distribution.

Report information
The Basics
Id: 46044
Status: resolved
Priority: 0/
Queue: Devel-CheckLib

People
Owner: Nobody in particular
Requestors: daxim [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.5
Fixed in: (no value)



Subject: [PATCH] parse @ARGV like EU::MM
Until recently, I used to be able to build File::LibMagic against my private installation of libmagic, thus: perl Makefile.PL LIBS=-L$HOME/local/lib INC=-I$HOME/local/include Now the author added Devel::CheckLib to his Makefile.PL and so it erroneously aborts: Can't link/include 'magic.h', 'magic' The reason for that is that Devel::CheckLib does not check the command-line parameters like EU::MM does. The attached patch fixes this. It applies cleanly against 0.5 with: git apply 0001-parse-ARGV-like-EU-MM.patch
Subject: 0001-parse-ARGV-like-EU-MM.patch
From 6253f023415f2beaf971b8571320855bcebdabcf Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Lars=20D=C9=AA=E1=B4=87=E1=B4=84=E1=B4=8B=E1=B4=8F=E1=B4=A1=20=E8=BF=AA=E6=8B=89=E6=96=AF?= <daxim@cpan.org> Date: Wed, 13 May 2009 19:41:02 +0200 Subject: [PATCH] parse @ARGV like EU::MM --- lib/Devel/CheckLib.pm | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Devel/CheckLib.pm b/lib/Devel/CheckLib.pm index d7167f4..2a3abad 100644 --- a/lib/Devel/CheckLib.pm +++ b/lib/Devel/CheckLib.pm @@ -149,14 +149,27 @@ sub assert_lib { if $args{incpath}; # work-a-like for Makefile.PL's LIBS and INC arguments + # if given as command-line argument, append to %args + for my $arg (@ARGV) { + for my $mm_attr_key qw(LIBS INC) { + if (my ($mm_attr_value) = $arg =~ /\A $mm_attr_key = (.*)/x) { + # it is tempting to put some \s* into the expression, but the + # MM command-line parser only accepts LIBS etc. followed by =, + # so we should not be any more lenient with whitespace than that + $args{$mm_attr_key} .= " $mm_attr_value"; + } + } + } + + # using special form of split to trim whitespace if(defined($args{LIBS})) { - foreach my $arg (split(/\s+/, $args{LIBS})) { + foreach my $arg (split(' ', $args{LIBS})) { die("LIBS argument badly-formed: $arg\n") unless($arg =~ /^-l/i); push @{$arg =~ /^-l/ ? \@libs : \@libpaths}, substr($arg, 2); } } if(defined($args{INC})) { - foreach my $arg (split(/\s+/, $args{INC})) { + foreach my $arg (split(' ', $args{INC})) { die("INC argument badly-formed: $arg\n") unless($arg =~ /^-I/); push @incpaths, substr($arg, 2); } -- 1.6.3
On Wed May 13 13:48:06 2009, DAXIM wrote: Show quoted text
> The reason for that is that Devel::CheckLib does not check the > command-line parameters like EU::MM does. The attached patch fixes this.
Thanks, applied, will be in the next release just as soon as I've written some tests for it. (If you have anything I could use for that, it would be very useful).
Regarding tests, I'm testing the command line thus (in t/cmdline-LIBS-INC.t, now in the git repo here: http://www.cantrell.org.uk/cgit/cgit.cgi/perlmodules/tree/Devel-CheckLib/t/cmdline-LIBS-INC.t) ok 1 - linked OK: LIBS=-lm ok 2 - linked OK: LIBS=-lm, LIBS=-lbazbam, LIBS=-L/tmp/Ip7ADMxxno ok 3 - linked OK: "LIBS=-lm -lbazbam -L/tmp/Ip7ADMxxno" (libbazbam is something that I build just for testing, in /tmp/whatever) The first is just a sanity-check. The second passes three LIBS=... arguments on the command line (is this legal?), the third passes all three in one go. Does that look sensible? Still need to add tests for INC ...
Here, I've refactored the repetition and added some edge-cases for whitespace. I've played a bit around with multiple INC for EU::MM on the command-line and it only seems to pick up the last one in order. It's your call whether you want to support it in D::C. No idea about multiple LIBS. Schwern and you have much more expertise than me.
diff --git a/t/cmdline-LIBS-INC.t b/t/cmdline-LIBS-INC.t index 5ae72f0..7d576cb 100644 --- a/t/cmdline-LIBS-INC.t +++ b/t/cmdline-LIBS-INC.t @@ -19,7 +19,7 @@ if($@ =~ /Couldn't find your C compiler/) { #' eval "use Helper qw(create_testlib)"; if($libdir = create_testlib("bazbam")) { - plan tests => 3; + plan tests => 5; } else { plan skip_all => "Couldn't build a library to test against"; }; @@ -34,50 +34,28 @@ my $runtime = '-l'.( : 'm' # default to Unix-style ); -my $rval = undef; -my @args = (qq{LIBS=$runtime}); -capture( - sub { $rval = system( - $Config{perlpath}, - '-Mblib', - '-MDevel::CheckLib', - '-e', - "print @ARGV;assert_lib(debug => $debug)", - @args - )}, - \$stdout, - \$stderr -); -ok($stderr eq '' && defined($rval) && $rval == 0, "linked OK: ".join(', ', @args)) || diag("\tSTDOUT: $stdout\n\tSTDERR: $stderr\n"); - -$rval = undef; -@args = map { "LIBS=$_" } ($runtime, '-lbazbam', "-L$libdir"); -capture( - sub { $rval = system( - $Config{perlpath}, - '-Mblib', - '-MDevel::CheckLib', - '-e', - "print @ARGV;assert_lib(debug => $debug)", - @args - )}, - \$stdout, - \$stderr -); -ok($stderr eq '' && defined($rval) && $rval == 0, "linked OK: ".join(', ', @args)) || diag("\tSTDOUT: $stdout\n\tSTDERR: $stderr\n"); - -$rval = undef; -@args = (qq{"LIBS=$runtime -lbazbam -L$libdir"}); -capture( - sub { $rval = system( - $Config{perlpath}, - '-Mblib', - '-MDevel::CheckLib', - '-e', - "print @ARGV;assert_lib(debug => $debug)", - @args - )}, - \$stdout, - \$stderr -); -ok($stderr eq '' && defined($rval) && $rval == 0, "linked OK: ".join(', ', @args)) || diag("\tSTDOUT: $stdout\n\tSTDERR: $stderr\n"); +for my $args_aref ( + [qq{LIBS=$runtime}], + [map {"LIBS=$_"} ($runtime, '-lbazbam', "-L$libdir")], + [qq{"LIBS=$runtime -lbazbam -L$libdir"}], + [" 'LIBS= $runtime ' ", " 'LIBS= -lbazbam ' ", " 'LIBS= -L$libdir ' ",], + [" 'LIBS= $runtime -lbazbam -L$libdir ' "], +) { + my $rval; + my @args = @{$args_aref}; + capture( + sub { $rval = system( + $Config{perlpath}, + '-Mblib', + '-MDevel::CheckLib', + '-e', + "print @ARGV;assert_lib(debug => $debug)", + @args + )}, + \$stdout, + \$stderr + ); + ok($stderr eq '' && defined($rval) && $rval == 0, + "linked OK: " . join(', ', @args)) + || diag("\tSTDOUT: $stdout\n\tSTDERR: $stderr\n"); +}
Version 0.6 on it sway to the CPAN. Will refactor tests later :-)