FormulaInstaller: implement installation locks

FormulaInstaller now attempts to take a lock on a "foo.brewing" file for
the formula and all of its dependencies before attempting installation.

The lock is an advisory lock implemented using flock(), and as such it
only locks out other processes that attempt to take the lock. It also
means that it is never necessary to manually remove the lock file,
because the lock is not enforced by I/O.

The uninstall, link, and unlink commands all learn to respect this lock
as well, so that the installation cannot be corrupted by a concurrent
Homebrew process, and keg operations cannot occur simultaneously.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>

Respect operation lock in link and unlink

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Formula::finalize_dsl

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Add support for optional and recommended deps

Optional deps are not installed by default but generate a corresponding
"with-foo" option for the formula. Recommended deps _are_ installed by
default, and generate a corresponding "without-foo" option.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Let option override with/without descriptions

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Dependency.expand_dependencies

Move Formula.expand_dependencies into the Dependency class, and extend
it to allow arbitrary filters to be applied when enumerating deps.

When supplied with a block, expand_dependencies will yield a [dependent,
dependency] pair for each dependency, allowing callers to filter out
dependencies that may not be applicable or useful in a given situation.

Deps can be skipped by simple calling Dependency.prune in the block,
e.g.:

  Dependency.expand_dependencies do |f, dep|
    Dependency.prune if dep.to_formula.installed?
  end

The return value of the method is filtered list.

If no block is supplied, a default filter that omits optional or
recommended deps based on what the dependent formula has requested is
applied.

Formula#recursive_dependencies is now implemented on top of this,
allowing FormulaInstaller to exact detailed control over what deps are
installed. `brew missing` and `brew upgrade` can learn to use this to
apply the installed options set when expanding dependencies.

Move Formula.expand_deps and Formula#recursive_deps into compat, because
these methods do not respect the new optional and recommended tags and
thus should no longer be used.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
FormulaInstaller: make tab an attr, but never a parameter

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
FormulaInstaller: don't install bottle if options were passed

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
FormulaInstaller: allow formulae to pass options to deps

Formulae can now pass build options to dependencies. The following
syntax is supported:

  depends_on 'foo' => 'with-bar'
  depends_on 'foo' => ['with-bar', 'with-baz']

If a dependency is already installed but lacks the required build
options, an exception is raised. Eventually we may be able to just stash
the existing keg and reinstall it with the combined set of used_options
and passed options, but enabling that is left for another day.
FormulaInstaller: consolidate ARGV munging

There are several steps required to construct the ARGV that is passed to
the spawned build process. Factor them out into a separate method.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
missing: ignore unused optional and recommended deps

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
deps: reimplement intersection with sets

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
uses: utilize modern dependency API

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
upgrade: offload dependency expansion to FormulaInstaller

Now that FormulaInstaller does dependency expansion the _right_ way,
avoid duplicating the logic in upgrade. Instead, offload it to the
installer, and generate an exception in check_install_sanity that we can
safely ignore when formulae in the outdated list are upgraded as part of
the dependency tree of another outdated formula.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Replace usages of recursive_deps with recursive_dependencies

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Add "depends_on :clt"

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Tag Xcode and CLT requirements as build-time

This way they can be skipped when installing bottles.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
curl: use new optional deps support

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
mtr: use new optional deps support

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
postgresql: use new recommended deps support

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
v8cgi: use new optional deps support

Signed-off-by: Jack Nagel <jacknagel@gmail.com>