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.

215e0166d4d8265395c5d9076da73c70?s=128

Mike McQuaid

April 19, 2019
Tweet

Transcript

  1. @MikeMcQuaid Building Homebrew in Ruby

  2. @MikeMcQuaid

  3. @MikeMcQuaid Mike McQuaid mike@mikemcquaid.com https://github.com/MikeMcQuaid A

  4. @MikeMcQuaid Homebrew Ruby

  5. @MikeMcQuaid Ruby 2.6 in 2019

  6. @MikeMcQuaid Ruby 1.8 in 2016

  7. @MikeMcQuaid Ruby 2.3 in 2019

  8. @MikeMcQuaid /usr/bin/ruby 2.3.7p456

  9. @MikeMcQuaid ./Library/Homebrew/ vendor/portable-ruby/ 2.3.7/bin/ruby

  10. @MikeMcQuaid ↙

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

    prof == ruby-prof brew style == rubocop brew tests == rspec brew vendor-gems == bundle install --standalone
  12. @MikeMcQuaid bundle install

  13. @MikeMcQuaid bundle exec brew

  14. @MikeMcQuaid Library/Homebrew/Gemfile

  15. @MikeMcQuaid Library/Homebrew/vendor/ bundle/bundler/setup.rb

  16. @MikeMcQuaid $:.unshift "#{path}/../ #{ruby_engine}/ #{ruby_version}/gems/ concurrent-ruby-1.1.5/lib"

  17. @MikeMcQuaid Library/Homebrew/vendor/ bundle/ruby/2.3.0/ extensions/universal- darwin-18/2.3.0/

  18. @MikeMcQuaid ActiveSupport String#present?

  19. @MikeMcQuaid RuboCop 0

  20. @MikeMcQuaid brew style

  21. @MikeMcQuaid brew style wget

  22. @MikeMcQuaid

  23. @MikeMcQuaid No Ruby API

  24. @MikeMcQuaid

  25. @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": {
  26. @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": {
  27. @MikeMcQuaid Bash $ time brew shellenv >/dev/null … 91% cpu

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

    0.223 total Ruby(Kaigi) $ time brew help >/dev/null … 96% cpu 0.754 total
  29. @MikeMcQuaid Formula DSL

  30. @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
  31. @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
  32. @MikeMcQuaid Homebrew ❤ Ruby and Ruby community

  33. @MikeMcQuaid questions?