mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
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.
This commit is contained in:
parent
9fa95d7218
commit
8b30abe060
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user