mxcl/homebrew — pull request #19880 by dhallman (2013-05-17 00:47:33+00:00)
Title: Improved support for Compound Formulae

Homebrew is great for interactive, one-off tool installation. However, it is not really geared toward installing a set of tools, in batch scenarios.

I've made 3 trivial tweaks that I believe address this, and allow brew to install tool chains. Note: this is minimal support for installing tool chains; not meant to rival orchestration tools by any means. I was more thinking about scenarios where one developer might pass a brew "compound formula" to a new hire, that will install the 8 or so tools that he'll need, setup a few mysql users, build ruby-1.9.3, etc. In other words, codify the tool selection, and automate some of the glue steps that need to occur after, and sometimes between installs.

My 3 tweaks per this pull request, in order of significance are:

1) Formula Ready Event - this is an event you can listen to in your compound formula that gets notified when a sub-formula is 100% done. Called a "finalizer", this listener can perform additional "glue" steps between successful installs, that may be required by subsequent tools later in the chain.

2) require_tap - a declarative way to specify what taps your compound formula will expect.

3) suppress_caveats? - Compound formulae may wish to act upon (automatically) all the caveats of its dependents, and then issue a single, summarized caveat once everything is installed.

So, with these 3 features, you can build a compound formula like the following:

require 'formula'
class SetupRubyDevEnv < Formula
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 'sidekiq'
depends_on 'brew-cask'

def suppress_caveats?(fi); true; end

def finalize_ruby_build(fi)
ohai "Building ruby 1.9.3.."
system "ruby-build", "ruby-1.9.3-p429", "~/.rubies/"
end
end

So, this "finalize_ruby_build" event fires after "ruby-build" installs, and would allow the parent/compound formula to guarantee that there is a working ruby 1.9.3 ready before sidekiq starts installing. Of course, this listeners are optional, so that finalize_chruby() would also fire if you added the method.

Anyway, I thought it was kind of cool and useful, to be able to execute glue steps in between installs. And it has helped me deliver a small tool chain to some non-technical folks, in a way that is light-weight, unintimidating and allows for a centralized deployment.

So, take it for what it's worth. If you don't find these ideas general purpose enough, that's fine. I should be able to achieve the same through monkey patching, so that I can avoid being version pinned to a fork.

Thanks,
Dean