StrawberryPerl / Perl-Dist-Strawberry

Tooling to build and package releases for Perl on Windows.
https://strawberryperl.com
Other
289 stars 49 forks source link

Problem on startup of 5.40.0.1-PDL build #200

Closed sisyphus closed 3 months ago

sisyphus commented 3 months ago

On my Windows 11 machine, the execution of 5.40.0.1-PDL's portableshell.bat culminates with:

 * see README.TXT for more info
----------------------------------------------
FATAL ERROR: 'perl' does not work; check if your strawberry pack is complete!

However, perl itself seems to be basically fine.

It seems that 5.38.2.2-PDL and 5.40.0.1-PDL are handling the command perl -MConfig -MPDL -e "printf("""Perl executable: %%s\nPerl version : %%vd / $Config{archname}\nPDL version : %%s\n\n""", $^X, $^V, $PDL::VERSION)" a little differently. On 5.38.2.2-PDL:

C:\>perl -MConfig -MPDL -e "printf("""Perl executable: %%s\nPerl version   : %%vd / $Config{archname}\nPDL version    : %%s\n\n""", $^X, $^V, $PDL::VERSION)";
Perl executable: %s
Perl version   : %vd / MSWin32-x64-multi-thread
PDL version    : %s

On 5.40.0.1-PDL:

C:\>perl -MConfig -MPDL -e "printf("""Perl executable: %%s\nPerl version   : %%vd / $Config{archname}\nPDL version    : %%s\n\n""", $^X, $^V, $PDL::VERSION)";
Can't find string terminator '"' anywhere before EOF at -e line 1.

After spending more time than I'm prepared to admit, I still haven't got to the bottom of it. I'll keep poking at it, but someone else might pinpoint the problem quicker than I can.

shawnlaffan commented 3 months ago

Thanks Rob. It looks like the change in 6def322571eee0e17703edfbbfe17504bb4e19d2 does not work.

Changing L45 to this gets it to work.

if %ERRORLEVEL% == "1" echo FATAL ERROR: 'perl' does not work; check if your strawberry pack is complete!
sisyphus commented 3 months ago

Oh, yes. I had played around with alterations to that line but, obviously, the wind here was blowing in the wrong direction. I still don't quite get it. Out of curiosity, what changed such that if ERRORLEVEL==1 needed to be altered to if %ERRORLEVEL% == "1" ?

shawnlaffan commented 3 months ago

I've uploaded new versions with that line amended. ~I still need to change the base code, though.~

The reason for the change is in #196

sisyphus commented 3 months ago

I had seen https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/196, but it doesn't really explain (to me, at least) the need for the change. If ERRORLEVEL==1 works fine on my Windows 11 box with perl-5.38.2, then I would expect it to work fine on the same box with perl-5.40.0.

I can only think that the difference comes back to that perl command (on the previous line of portableshell.bat) being handled differently by perl-5.38.2 and perl-5.40.0. And I can't see why perl-5.38.2 and perl-5.40.0 should handle that line of code differently. I'm thinking "perl bug" ... but maybe the only bug is inside my head ;-)

I'll close this now, as the immediate issue is fixed.

But I'll strive to get a better understanding of what is happening here ... and update this thread if I'm successful.

sisyphus commented 3 months ago

Reopening because I now think the "fix" of replacing ERRORLEVEL 1with %ERRORLEVEL% == "1" merely hides the problem, rather than fixing it. Although there is then no report of an error, the perl one-liner outputs nothing ... because it died. We might just as well remove that one-liner (and the check on ERRORLEVEL) from portableshell.bat.

Changing the one-liner to:

perl -MConfig -MPDL -e "printf(\"Perl executable: %%s\nPerl version   : %%vd / $Config{archname}\nPDL version    : %%s\n\n\", $^X, $^V, $PDL::VERSION)" 2>nul

(as suggested at https://www.perlmonks.org/?node_id=11160849) fixes the problem for me - without (I think) any need to alter the following line (line 45). But I don't know why it wasn't always done that way.

That perlmonks thread also presents the notion that the change in behaviour arises from a change in underlying C library, which also seems reasonable. But I don't think it has been caused by the change from MSVCRT to UCRT. My own builds of perl-5.38 are UCRT (unlike SP-5.38 which is MSVCRT), but they handle the original one-liner construct just fine.

UPDATE: It's apparently the white space between the 2 triplets of double-quotes that stuffs things up:

C:\>perl -wle "printf("""SP-Version:%s\n""", $]);"
SP-Version:5.040000

C:\>perl -wle "printf("""SP-Version: %s\n""", $]);"
Can't find string terminator '"' anywhere before EOF at -e line 1.

SP-5.40.0-RC1 avoided the issue by using qq{...} instead of \" ... \". I'm not sure which (if any) is the preferred solution.

shawnlaffan commented 3 months ago

qq{} is the simplest means of avoiding all the escaping of double quotes. I'll modify the .bat files accordingly.

Even so, the command needs to use %%s to escape the % when run as a batch file. I'm not fully across batch file escape rules but it otherwise throws errors when run as a script.

I think I'll also revert the error level check. The old style seems to work well enough now I have tested it more thoroughly.

sisyphus commented 3 months ago

Even so, the command needs to use %%s to escape the % when run as a batch file.

FWIW (probably not much) you can actually emit the same output from portableshell.bat using print() instead of printf() - thereby avoiding the printf formatting completely:

perl -MConfig -MPDL -e "print qq{Perl executable: $^X\nPerl version   : $^V / $Config{archname}\nPDL version    : $PDL::VERSION\n\n}" 2>nul

Maybe that doesn't have the desired effect on ERRORLEVEL if something is missing. (I don't know.)

UPDATE: Duh ... not quite the same as perl version appears as "v5.40.0" instead of "5.40.0".

shawnlaffan commented 3 months ago

Thanks Rob.

A plain print() call seems to me to be a simpler approach.

I don't see issues with printing versions with the leading v. It is purely feedback for when the shell starts. If args are passed then perl is called and the script exits before it gets to this code.

shawnlaffan commented 3 months ago

5.40.0.1 has the changes discussed in this issue. I'll close this once that is promoted to the latest release.

Edit: link is https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/tag/SP_54001_64bit_UCRT

shawnlaffan commented 3 months ago

SP 5.40.0.1 is now the latest release so I'll close this.

Thanks again @sisyphus for the report and discussion.