This article mainly introduces Homebrew, a software package management tool for Mac OS, and explains the steps of creating Formula in detail.


Review of previous article:
Nginx dynamic discovery scheme and practice



1.Homebrew is introduced

Homebrew[1] is a software package management tool based on Mac OS platform. It has many practical functions such as installation, uninstallation, update, view, search and so on. Package management can be implemented with a simple command, and you don’t have to worry about dependencies and file paths. It is very convenient and quick. Homebrew has become something of a standard for Mac programmers. As a contributor to open source software, this article will show you how to make your open source projects package managed through Homebrew.

brew install fooCopy the code

2,Formula VS. Cask

Homebrew supports multiple forms of package management, including Formula and Cask. Formula is used for source code compilation and installation of open source command-line tools, and Cask is used for installation of UI-enabled applications. The Github project corresponding to official Formula is Homebrew-Core [2], and the Github project corresponding to Cask is Homebrew-Cask [3]. You are advised to Fork the corresponding Git project into your own account before adding new tools. Limited by space, this article will only introduce the method of Formula creation and use, and the method of Cask creation is similar.

3,Procedure for creating a Formula

1. Prepare local Git repository

cd `brew --repo`/Library/Taps/homebrew/homebrew-core
git remote add ${your_github_id} https://github.com/${your_github_id}/homebrew-core.git
git fetch ${your_github_id}
git checkout -b ${your_github_id} ${your_github_id}/masterCopy the code

2. Create Formula script file

# This command will automatically create a file named foo.rb in the Formula directory, which will also be opened by the text editor.
brew create fooCopy the code

3. Edit Formula file

4, test installation

# installation
brew install foo
Instead of downloading the compiled version of Bottle, the following link is an introduction to Bottle
# https://docs.brew.sh/Bottle
brew reinstall --build-from-source foo
Check Formula script format, super useful linter tool
brew audit --strict fooCopy the code

5. Submit the code and wait for the PR merge

Homebrew has a very active community and typically receives a response from the project maintainer within 24 hours of submitting a PR. In order to allow the tool written by myself to be included as soon as possible, it is recommended to read the Issue Template carefully before submitting PR and modify it according to the suggestions. Here’s the official PR advice.

- [ ] Have you followed the [guidelines for contributing](https://github.com/Homebrew/homebrew-core/blob/master/CONTRIBUTING.md)?
- [ ] Have you checked that there aren't other open [pull requests](https://github.com/Homebrew/homebrew-core/pulls) for the same formula update/change? - [ ]  Have you built your formula locally with `brew install --build-from-source 
       
        `, where `
        
         ` is the name of the formula you'
        
       re submitting?
- [ ] Does your build pass `brew audit --strict <formula>` (after doing `brew install <formula>`)?Copy the code


Refer to the link

[1] https://brew.sh/

[2] https://github.com/Homebrew/homebrew-core

[3] https://github.com/Homebrew/homebrew-cask

[4] https://docs.brew.sh/Formula-Cookbook#homebrew-terminology

[5] https://docs.brew.sh/Formula-Cookbook

[6] https://github.com/Homebrew


This article was first published on the public account “Mi Operation and Maintenance”. Click to view the original article