Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Homebrew in Ruby

Building Homebrew in Ruby

Homebrew is a popular macOS package manager in the Ruby community and is also written in Ruby. As Homebrew isn't a web application and doesn't provide a Ruby library, the Ruby ecosystem works great for us in some ways and less great in others. Learn about things we love, hate and struggle with because Homebrew is built in Ruby.

Mike McQuaid

April 19, 2019
Tweet

More Decks by Mike McQuaid

Other Decks in Technology

Transcript

  1. @MikeMcQuaid brew irb == irb/pry brew man == ronn brew

    prof == ruby-prof brew style == rubocop brew tests == rspec brew vendor-gems == bundle install --standalone
  2. @MikeMcQuaid $ brew info wget --json | jq . [

    { "name": "wget", "full_name": "wget", "oldname": null, "aliases": [], "versioned_formulae": [], "desc": "Internet file retriever", "homepage": "https://www.gnu.org/software/wget/", "versions": { "stable": "1.20.3", "devel": null, "head": "HEAD", "bottle": true }, "revision": 0, "version_scheme": 0, "bottle": { "stable": {
  3. @MikeMcQuaid $ curl https://formulae.brew.sh/api/formula/wget.json | jq . [ { "name":

    "wget", "full_name": "wget", "oldname": null, "aliases": [], "versioned_formulae": [], "desc": "Internet file retriever", "homepage": "https://www.gnu.org/software/wget/", "versions": { "stable": "1.20.3", "devel": null, "head": "HEAD", "bottle": true }, "revision": 0, "version_scheme": 0, "bottle": { "stable": {
  4. @MikeMcQuaid Bash $ time brew shellenv >/dev/null … 91% cpu

    0.223 total Ruby $ time brew help >/dev/null … 96% cpu 0.852 total
  5. @MikeMcQuaid Bash $ time brew shellenv >/dev/null … 91% cpu

    0.223 total Ruby(Kaigi) $ time brew help >/dev/null … 96% cpu 0.754 total
  6. @MikeMcQuaid class Wget < Formula homepage "https://www.gnu.org/software/wget/" url "https://ftp.gnu.org/gnu/wget/wget-…" sha256

    "52126be8cf1bddd7536886e74c053ad7d0ed…" def install system "./configure", "--prefix=#{prefix}" system "make", "install" end end
  7. @MikeMcQuaid require "cli_parser" module Homebrew module_function def home_args Homebrew::CLI::Parser.new do

    usage_banner <<~EOS `home` [<formula>] Open <formula>'s homepage in a browser. If no formula is provided, open Homebrew's own homepage in a browser. EOS switch :debug end end def home home_args.parse if args.remaining.empty? exec_browser HOMEBREW_WWW else exec_browser(*ARGV.formulae.map(&:homepage)) end end end