Skip to content
Snippets Groups Projects
Commit a4dc835b authored by Alyssa Ross's avatar Alyssa Ross
Browse files

uninstall: call Formula#missing_dependencies directly

parent 422f38b9
No related branches found
No related tags found
No related merge requests found
......@@ -76,7 +76,7 @@ module Homebrew
end
def check_for_dependents(kegs)
return false unless result = find_some_installed_dependents(kegs)
return false unless result = Keg.find_some_installed_dependents(kegs)
requireds, dependents = result
......@@ -108,8 +108,16 @@ module Homebrew
remaining_formulae = Formula.installed.select { |f|
f.installed_kegs.any? { |k| Tab.for_keg(k).runtime_dependencies.nil? }
}
Diagnostic.missing_deps(remaining_formulae, kegs.map(&:name)) do |dependent, required|
kegs_by_name = kegs.group_by(&:to_formula)
keg_names = kegs.map(&:name)
kegs_by_name = kegs.group_by(&:to_formula)
remaining_formulae.each do |dependent|
required = dependent.missing_dependencies(hide: keg_names)
required.select! do |f|
kegs_by_name.key?(f)
end
next unless required.any?
required_kegs = required.map { |f| kegs_by_name[f].sort_by(&:version).last }
return required_kegs, [dependent]
end
......
......@@ -87,6 +87,41 @@ class Keg
mime-info pixmaps sounds postgresql
].freeze
# Will return some kegs, and some dependencies, if they're present.
# For efficiency, we don't bother trying to get complete data.
def self.find_some_installed_dependents(kegs)
# First, check in the tabs of installed Formulae.
kegs.each do |keg|
dependents = keg.installed_dependents - kegs
dependents.map! { |d| "#{d.name} #{d.version}" }
return [keg], dependents if dependents.any?
end
# Some kegs won't have modern Tabs with the dependencies listed.
# In this case, fall back to Formula#missing_dependencies.
# Find formulae that didn't have dependencies saved in all of their kegs,
# so need them to be calculated now.
#
# This happens after the initial dependency check because it's sloooow.
remaining_formulae = Formula.installed.select { |f|
f.installed_kegs.any? { |k| Tab.for_keg(k).runtime_dependencies.nil? }
}
keg_names = kegs.map(&:name)
kegs_by_name = kegs.group_by(&:to_formula)
remaining_formulae.each do |dependent|
required = dependent.missing_dependencies(hide: keg_names)
required.select! { |f| kegs_by_name.key?(f) }
next unless required.any?
required_kegs = required.map { |f| kegs_by_name[f].sort_by(&:version).last }
return required_kegs, [dependent]
end
nil
end
# if path is a file in a keg then this will return the containing Keg object
def self.for(path)
path = path.realpath
......
......@@ -31,6 +31,32 @@ class IntegrationCommandTestUninstall < IntegrationCommandTestCase
assert_empty Formulary.factory(testball).installed_kegs
end
def test_uninstall_with_unrelated_missing_deps_in_tab
setup_test_formula "testball"
run_as_not_developer do
cmd("install", testball)
cmd("install", "testball_f2")
cmd("uninstall", "--ignore-dependencies", "testball_f1")
cmd("uninstall", testball)
end
end
def test_uninstall_with_unrelated_missing_deps_not_in_tab
setup_test_formula "testball"
run_as_not_developer do
cmd("install", testball)
cmd("install", "testball_f2")
f2_keg = f2.installed_kegs.first
f2_tab = Tab.for_keg(f2_keg)
f2_tab.runtime_dependencies = nil
f2_tab.write
cmd("uninstall", "--ignore-dependencies", "testball_f1")
cmd("uninstall", testball)
end
end
def test_uninstall_leaving_dependents
cmd("install", "testball_f2")
run_as_not_developer do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment