mxcl/homebrew — pull request #19869 by dhallman (2013-05-16 17:29:53+00:00)
Title: Please merge in 3 new features

I've added 3 features that I think could be interesting to people. In brief, it makes Homebrew better at building composite recipes (formula), by allowing a parent recipe to delegate and mediate between its sub-recipes.

Some background: I have several people in Accounting that are only slightly technical, but we need to deploy a suite of tools to their laptops. This forms a company standard toolset. What I wanted was a homebrew recipe like this:

$ brew tap company/system_setups
$ brew install rg-accounting-toolset

In my experience, Homebrew doesn't handle big composite recipes so well. Homebrew seems to be geared toward the one-off tool install, but not really re-initializing a whole laptop with a single 'brew install' command. I'm sure that wasn't the goal.

Still, I've added 3 small features, that I think make Homebrew much better at building composite recipes, that span multiple taps, and require steps be taken in between sub-recipes/dependencies.

These 3 composition features are illustrated in canonical form here:

require 'formula'

class BuildDevbox < Formula
homepage 'https://github.com/dhallman/ruby-envs/wiki/setup-devbox'

url 'https://github.com/dhallman/homebrew-ruby_envs.git', :tag => '0.0.3'
version '0.0.3'

head 'https://github.com/dhallman/homebrew-ruby_envs.git', :branch => 'master'

require_tap 'phinze/cask'
depends_on 'chruby'
depends_on 'ruby-build'
depends_on 'brew-cask'

def suppress_caveats?(depi)
true
end

def finalize_chruby(fi)
ohai "Finalize chruby ! "
end

def finalize_ruby_build(fi)
ohai "Finalize ruby-build !"
end

def finalize_brew_cask(fi)
ohai "Finalize brew-cask ! "
end

# Wrap up the whole install
def install
ohai "Done."
end

end

So, sometimes you can't continue with installing the next dependency, until you make some elections with the last one. I.e. like what the caveats are warning you about. Maybe you need to add something to the .bashrc, lauchctl, or build ruby 1.9.3 or else subsequent installs will fail their requirements.

In our case, we just want a convention over configuration setup, so I don't want to give them "caveats". I want to give them a finalized environment. Therefore:

1) Caveats can be suppressed, since Finalize will make the choices.
2) Optionally, you can define a "Finalize_<*>" method that gets called in between recipes
3) Your master recipe/formula can declare at the top, what taps it will need to complete the full installation.

Thanks for your consideration on this pull request. Hopefully, I didn't miss equivalent features already in the system. Certainly possible, as I only started looking at my first homebrew recipe and internals yesterday.