Skip to contentSkip to conversation

Fix invocation of b4.sh through a symlink

PATCH In review Geert Uytterhoeven 3 participants 3 messages Mar 24, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix invocation of b4.sh through a symlink

If b4 in your $PATH is a symlink pointing to b4.sh, $SCRIPT_TOP points to the directory containing the symlink, and b4/command.py cannot be found.

Fix this by following any symlinks, if present.

After this it works for being invoked through either an alias, symlink, or plain path.

---
Stack Overflow tells me "readlink -f" is not supported on OS X and some BSDs. Do we care?

---
 b4.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
b4.sh +1 -1
index cafeee186115832d..e5459192d978e41b 100755
@@ -3,6 +3,6 @@
 # Run b4 from a git checkout.
 #
 
-SCRIPT_TOP="${SCRIPT_TOP:-$(cd "${BASH_SOURCE%/*}" && pwd)}"
+SCRIPT_TOP="${SCRIPT_TOP:-$(dirname $(readlink -f $0))}"
 
 exec env PYTHONPATH="${SCRIPT_TOP}" python3 "${SCRIPT_TOP}/b4/command.py" "${@}"
Signature · 1 line
2.17.1
#1 lore raw
Quoted 6 lines · Geert Uytterhoeven

If b4 in your $PATH is a symlink pointing to b4.sh, $SCRIPT_TOP points to the directory containing the symlink, and b4/command.py cannot be found.

Fix this by following any symlinks, if present.

Quoted 7 lines

After this it works for being invoked through either an alias, symlink, or plain path.

---
Stack Overflow tells me "readlink -f" is not supported on OS X and some BSDs. Do we care?

I used a similar patch that Greg sent because it used "realpath" instead. It doesn't exist at all on OSX/BSDs, but if they are doing any kernel development at all, they probably know how to install coreutils. I think that's an easier requirement than setting up a GNU-compatible version of readlink.

Best,
-K

#2 lore raw

Hi Konstantin,

Quoted 15 lines · Konstantin Ryabitsev
Quoted 6 lines · Geert Uytterhoeven

If b4 in your $PATH is a symlink pointing to b4.sh, $SCRIPT_TOP points to the directory containing the symlink, and b4/command.py cannot be found.

Fix this by following any symlinks, if present.

Quoted 7 lines

After this it works for being invoked through either an alias, symlink, or plain path.

---
Stack Overflow tells me "readlink -f" is not supported on OS X and some BSDs. Do we care?

Quoted 5 lines

I used a similar patch that Greg sent because it used "realpath" instead. It doesn't exist at all on OSX/BSDs, but if they are doing any kernel development at all, they probably know how to install coreutils. I think that's an easier requirement than setting up a GNU-compatible version of readlink.

Greg's version works fine for me, too.

Note that both readlink and realpath are part of coreutils ;-)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds