boot_dev script has a bug on macOS when using plugins: it attempts to invoke
readlink -f, which works fine with GNU
readlink but doesn’t work with macOS
readlink. (I reproduce the issue on macOS Big Sur 11.6, which is latest as of today.)
The script on
master includes a comment documenting how to work around the issue manually, using Homebrew to install
coreutils, which installs a GNU version of
greadlink. The comment then recommends symlinking
greadlink so bare calls to
readlink will use the GNU version instead of the macOS default version.
That’s a pretty weird thing to do to a machine just to satisfy this one script, and, anyway, it’s a bummer that the script fails and that the end user has to manually follow directions in a comment to fix it.
In this PR, I attempt to
readlink -f the directory that we just created; if that fails, we create a one-liner Python script that does the same thing as
readlink -f, and we use that, instead.
I got the one-liner from macos - How can I get the behavior of GNU's readlink -f on a Mac? - Stack Overflow … there are other implementations there, including a few pure-bash implementations, but they’re kinda verbose; various replies warn that there are a lot of weird corner cases. The Python one-liner seems like the easiest way to handle it.
(This infrastructure script has no tests, and I didn’t add any.)