Implement rustup
audit as a style check
This allows results to be cached and auto-corrected.
This commit is contained in:
parent
f75ccc005e
commit
470c1e6683
@ -309,10 +309,6 @@ module Homebrew
|
|||||||
|
|
||||||
next unless @core_tap
|
next unless @core_tap
|
||||||
|
|
||||||
if @strict && dep.name == "rustup-init" && !dep.test?
|
|
||||||
problem "Formulae should use `rust` instead of `rustup-init` to build"
|
|
||||||
end
|
|
||||||
|
|
||||||
unless dep_f.tap.core_tap?
|
unless dep_f.tap.core_tap?
|
||||||
problem <<~EOS
|
problem <<~EOS
|
||||||
Dependency '#{dep.name}' is not in homebrew/core. Formulae in homebrew/core
|
Dependency '#{dep.name}' is not in homebrew/core. Formulae in homebrew/core
|
||||||
|
@ -884,6 +884,50 @@ module RuboCop
|
|||||||
problem "Formulae should not depend on :tuntap" if depends_on? :tuntap
|
problem "Formulae should not depend on :tuntap" if depends_on? :tuntap
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This cop makes sure that formulae build with `rust` instead of `rustup-init`.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
class RustCheck < FormulaCop
|
||||||
|
extend AutoCorrector
|
||||||
|
|
||||||
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
|
# Enforce use of `rust` for rust dependency in core
|
||||||
|
return if formula_tap != "homebrew-core"
|
||||||
|
|
||||||
|
find_method_with_args(body_node, :depends_on, "rustup-init") do
|
||||||
|
problem "Formulae in homebrew/core should use 'depends_on \"rust\"' " \
|
||||||
|
"instead of '#{@offensive_node.source}'." do |corrector|
|
||||||
|
corrector.replace(@offensive_node.source_range, "depends_on \"rust\"")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: Enforce order of dependency types so we don't need to check for
|
||||||
|
# depends_on "rustup-init" => [:test, :build]
|
||||||
|
[:build, [:build, :test], [:test, :build]].each do |type|
|
||||||
|
find_method_with_args(body_node, :depends_on, "rustup-init" => type) do
|
||||||
|
problem "Formulae in homebrew/core should use 'depends_on \"rust\" => #{type}' " \
|
||||||
|
"instead of '#{@offensive_node.source}'." do |corrector|
|
||||||
|
corrector.replace(@offensive_node.source_range, "depends_on \"rust\" => #{type}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
install_node = find_method_def(body_node, :install)
|
||||||
|
return if install_node.blank?
|
||||||
|
|
||||||
|
find_every_method_call_by_name(install_node, :system).each do |method|
|
||||||
|
param = parameters(method).first
|
||||||
|
next if param.blank?
|
||||||
|
# FIXME: Handle Pathname parameters (e.g. `system bin/"rustup-init"`).
|
||||||
|
next if regex_match_group(param, /rustup-init$/).blank?
|
||||||
|
|
||||||
|
problem "Formula in homebrew/core should not use `rustup-init` at build-time."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user