bfgroup / b2

B2 makes it easy to build C++ projects, everywhere.
https://www.bfgroup.xyz/b2/
Boost Software License 1.0
81 stars 230 forks source link

`%~dp0` is wrong in `SHELL \"script\"` (correct in `SHELL script`) #309

Open Kojoley opened 1 year ago

Kojoley commented 1 year ago

Make sure you completed the following tasks

Environment and version details

Brief problem description

Steps to reproduce the issue

C:\correct\asd.bat

echo %%~dp0=%~dp0

C:\wrong\jamroot

ECHO unquoted [ SHELL asd ] ;
ECHO quoted   [ SHELL \"asd\" ] ;

Execute following:

set PATH=C:\correct;%PATH%
cd C:\wrong
b2 -fjamroot
unquoted %~dp0=C:\correct\

quoted %~dp0=C:\wrong\

...found 1 target...

Actual behavior summary

%~dp0 points to current working directory.

Expected behavior summary

%~dp0 points to the bat self path.

That doesn't happen for python scripts though

C:\correct\qwe.py

print(__file__)

C:\wrong\jamroot

ECHO unquoted [ SHELL qwe ] ;
ECHO quoted   [ SHELL \"qwe\" ] ;

Execute following:

set PATH=C:\correct;%PATH%
set PATHEXT=.PY;%PATHEXT%
cd C:\wrong
b2 -fjamroot
unquoted C:\correct\qwe.py

quoted C:\correct\qwe.py

...found 1 target...
Kojoley commented 1 year ago

Turns out it is a cmd.exe bug https://github.com/microsoft/terminal/issues/15212 and they won't fix it:

Oh I'm so sorry to be the person that lets you know, but yea, cmd.exe isn't actively maintained anymore (beyond security patches). Yea, the Terminal team does own cmd.exe, but we're not gonna be making any changes to it anytime soon.