DEV: Automatically handle macOS readlink issues (PR #14379)

The Docker 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 readlink as greadlink. The comment then recommends symlinking readlink to 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.)


The title of this pull request changed from “Automatically handle macOS readlink issues” to "DEV: Automatically handle macOS readlink issues

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

Hi @dfabulich, I’ll like to first thank you for your contribution and I apologise for the delay in our response. I just wanted to provide an update here to let you know that we’re aware of this PR and are deliberating internally on how we should resolve this.

Are there any questions I could answer about this PR?



The only thing that make me uneasy here is creation of a tempfile. Can you amend it so it just calls python direct with the full program and we have no intermediate file to worry about?