2020-10-10 14:16:11 +02:00
|
|
|
# typed: true
|
2020-04-05 15:22:06 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rubocops/extend/formula"
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module FormulaAudit
|
2020-11-05 17:17:03 -05:00
|
|
|
# This cop audits `uses_from_macos` dependencies in formulae.
|
2020-04-05 15:22:06 +01:00
|
|
|
class UsesFromMacos < FormulaCop
|
2020-04-20 10:36:42 +01:00
|
|
|
# Generate with:
|
2020-11-05 17:17:03 -05:00
|
|
|
#
|
|
|
|
# ```
|
2020-04-20 10:36:42 +01:00
|
|
|
# brew ruby -e 'puts Formula.select {|f| f.keg_only_reason&.provided_by_macos? }.map(&:name).sort.join("\n")'
|
2020-11-05 17:17:03 -05:00
|
|
|
# ```
|
|
|
|
#
|
|
|
|
# Not done at runtime as it's too slow and RuboCop doesn't have access.
|
2020-04-20 10:36:42 +01:00
|
|
|
PROVIDED_BY_MACOS_FORMULAE = %w[
|
|
|
|
apr
|
|
|
|
bc
|
2020-04-05 15:22:06 +01:00
|
|
|
bison
|
|
|
|
bzip2
|
2020-04-20 10:36:42 +01:00
|
|
|
cups
|
2020-04-05 15:22:06 +01:00
|
|
|
curl
|
2020-04-20 10:36:42 +01:00
|
|
|
dyld-headers
|
2020-06-15 23:50:54 +02:00
|
|
|
ed
|
2020-04-05 15:22:06 +01:00
|
|
|
expat
|
2020-04-20 10:36:42 +01:00
|
|
|
file-formula
|
2020-04-05 15:22:06 +01:00
|
|
|
flex
|
2020-04-20 10:36:42 +01:00
|
|
|
gcore
|
|
|
|
gnu-getopt
|
2020-04-07 12:16:17 +01:00
|
|
|
icu4c
|
|
|
|
krb5
|
2020-04-20 10:36:42 +01:00
|
|
|
libarchive
|
2020-04-07 12:16:17 +01:00
|
|
|
libedit
|
2020-04-05 15:22:06 +01:00
|
|
|
libffi
|
2020-04-18 21:39:39 +10:00
|
|
|
libiconv
|
2020-04-07 12:16:17 +01:00
|
|
|
libpcap
|
2020-04-20 10:36:42 +01:00
|
|
|
libressl
|
2020-04-05 15:22:06 +01:00
|
|
|
libxml2
|
|
|
|
libxslt
|
2020-04-07 12:16:17 +01:00
|
|
|
llvm
|
2020-04-20 10:36:42 +01:00
|
|
|
lsof
|
2020-04-05 15:22:06 +01:00
|
|
|
m4
|
2020-04-20 10:36:42 +01:00
|
|
|
ncompress
|
2020-04-07 15:04:23 +01:00
|
|
|
ncurses
|
2020-04-20 10:36:42 +01:00
|
|
|
net-snmp
|
2020-04-07 12:16:17 +01:00
|
|
|
openldap
|
2020-04-20 10:36:42 +01:00
|
|
|
openlibm
|
|
|
|
pod2man
|
|
|
|
rpcgen
|
2020-04-05 15:22:06 +01:00
|
|
|
ruby
|
|
|
|
sqlite
|
2020-04-07 15:04:23 +01:00
|
|
|
ssh-copy-id
|
2020-04-20 10:36:42 +01:00
|
|
|
swift
|
2020-04-07 12:16:17 +01:00
|
|
|
tcl-tk
|
2020-04-05 15:22:06 +01:00
|
|
|
texinfo
|
2020-04-20 10:36:42 +01:00
|
|
|
unifdef
|
2020-04-05 15:22:06 +01:00
|
|
|
unzip
|
2020-04-07 12:16:17 +01:00
|
|
|
zip
|
2020-04-07 15:04:23 +01:00
|
|
|
zlib
|
2020-04-05 15:22:06 +01:00
|
|
|
].freeze
|
|
|
|
|
2020-11-05 17:17:03 -05:00
|
|
|
# These formulae aren't `keg_only :provided_by_macos` but are provided by
|
|
|
|
# macOS (or very similarly, e.g. OpenSSL where system provides LibreSSL).
|
2020-04-20 10:36:42 +01:00
|
|
|
# TODO: consider making some of these keg-only.
|
|
|
|
ALLOWED_USES_FROM_MACOS_DEPS = (PROVIDED_BY_MACOS_FORMULAE + %w[
|
|
|
|
bash
|
2020-07-08 22:59:41 +02:00
|
|
|
cpio
|
2020-04-20 10:36:42 +01:00
|
|
|
expect
|
|
|
|
groff
|
2020-04-20 10:38:06 -07:00
|
|
|
gzip
|
2020-04-20 10:36:42 +01:00
|
|
|
openssl
|
|
|
|
openssl@1.1
|
|
|
|
perl
|
|
|
|
php
|
|
|
|
python
|
|
|
|
python@3
|
2020-04-20 10:38:06 -07:00
|
|
|
rsync
|
2020-04-20 10:36:42 +01:00
|
|
|
vim
|
|
|
|
xz
|
|
|
|
zsh
|
|
|
|
]).freeze
|
|
|
|
|
2020-04-05 15:22:06 +01:00
|
|
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
|
|
|
find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method|
|
2020-10-09 11:12:06 +02:00
|
|
|
dep = if parameters(method).first.instance_of?(RuboCop::AST::StrNode)
|
2020-04-05 15:22:06 +01:00
|
|
|
parameters(method).first
|
2020-10-09 11:12:06 +02:00
|
|
|
elsif parameters(method).first.instance_of?(RuboCop::AST::HashNode)
|
2020-04-05 15:22:06 +01:00
|
|
|
parameters(method).first.keys.first
|
|
|
|
end
|
|
|
|
|
|
|
|
next if ALLOWED_USES_FROM_MACOS_DEPS.include?(string_content(dep))
|
|
|
|
|
|
|
|
problem "`uses_from_macos` should only be used for macOS dependencies, not #{string_content(dep)}."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|