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, email@example.com, firstname.lastname@example.org, 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 email@example.com. 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 firstname.lastname@example.org 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 email@example.com and create it on each
brew link firstname.lastname@example.org. With this, I could set
GOROOT=/usr/local/var/goroot, and the underlying target would be set by