This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl.c: Improve buildcustomize error message
authorFather Chrysostomos <sprout@cpan.org>
Mon, 1 Sep 2014 01:20:28 +0000 (18:20 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 1 Sep 2014 01:20:42 +0000 (18:20 -0700)
buildcustomize.pl was being loaded with generated code that died if
‘lib/buildcustomize.pl’ existed but do-file failed.  $@ was used as
the error message.

If the file does not exist (do-file searching @INC), then $@ is empty
and the error is in $!.  Before 9054c817, this is what we would get:

$ ./miniperl -T -Ilib -e0
Died.
BEGIN failed--compilation aborted.

I fixed that in 9054c817 so there would be no error (by adding an ini-
tial ‘./’ to the path.)

That message was rather baffling.  It would have been easier to track
down the cause if I had seen something like this:

$ ./miniperl -T -Ilib -e0
lib/buildcustomize.pl: No such file or directory.
BEGIN failed--compilation aborted.

This commit changes the generated code to output $! like that if $@ is
empty, in case a similar bug occurs again.

perl.c

diff --git a/perl.c b/perl.c
index 4af5348..b61e2ff 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -2070,10 +2070,9 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
                it should be reported immediately as a build failure.  */
            (void)Perl_av_create_and_unshift_one(aTHX_ &PL_preambleav,
                                                 Perl_newSVpvf(aTHX_
-                               "BEGIN { do {local $!; -f q%c./%"SVf
-                               "/buildcustomize.pl%c} and do q%c./%"SVf
-                               "/buildcustomize.pl%c || die $@ }",
-                                                              0, SVfARG(*inc0), 0,
+               "BEGIN { my $f = q%c./%"SVf"/buildcustomize.pl%c; "
+                       "do {local $!; -f $f }"
+                       " and do $f || die $@ || qq '$f: $!' }",
                                                               0, SVfARG(*inc0), 0));
        }
 #  else