I’m wondering if it’s possible to create hooks in a formula that will be called by
brew link <FORMULA> and
brew unlink <FORMULA>? The purpose here is to create/remove symlinks that are specific to folders (not just executables) within the specific formula being linked or unlinked.
Here’s a specific use case. Golang (go, firstname.lastname@example.org, email@example.com, etc.) requires a GOROOT environment variable that points to the current installation folder (
libexec, in brew). Prior to the new style of versioning, I just set
GOROOT=/usr/local/opt/go/libexec, and when I did
brew switch go <VERSION>, my GOROOT was still correct, as the underlying symlink target had changed.
With the new versioning style, I switch versions using (for example)
brew unlink go followed by
brew link --force firstname.lastname@example.org. I want to be able to set GOROOT once (as before), and have this always be correct after unlinking one version and linking another.
I experimented with this in the email@example.com formula locally. After adding the following line to the
install method, I created a symlink at
/usr/local/var/goroot that pointed to the
var.install_symlink libexec => "goroot"
The problem is, the symlink created is permanent, whereas I want to be able to remove it on each
brew unlink firstname.lastname@example.org and create it on each
brew link email@example.com. With this, I could set
GOROOT=/usr/local/var/goroot, and the underlying target would be set by