formula_installer: further reduce dependency calculations
This commit is contained in:
parent
4524714a7b
commit
73d372e951
@ -286,49 +286,51 @@ class FormulaInstaller
|
|||||||
|
|
||||||
return if ignore_deps?
|
return if ignore_deps?
|
||||||
|
|
||||||
recursive_deps = formula.recursive_dependencies
|
if Homebrew::EnvConfig.developer?
|
||||||
recursive_formulae = recursive_deps.map(&:to_formula)
|
# `recursive_dependencies` trims cyclic dependencies, so we do one level and take the recursive deps of that.
|
||||||
|
# Mapping direct dependencies to deeper dependencies in a hash is also useful for the cyclic output below.
|
||||||
|
recursive_dep_map = formula.deps.to_h { |dep| [dep, dep.to_formula.recursive_dependencies] }
|
||||||
|
|
||||||
recursive_dependencies = []
|
cyclic_dependencies = []
|
||||||
invalid_arch_dependencies = []
|
recursive_dep_map.each do |dep, recursive_deps|
|
||||||
recursive_formulae.each do |dep|
|
if [formula.name, formula.full_name].include?(dep.name)
|
||||||
dep_recursive_dependencies = dep.recursive_dependencies.map(&:to_s)
|
cyclic_dependencies << "#{formula.full_name} depends on itself directly"
|
||||||
if dep_recursive_dependencies.include?(formula.name)
|
elsif recursive_deps.any? { |rdep| [formula.name, formula.full_name].include?(rdep.name) }
|
||||||
recursive_dependencies << "#{formula.full_name} depends on #{dep.full_name}"
|
cyclic_dependencies << "#{formula.full_name} depends on itself via #{dep.name}"
|
||||||
recursive_dependencies << "#{dep.full_name} depends on #{formula.full_name}"
|
|
||||||
end
|
|
||||||
|
|
||||||
if (tab = Tab.for_formula(dep)) && tab.arch.present? && tab.arch.to_s != Hardware::CPU.arch.to_s
|
|
||||||
invalid_arch_dependencies << "#{dep} was built for #{tab.arch}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless recursive_dependencies.empty?
|
if cyclic_dependencies.present?
|
||||||
raise CannotInstallFormulaError, <<~EOS
|
raise CannotInstallFormulaError, <<~EOS
|
||||||
#{formula.full_name} contains a recursive dependency on itself:
|
#{formula.full_name} contains a recursive dependency on itself:
|
||||||
#{recursive_dependencies.join("\n ")}
|
#{cyclic_dependencies.join("\n ")}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
if recursive_formulae.flat_map(&:recursive_dependencies)
|
# Merge into one list
|
||||||
.map(&:to_s)
|
recursive_deps = recursive_dep_map.flat_map { |dep, rdeps| [dep] + rdeps }
|
||||||
.include?(formula.name)
|
Dependency.merge_repeats(recursive_deps)
|
||||||
raise CannotInstallFormulaError, <<~EOS
|
else
|
||||||
#{formula.full_name} contains a recursive dependency on itself!
|
recursive_deps = formula.recursive_dependencies
|
||||||
EOS
|
|
||||||
end
|
end
|
||||||
|
|
||||||
unless invalid_arch_dependencies.empty?
|
invalid_arch_dependencies = []
|
||||||
|
pinned_unsatisfied_deps = []
|
||||||
|
recursive_deps.each do |dep|
|
||||||
|
if (tab = Tab.for_formula(dep.to_formula)) && tab.arch.present? && tab.arch.to_s != Hardware::CPU.arch.to_s
|
||||||
|
invalid_arch_dependencies << "#{dep} was built for #{tab.arch}"
|
||||||
|
end
|
||||||
|
|
||||||
|
pinned_unsatisfied_deps << dep if dep.to_formula.pinned? && !dep.satisfied?(inherited_options_for(dep))
|
||||||
|
end
|
||||||
|
|
||||||
|
if invalid_arch_dependencies.present?
|
||||||
raise CannotInstallFormulaError, <<~EOS
|
raise CannotInstallFormulaError, <<~EOS
|
||||||
#{formula.full_name} dependencies not built for the #{Hardware::CPU.arch} CPU architecture:
|
#{formula.full_name} dependencies not built for the #{Hardware::CPU.arch} CPU architecture:
|
||||||
#{invalid_arch_dependencies.join("\n ")}
|
#{invalid_arch_dependencies.join("\n ")}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
pinned_unsatisfied_deps = recursive_deps.select do |dep|
|
|
||||||
dep.to_formula.pinned? && !dep.satisfied?(inherited_options_for(dep))
|
|
||||||
end
|
|
||||||
|
|
||||||
return if pinned_unsatisfied_deps.empty?
|
return if pinned_unsatisfied_deps.empty?
|
||||||
|
|
||||||
raise CannotInstallFormulaError,
|
raise CannotInstallFormulaError,
|
||||||
@ -1151,10 +1153,12 @@ class FormulaInstaller
|
|||||||
|
|
||||||
tab = Tab.for_keg(keg)
|
tab = Tab.for_keg(keg)
|
||||||
|
|
||||||
|
unless ignore_deps?
|
||||||
CxxStdlib.check_compatibility(
|
CxxStdlib.check_compatibility(
|
||||||
formula, formula.recursive_dependencies,
|
formula, formula.recursive_dependencies,
|
||||||
Keg.new(formula.prefix), tab.compiler
|
Keg.new(formula.prefix), tab.compiler
|
||||||
)
|
)
|
||||||
|
end
|
||||||
|
|
||||||
tab.tap = formula.tap
|
tab.tap = formula.tap
|
||||||
tab.poured_from_bottle = true
|
tab.poured_from_bottle = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user