From 718cf8b0df5666001dce4fa73a88c70218b98252 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 22 Aug 2022 14:54:52 +0800 Subject: [PATCH] Fix Linux-only GCC dependency check. This is based on feedback from code review. --- Library/Homebrew/formula_auditor.rb | 31 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index 9d51183606..3ecabea98f 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -333,21 +333,11 @@ module Homebrew return unless @core_tap - # Prevent formulae from declaring Linux-only dependencies on GCC, - # or else its dependency tree grows out of control. - on_linux_deps = formula.to_hash_with_variations.dig("variations", :x86_64_linux, "dependencies") - if on_linux_deps&.include? "gcc" - bad_gcc_dep = @strict || begin - fv = FormulaVersions.new(formula) - prev_on_linux_deps = fv.formula_at_revision("origin/HEAD") do |prev_f| - prev_f.to_hash_with_variations.dig("variations", :x86_64_linux, "dependencies") - end - - prev_on_linux_deps&.exclude? "gcc" - end - - problem "Formulae in homebrew/core should not have a Linux-only dependency on GCC." if bad_gcc_dep - end + bad_gcc_dep = linux_only_gcc_dep?(formula) && (@strict || begin + fv = FormulaVersions.new(formula) + fv.formula_at_revision("origin/HEAD") { |prev_f| !linux_only_gcc_dep?(prev_f) } + end) + problem "Formulae in homebrew/core should not have a Linux-only dependency on GCC." if bad_gcc_dep return if formula.tap&.audit_exception :versioned_dependencies_conflicts_allowlist, formula.name @@ -865,5 +855,16 @@ module Homebrew def head_only?(formula) formula.head && formula.stable.nil? end + + def linux_only_gcc_dep?(formula) + # TODO: Make this check work when running on Linux and not simulating macOS too. + return false unless Homebrew::SimulateSystem.simulating_or_running_on_macos? + + formula_hash = formula.to_hash_with_variations + deps = formula_hash["dependencies"] + linux_deps = formula_hash.dig("variations", :x86_64_linux, "dependencies") + + deps.exclude?("gcc") && linux_deps&.include?("gcc") + end end end