Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def info_formula(formula)
sig { params(dependencies: T::Array[Dependency]).returns(String) }
def decorate_dependencies(dependencies)
deps_status = dependencies.map do |dep|
if dep.satisfied?([])
if dep.satisfied?
pretty_installed(dep_display_s(dep))
else
pretty_uninstalled(dep_display_s(dep))
Expand Down
7 changes: 3 additions & 4 deletions Library/Homebrew/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,15 @@ def installed?(minimum_version: nil, minimum_revision: nil, minimum_compatibilit
end
end

def satisfied?(inherited_options = [], minimum_version: nil, minimum_revision: nil,
def satisfied?(minimum_version: nil, minimum_revision: nil,
minimum_compatibility_version: nil, bottle_os_version: nil)
installed?(minimum_version:, minimum_revision:, minimum_compatibility_version:, bottle_os_version:) &&
missing_options(inherited_options).empty?
missing_options.empty?
end

def missing_options(inherited_options)
def missing_options
formula = to_installed_formula
required = options
required |= inherited_options
required &= formula.options.to_a
required -= Tab.for_formula(formula).used_options
required
Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1632,9 +1632,6 @@ def skip_cxxstdlib_check?
false
end

sig { returns(T::Boolean) }
def require_universal_deps? = false

sig { void }
def patch
return if patchlist.empty?
Expand Down
78 changes: 28 additions & 50 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def check_install_sanity
end

next unless dep.to_formula.pinned?
next if dep.satisfied?(inherited_options_for(dep))
next if dep.satisfied?

pinned_unsatisfied_deps << dep
end
Expand All @@ -499,7 +499,7 @@ def fresh_install?(_formula) = false
def fetch_fetch_deps
return if @compute_dependencies.blank?

compute_dependencies(use_cache: false) if @compute_dependencies.any? do |dep,|
compute_dependencies(use_cache: false) if @compute_dependencies.any? do |dep|
next false unless dep.implicit?

fetch_dependencies
Expand All @@ -511,11 +511,11 @@ def fetch_fetch_deps
def install_fetch_deps
return if @compute_dependencies.blank?

compute_dependencies(use_cache: false) if @compute_dependencies.any? do |dep, options|
compute_dependencies(use_cache: false) if @compute_dependencies.any? do |dep|
next false unless dep.implicit?

fetch_dependencies
install_dependency(dep, options)
install_dependency(dep)
true
end
end
Expand Down Expand Up @@ -666,9 +666,9 @@ def check_conflicts

# Compute and collect the dependencies needed by the formula currently
# being installed.
sig { params(use_cache: T::Boolean).returns(T::Array[[Dependency, Options]]) }
sig { params(use_cache: T::Boolean).returns(T::Array[Dependency]) }
def compute_dependencies(use_cache: true)
@compute_dependencies = T.let(nil, T.nilable(T::Array[[Dependency, Options]])) unless use_cache
@compute_dependencies = T.let(nil, T.nilable(T::Array[Dependency])) unless use_cache
@compute_dependencies ||= begin
# Needs to be done before expand_dependencies
fetch_bottle_tab if pour_bottle?
Expand All @@ -678,9 +678,9 @@ def compute_dependencies(use_cache: true)
end
end

sig { params(deps: T::Array[[Dependency, Options]]).returns(T::Array[Formula]) }
sig { params(deps: T::Array[Dependency]).returns(T::Array[Formula]) }
def unbottled_dependencies(deps)
deps.map { |(dep, _options)| dep.to_formula }.reject do |dep_f|
deps.map(&:to_formula).reject do |dep_f|
next false unless dep_f.pour_bottle?

dep_f.bottled?
Expand Down Expand Up @@ -755,16 +755,12 @@ def expand_requirements
unsatisfied_reqs
end

sig { params(formula: Formula, inherited_options: T::Hash[String, Options]).returns(T::Array[Dependency]) }
def expand_dependencies_for_formula(formula, inherited_options)
sig { params(formula: Formula).returns(T::Array[Dependency]) }
def expand_dependencies_for_formula(formula)
# Cache for this expansion only. FormulaInstaller has a lot of inputs which can alter expansion.
cache_key = "FormulaInstaller-#{formula.full_name}-#{Time.now.to_f}"
Dependency.expand(formula, cache_key:) do |dependent, dep|
inherited_options[dep.name] |= inherited_options_for(dep)
build = effective_build_options_for(
dependent,
inherited_options.fetch(dependent.name, Options.new),
)
build = effective_build_options_for(dependent)

keep_build_test = false
keep_build_test ||= dep.test? && include_test? && @include_test_formulae.include?(dependent.full_name)
Expand All @@ -778,25 +774,19 @@ def expand_dependencies_for_formula(formula, inherited_options)

if dep.prune_from_option?(build) || ((dep.build? || dep.test?) && !keep_build_test)
Dependency.prune
elsif dep.satisfied?(inherited_options[dep.name], minimum_version:, minimum_revision:, bottle_os_version:)
elsif dep.satisfied?(minimum_version:, minimum_revision:, bottle_os_version:)
Dependency.skip
end
end
end

sig { returns(T::Array[[Dependency, Options]]) }
def expand_dependencies
inherited_options = Hash.new { |hash, key| hash[key] = Options.new }
sig { returns(T::Array[Dependency]) }
def expand_dependencies = expand_dependencies_for_formula(formula)

expanded_deps = expand_dependencies_for_formula(formula, inherited_options)

expanded_deps.map { |dep| [dep, inherited_options[dep.name]] }
end

sig { params(dependent: Formula, inherited_options: Options).returns(BuildOptions) }
def effective_build_options_for(dependent, inherited_options = Options.new)
sig { params(dependent: Formula).returns(BuildOptions) }
def effective_build_options_for(dependent)
args = dependent.build.used_options
args |= (dependent == formula) ? options : inherited_options
args |= options if dependent == formula
args |= Tab.for_formula(dependent).used_options
args &= dependent.options
BuildOptions.new(args, dependent.options)
Expand All @@ -813,27 +803,17 @@ def display_options(formula)
options
end

sig { params(dep: Dependency).returns(Options) }
def inherited_options_for(dep)
inherited_options = Options.new
u = Option.new("universal")
if (options.include?(u) || formula.require_universal_deps?) && !dep.build? && dep.to_formula.option_defined?(u)
inherited_options << u
end
inherited_options
end

sig { params(deps: T::Array[[Dependency, Options]]).void }
sig { params(deps: T::Array[Dependency]).void }
def install_dependencies(deps)
if deps.empty? && only_deps?
puts "All dependencies for #{formula.full_name} are satisfied."
elsif !deps.empty?
if deps.length > 1
oh1 "Installing dependencies for #{formula.full_name}: " \
"#{deps.map(&:first).map { Formatter.identifier(_1) }.to_sentence}",
"#{deps.map { Formatter.identifier(_1) }.to_sentence}",
truncate: false
end
deps.each { |dep, options| install_dependency(dep, options) }
deps.each { install_dependency(_1) }
end

@show_header = true if deps.length > 1
Expand Down Expand Up @@ -865,8 +845,8 @@ def fetch_dependency(dep)
fi.fetch
end

sig { params(dep: Dependency, inherited_options: Options).void }
def install_dependency(dep, inherited_options)
sig { params(dep: Dependency).void }
def install_dependency(dep)
df = dep.to_formula

if df.linked_keg.directory?
Expand Down Expand Up @@ -897,7 +877,6 @@ def install_dependency(dep, inherited_options)
options = Options.new
options |= tab.used_options if tab.present?
options |= Tab.remap_deprecated_options(df.deprecated_options, dep.options)
options |= inherited_options
options &= df.options

installed_on_request = df.any_version_installed? && tab.present? && tab.installed_on_request
Expand Down Expand Up @@ -1390,21 +1369,20 @@ def fetch_dependencies
return if ignore_deps?

# Don't output dependencies if we're explicitly installing them.
deps = compute_dependencies.reject do |(dep, _options)|
deps = compute_dependencies.reject do |dep|
self.class.fetched.include?(dep.to_formula)
end

return if deps.empty?

unless download_queue
dependencies_string = deps.map(&:first)
.map { |dep| Formatter.identifier(dep) }
dependencies_string = deps.map { |dep| Formatter.identifier(dep) }
.to_sentence
oh1 "Fetching dependencies for #{formula.full_name}: #{dependencies_string}",
truncate: false
end

deps.each { |(dep, _options)| fetch_dependency(dep) }
deps.each { fetch_dependency(_1) }
end

sig { returns(T.nilable(Formula)) }
Expand Down Expand Up @@ -1627,7 +1605,7 @@ def forbidden_license_check
end

unless ignore_deps?
compute_dependencies.each do |(dep, _options)|
compute_dependencies.each do |dep|
dep_f = dep.to_formula
next unless SPDX.licenses_forbid_installation? dep_f.license, forbidden_licenses

Expand Down Expand Up @@ -1659,7 +1637,7 @@ def forbidden_tap_check
end

unless ignore_deps?
compute_dependencies.each do |(dep, _options)|
compute_dependencies.each do |dep|
dep_tap = dep.tap
next if dep_tap.blank? || (dep_tap.allowed_by_env? && !dep_tap.forbidden_by_env?)

Expand Down Expand Up @@ -1700,7 +1678,7 @@ def forbidden_formula_check
end

unless ignore_deps?
compute_dependencies.each do |(dep, _options)|
compute_dependencies.each do |dep|
dep_name = if forbidden_formulae.include?(dep.name)
dep.name
elsif dep.tap.present? &&
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def install_formulae(
sig {
params(
formula: Formula,
dependencies: T::Array[[Dependency, Options]],
dependencies: T::Array[Dependency],
_block: T.proc.params(arg0: Formula).returns(String),
).void
}
Expand All @@ -434,7 +434,7 @@ def print_dry_run_dependencies(formula, dependencies, &_block)

ohai "Would install #{Utils.pluralize("dependency", dependencies.count, include_count: true)} " \
"for #{formula.name}:"
formula_names = dependencies.map { |(dep, _options)| yield dep.to_formula }
formula_names = dependencies.map { |dep| yield dep.to_formula }
puts formula_names.join(" ")
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
subject(:dependency) { described_class.new("foo") }

it "accepts bottle_os_version parameter" do
expect { dependency.satisfied?([], bottle_os_version: "macOS 14") }.not_to raise_error
expect { dependency.satisfied?(bottle_os_version: "macOS 14") }.not_to raise_error
end

it "accepts Ubuntu bottle_os_version parameter" do
Expand Down
Loading