From 01d1f1ecb60e05e9cbe1d09c38405f3d8b9d179c Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Thu, 30 Jun 2022 04:11:15 +0100 Subject: [PATCH] Fix `Keg.bottle_dependencies` including unneeded build dependencies --- .../Homebrew/extend/os/linux/keg_relocate.rb | 3 +- Library/Homebrew/formula_installer.rb | 37 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/extend/os/linux/keg_relocate.rb b/Library/Homebrew/extend/os/linux/keg_relocate.rb index 294b4aef94..ee1537910c 100644 --- a/Library/Homebrew/extend/os/linux/keg_relocate.rb +++ b/Library/Homebrew/extend/os/linux/keg_relocate.rb @@ -87,8 +87,7 @@ class Keg gcc = Formulary.factory(CompilerSelector.preferred_gcc) if !Homebrew::EnvConfig.simulate_macos_on_linux? && DevelopmentTools.non_apple_gcc_version("gcc") < gcc.version.to_i - formulae += gcc.recursive_dependencies.map(&:name) - formulae << gcc.name + formulae << gcc end formulae end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 4d9f8f86ab..03486bb730 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -577,9 +577,8 @@ class FormulaInstaller unsatisfied_reqs end - def expand_dependencies - inherited_options = Hash.new { |hash, key| hash[key] = Options.new } - pour_bottle = pour_bottle? + def expand_dependencies_for_formula(formula, inherited_options) + any_bottle_used = false # 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}" @@ -600,24 +599,34 @@ class FormulaInstaller elsif dep.satisfied?(inherited_options[dep.name]) Dependency.skip else - pour_bottle ||= install_bottle_for?(dep.to_formula, build) + any_bottle_used ||= install_bottle_for?(dep.to_formula, build) end end + [expanded_deps, any_bottle_used] + end + + def expand_dependencies + inherited_options = Hash.new { |hash, key| hash[key] = Options.new } + any_bottle_used = pour_bottle? + + expanded_deps, any_dep_bottle_used = expand_dependencies_for_formula(formula, inherited_options) + any_bottle_used ||= any_dep_bottle_used + # We require some dependencies (glibc, GCC 5, etc.) if binaries were built. # Native binaries shouldn't exist in cross-platform `all` bottles. - if pour_bottle && !formula.bottled?(:all) && !Keg.bottle_dependencies.empty? - bottle_deps = if Keg.bottle_dependencies.exclude?(formula.name) - Keg.bottle_dependencies - else - [] + if any_bottle_used && !formula.bottled?(:all) && !Keg.bottle_dependencies.empty? + all_bottle_deps = Keg.bottle_dependencies.flat_map do |bottle_dep| + bottle_dep.recursive_dependencies.map(&:name) + [bottle_dep.name] end - bottle_deps = bottle_deps.map { |formula| Dependency.new(formula) } - .reject do |dep| - inherited_options[dep.name] |= inherited_options_for(dep) - dep.satisfied? inherited_options[dep.name] + + if all_bottle_deps.exclude?(formula.name) + bottle_deps = Keg.bottle_dependencies.flat_map do |bottle_dep| + expanded_bottle_deps, = expand_dependencies_for_formula(bottle_dep, inherited_options) + expanded_bottle_deps + end + expanded_deps = Dependency.merge_repeats(bottle_deps + expanded_deps) end - expanded_deps = Dependency.merge_repeats(bottle_deps + expanded_deps) end expanded_deps.map { |dep| [dep, inherited_options[dep.name]] }