# Homebrew

* <https://github.com/Homebrew>
* <https://github.com/Homebrew/brew>
* <https://github.com/Homebrew/homebrew-core>
* <https://github.com/Homebrew/homebrew-cask>

[**Terms**](https://docs.brew.sh/Formula-Cookbook#homebrew-terminology)**:**

* 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.
  * Command parser: <https://github.com/Homebrew/brew/blob/master/Library/Homebrew/cli/parser.rb>
  * Check if to install: <https://github.com/Homebrew/brew/blob/aa14e48f4e73d2f4c7d178d7b8a2f528b74995d7/Library/Homebrew/install.rb#L95>
  * Install: <https://github.com/Homebrew/brew/blob/aa14e48f4e73d2f4c7d178d7b8a2f528b74995d7/Library/Homebrew/install.rb#L232>
    * Accepts formula and a ton of params.
    * I would probably extract the params into some class.
  * Then it creates [FormulaInstaller](https://github.com/Homebrew/brew/blob/aa14e48f4e73d2f4c7d178d7b8a2f528b74995d7/Library/Homebrew/formula_installer.rb#L29) 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.
* Locking. <https://github.com/Homebrew/brew/blob/master/Library/Homebrew/lock_file.rb>
* 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>
* Search: <https://github.com/Homebrew/brew/blob/master/Library/Homebrew/search.rb>
* Download strategy switch: <https://github.com/Homebrew/brew/blob/09f7bc27a99469cf947431df4754737dfbadb31d/Library/Homebrew/download_strategy.rb#L1323-L1356>
* Unpack strategy. <https://github.com/Homebrew/brew/blob/master/Library/Homebrew/unpack_strategy.rb> <https://github.com/Homebrew/brew/tree/master/Library/Homebrew/unpack_strategy>
* Cache store: <https://github.com/Homebrew/brew/blob/master/Library/Homebrew/cache_store.rb>
* Curl & workarounds: <https://github.com/Homebrew/brew/blob/04532cb6216b69a5b067aa7a4e22cff0944b257d/Library/Homebrew/utils/curl.rb#L64>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.ainzzorl.lol/tech/open-source/homebrew.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
