Homebrew
Summarizing my attempts to understand Homebrew codebase
Formula - package definition.
Keg - installation prefix of a formula.
Cellar - where all kegs are located.
Tap - git repo of formulae and/or commands.
Bottle - pre-built keg.
Cask - extension of Homebrew to install native MacOS apps.
General notes:
I like how formulae come with tests.
Formula dev guide is pretty great.
Ruby seems like a great choice for DLSs like this.
Overall code structure seems moderately simple, e.g. there are not too many layers of redirection for the most part.
Implementation details are often rather convoluted, with not too many comments.
A lot of long methods.
Tracing:
Entry point shell script: https://github.com/Homebrew/brew/blob/master/bin/brew
Then https://github.com/Homebrew/brew/blob/master/Library/Homebrew/brew.sh
Setting env variables for OS, cache location, etc.
Checks that it's not sudo, not installing on temp, etc.
Check dependencies: curl, git, ...
Then route to one of https://github.com/Homebrew/brew/tree/master/Library/Homebrew/cmd
Some are .sh, some are .rb
I expected a single ruby entry point, but there's none!
Install path:
https://github.com/Homebrew/brew/blob/master/Library/Homebrew/cmd/install.rb
Test: https://github.com/Homebrew/brew/blob/master/Library/Homebrew/test/cmd/install_spec.rb Seems rather... superficial. But I kind of like their test DSL.
Accepts formula and a ton of params.
I would probably extract the params into some class.
Then it creates FormulaInstaller and calls its methods one by one: prelude, fetch, install, finish.
FormulaInstaller seems... rather convoluted.
Interesting:
Did you mean? https://github.com/Homebrew/brew/pull/11565/files
Not too interesting. It just delegates.
Github access https://github.com/Homebrew/brew/blob/aa14e48f4e73d2f4c7d178d7b8a2f528b74995d7/Library/Homebrew/utils/github.rb With pagination and what not. Spec: https://github.com/Homebrew/brew/blob/master/Library/Homebrew/test/utils/github_spec.rb
Last updated