Now that FormulaInstaller does dependency expansion the _right_ way,
avoid duplicating the logic in upgrade. Instead, offload it to the
installer, which will 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.
When a dependency of a formula specified on the command-line is also
specified, *after* the dependent formula, installation proceeds as part
of the dependent's dependency tree and then is attempted again because
the user asked for it explicitly. This results in the installer raising
a CannotInstallFormulaError because it has already been installed.
For example:
$ brew install graphviz pkg-config
==> Installing graphviz dependency: pkg-config
...
==> Installing graphviz
...
Error: pkg-config-0.27.1 already installed
We already have a mechanism for dealing with this, but it does not kick
in early enough. Move the installation attempt check into
FormulaInstaller#check_install_sanity and catch the exception in the
appropriate places.
FixesHomebrew/homebrew#16957.
Two issues were preventing `brew upgrade` from functioning properly:
- `Tab.for_formula` was used to recover options from prior installs. The
problem is that during an upgrade `for_formula` will be directed to a
non-existant install of the newer version and thus returns a forged tab
claiming no options were invoked.
- The assignment to `installer.install_bottle` requires parenthesis in order
to function properly.
Usually, the "foo-version already installed" error is printed by
FormulaInstaller. However, if an up-to-date formula that has outdated
deps is passed on the command line, we proceed to upgrade the deps and
then print a message saying that the formulae given on the command line
is already installed.
Catch this earlier, when the outdated list is being populated, print an
appropriate message, and skip the up-to-date formula.
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This serves the same purpose as similar code in FormulaInstaller, but we
duplicate it because we do the dependency expansion in an ad-hoc fashion
here.
FixesHomebrew/homebrew#11863.
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Callers of FormulaInstaller now usually unlink the existing keg prior to
running the installer. However, Tab.for_formula uses the LinkedKeg
record to obtain the tab.
Since we need the tab to persist install options across upgrades, we
must start creating the Tab object before unlinking the old keg and
passing it to the FormulaInstaller.
FixesHomebrew/homebrew#11086.
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Also, unlink previous keg before installing to prevent issues when existing installed brews cause build problems for the newer installed brew.
If the build fails the active keg is relinked before aborting.
Fixes #10341.
Calling Keg#unlink on "#{f.rack}/#{f.version}" will perform the unlink
relative to the _new_ keg, rather than the keg we are upgrading from.
Fix this by resolving the linked_keg entry and unlinking relative to it.
FixesHomebrew/homebrew#10296.
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Previously, `outdated_brews` returned a list of lists---each containing three
components of a Formula object:
- f.rack
- f.name
- f.version
Frequently more information is required which necessitates back-casting from
`name` to a Formula object---simpy returning formula objects removes this step.
`rack` is a commonly used alias for `formula.prefix.parent`---so common that it
gets defined and used quite a bit. This patch makes `rack` an official method
of the `Formula` class.
Consequence: you can no longer install when something is already installed, you must upgrade it. This doesn't apply if the formula in question was unlinked. You can still --force installs though.
Rationale: the old way of installing over the top would leave symlinks to multiple versions in /usr/local if the old version had a file the newer version didn't. The new upgrade command handles everything properly.