diff --git a/Library/Homebrew/rubocops/uses_from_macos.rb b/Library/Homebrew/rubocops/uses_from_macos.rb index 679547a431..51b5da7370 100644 --- a/Library/Homebrew/rubocops/uses_from_macos.rb +++ b/Library/Homebrew/rubocops/uses_from_macos.rb @@ -7,42 +7,72 @@ module RuboCop module FormulaAudit # This cop audits `uses_from_macos` dependencies in formulae class UsesFromMacos < FormulaCop - ALLOWED_USES_FROM_MACOS_DEPS = %w[ + # Generate with: + # brew ruby -e 'puts Formula.select {|f| f.keg_only_reason&.provided_by_macos? }.map(&:name).sort.join("\n")' + # Not done at runtime as its too slow and RuboCop doesn't have access. + PROVIDED_BY_MACOS_FORMULAE = %w[ + apr + bc bison bzip2 + cups curl + dyld-headers expat - expect + file-formula flex - groff + gcore + gnu-getopt icu4c krb5 + libarchive libedit libffi libiconv libpcap + libressl libxml2 libxslt llvm + lsof m4 + ncompress ncurses + net-snmp openldap - openssl@1.1 - perl - php + openlibm + pod2man + rpcgen ruby sqlite ssh-copy-id + swift tcl-tk texinfo + unifdef unzip - vim - xz zip zlib - zsh ].freeze + # These formulae aren't keg_only :provided_by_macos but are provided by + # macOS (or very similarly e.g. OpenSSL where system provides LibreSSL) + # TODO: consider making some of these keg-only. + ALLOWED_USES_FROM_MACOS_DEPS = (PROVIDED_BY_MACOS_FORMULAE + %w[ + bash + expect + groff + openssl + openssl@1.1 + perl + php + python + python@3 + vim + xz + zsh + ]).freeze + def audit_formula(_node, _class_node, _parent_class_node, body_node) find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method| dep = if parameters(method).first.class == RuboCop::AST::StrNode diff --git a/Library/Homebrew/test/support/helper/spec/shared_examples/formulae_exist.rb b/Library/Homebrew/test/support/helper/spec/shared_examples/formulae_exist.rb index 57a6560c72..b005657977 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_examples/formulae_exist.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_examples/formulae_exist.rb @@ -3,8 +3,10 @@ shared_examples "formulae exist" do |array| array.each do |f| it "#{f} formula exists" do - formula_path = Pathname("#{HOMEBREW_LIBRARY_PATH}/../Taps/homebrew/homebrew-core/Formula/#{f}.rb") - expect(formula_path.exist?).to be true + core_tap = Pathname("#{HOMEBREW_LIBRARY_PATH}/../Taps/homebrew/homebrew-core") + formula_path = core_tap/"Formula/#{f}.rb" + alias_path = core_tap/"Aliases/#{f}" + expect(formula_path.exist? || alias_path.exist?).to be true end end end