aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAlyssa Ross2016-12-31 13:14:27 +0000
committerAlyssa Ross2016-12-31 17:53:06 +0000
commit8b30abe0600df5c9d3da5b4c31ca88a71a1c3e03 (patch)
tree6f4d26a070a713250b62410eed0aa6e169e8bfdf /Library
parent9fa95d721820919eff3193c3c5bded37f6589831 (diff)
downloadbrew-8b30abe0600df5c9d3da5b4c31ca88a71a1c3e03.tar.bz2
keg: handle dependencies of moved/renamed formulae
In #1497 I switched from Keg#to_formula for comparing kegs to formulae to comparing the name and tap in the keg's tab to the name and tap of the formula. However, this fails to match if the name and tap of the formula have changed since the keg was installed, so it's clearly better to use Keg#to_formula where possible, and fall back to the information in the tab when #to_formula can't be used.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/keg.rb13
-rw-r--r--Library/Homebrew/test/keg_test.rb20
2 files changed, 31 insertions, 2 deletions
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index e64fd9b33..74fd88c2e 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -126,7 +126,18 @@ class Keg
end
keg_names = kegs.map(&:name)
- kegs_by_source = kegs.group_by { |k| [k.name, Tab.for_keg(k).tap] }
+ kegs_by_source = kegs.group_by do |keg|
+ begin
+ # First, attempt to resolve the keg to a formula
+ # to get up-to-date name and tap information.
+ f = keg.to_formula
+ [f.name, f.tap]
+ rescue FormulaUnavailableError
+ # If the formula for the keg can't be found,
+ # fall back to the information in the tab.
+ [keg.name, Tab.for_keg(keg).tap]
+ end
+ end
remaining_formulae.each do |dependent|
required = dependent.missing_dependencies(hide: keg_names)
diff --git a/Library/Homebrew/test/keg_test.rb b/Library/Homebrew/test/keg_test.rb
index 45d63aa95..40beac887 100644
--- a/Library/Homebrew/test/keg_test.rb
+++ b/Library/Homebrew/test/keg_test.rb
@@ -373,6 +373,7 @@ class InstalledDependantsTests < LinkTestCase
t.source["tap"] = "some/tap"
t.source["path"] = nil
end
+
dependencies [{ "full_name" => "some/tap/foo", "version" => "1.0" }]
assert_equal [@dependent], @keg.installed_dependents
assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg])
@@ -388,7 +389,7 @@ class InstalledDependantsTests < LinkTestCase
Formula["bar"].class.depends_on "baz"
result = Keg.find_some_installed_dependents([@keg, @tap_dep])
- assert_equal [[@tap_dep], ["bar"]], result
+ assert_equal [[@keg, @tap_dep], ["bar"]], result
end
def test_no_dependencies_anywhere
@@ -411,6 +412,23 @@ class InstalledDependantsTests < LinkTestCase
assert_nil Keg.find_some_installed_dependents([@keg, @dependent])
end
+ def test_renamed_dependency
+ dependencies nil
+
+ stub_formula_loader Formula["foo"], "homebrew/core/foo-old"
+ renamed_path = HOMEBREW_CELLAR/"foo-old"
+ (HOMEBREW_CELLAR/"foo").rename(renamed_path)
+ renamed_keg = Keg.new(renamed_path.join("1.0"))
+
+ Formula["bar"].class.depends_on "foo"
+
+ result = Keg.find_some_installed_dependents([renamed_keg])
+ assert_equal [[renamed_keg], ["bar"]], result
+ ensure
+ # Move it back to where it was so it'll be cleaned up.
+ (HOMEBREW_CELLAR/"foo-old").rename(HOMEBREW_CELLAR/"foo")
+ end
+
def test_empty_dependencies_in_tab
dependencies []
assert_empty @keg.installed_dependents