formula_auditor: audit for Linux-only dependencies on GCC

As we've seen, allowing Linux-only dependencies on GCC results in its
dependency tree growing out of control to the point of being extremely
painful to maintain.

Let's stop this situation from getting worse by:
- failing a `--strict` audit when there is a Linux-only GCC dependency.
  This also prevents new formulae from having such a dependency.
- failing any audit whenever a formula that did not previously have a
  Linux-only GCC dependency picks one up

If a future formula update causes a formula to fail to build on Linux
because it needs a newer GCC when it previously did not, then we should
not bottle it. We can bottle this hypothetical formula when our bottling
distribution includes a new enough version of GCC.
This commit is contained in:
Carlo Cabrera 2022-08-04 22:09:40 +08:00
parent 93bf9e5ba2
commit 4302af67b7
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -332,6 +332,23 @@ module Homebrew
end
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
return if formula.tap&.audit_exception :versioned_dependencies_conflicts_allowlist, formula.name
# The number of conflicts on Linux is absurd.