Merge pull request #3612 from MikeMcQuaid/more-deprecations

requirements: move more to compat.
This commit is contained in:
Mike McQuaid 2017-12-31 16:11:21 +00:00 committed by GitHub
commit 93a2e9fc25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 82 additions and 112 deletions

View File

@ -1,4 +1,5 @@
require "forwardable"
require "language/python"
class Caveats
extend Forwardable

View File

@ -27,3 +27,4 @@ require "compat/ENV/std"
require "compat/ENV/super"
require "compat/utils/shell"
require "compat/extend/string"
require "compat/gpg"

View File

@ -22,31 +22,61 @@ class DependencyCollector
case spec
when :clt
odeprecated "'depends_on :clt'"
when :tex
# odeprecated "'depends_on :tex'"
TeXRequirement.new(tags)
when :autoconf, :automake, :bsdmake, :libtool
output_deprecation(spec, tags)
autotools_dep(spec, tags)
when :cairo, :fontconfig, :freetype, :libpng, :pixman
output_deprecation(spec, tags)
Dependency.new(spec.to_s, tags)
when :apr
# output_deprecation(spec, tags, "apr-util")
Dependency.new("apr-util", tags)
when :ant, :expat
# output_deprecation(spec, tags)
Dependency.new(spec.to_s, tags)
when :libltdl
tags << :run
output_deprecation("libtool", tags)
Dependency.new("libtool", tags)
when :mysql
# output_deprecation("mysql", tags)
MysqlRequirement.new(tags)
when :postgresql
# output_deprecation("postgresql", tags)
PostgresqlRequirement.new(tags)
when :apr
# output_deprecation(spec, tags, "apr-util")
Dependency.new("apr-util", tags)
when :fortran
# output_deprecation(spec, tags, "gcc")
FortranRequirement.new(tags)
when :gpg
# output_deprecation("gnupg", tags)
# output_deprecation(spec, tags, "gnupg")
GPG2Requirement.new(tags)
when :hg
# output_deprecation(spec, tags, "mercurial")
MercurialRequirement.new(tags)
when :mpi
# output_deprecation(spec, tags, "open-mpi")
MPIRequirement.new(*tags)
when :emacs
# output_deprecation(spec, tags)
EmacsRequirement.new(tags)
when :mysql
# output_deprecation(spec, tags)
MysqlRequirement.new(tags)
when :perl
# output_deprecation(spec, tags)
PerlRequirement.new(tags)
when :postgresql
# output_deprecation(spec, tags)
PostgresqlRequirement.new(tags)
when :python, :python2
# output_deprecation(spec, tags)
PythonRequirement.new(tags)
when :python3
# output_deprecation(spec, tags)
Python3Requirement.new(tags)
when :rbenv
# output_deprecation("rbenv", tags)
# output_deprecation(spec, tags)
RbenvRequirement.new(tags)
when :ruby
# output_deprecation(spec, tags)
RubyRequirement.new(tags)
else
_parse_symbol_spec(spec, tags)
end

View File

@ -1,5 +1,11 @@
require "requirements"
require "compat/requirements/emacs_requirement"
require "compat/requirements/fortran_requirement"
require "compat/requirements/language_module_requirement"
require "compat/requirements/mpi_requirement"
require "compat/requirements/perl_requirement"
require "compat/requirements/python_requirement"
require "compat/requirements/ruby_requirement"
require "compat/requirements/tex_requirement"
class MysqlRequirement < Requirement

View File

@ -53,10 +53,6 @@ class DependencyCollector
parse_spec(spec, Array(tags))
end
def ant_dep_if_needed(tags)
Dependency.new("ant", tags)
end
def cvs_dep_if_needed(tags)
Dependency.new("cvs", tags)
end
@ -65,10 +61,6 @@ class DependencyCollector
Dependency.new("xz", tags)
end
def expat_dep_if_needed(tags)
Dependency.new("expat", tags)
end
def ld64_dep_if_needed(*)
LD64Dependency.new
end
@ -112,23 +104,11 @@ class DependencyCollector
when :xcode then XcodeRequirement.new(tags)
when :linux then LinuxRequirement.new(tags)
when :macos then MacOSRequirement.new(tags)
when :fortran then FortranRequirement.new(tags)
when :mpi then MPIRequirement.new(*tags)
when :tex then TeXRequirement.new(tags)
when :arch then ArchRequirement.new(tags)
when :hg then MercurialRequirement.new(tags)
when :python then PythonRequirement.new(tags)
when :python2 then PythonRequirement.new(tags)
when :python3 then Python3Requirement.new(tags)
when :java then JavaRequirement.new(tags)
when :ruby then RubyRequirement.new(tags)
when :osxfuse then OsxfuseRequirement.new(tags)
when :perl then PerlRequirement.new(tags)
when :tuntap then TuntapRequirement.new(tags)
when :ant then ant_dep_if_needed(tags)
when :emacs then EmacsRequirement.new(tags)
when :ld64 then ld64_dep_if_needed(tags)
when :expat then expat_dep_if_needed(tags)
else
raise ArgumentError, "Unsupported special dependency #{spec.inspect}"
end

View File

@ -379,24 +379,7 @@ class FormulaAuditor
case dep.name
when "git"
problem "Don't use git as a dependency"
when "gfortran"
problem "Use `depends_on :fortran` instead of `depends_on 'gfortran'`"
when "ruby"
problem <<~EOS
Don't use "ruby" as a dependency. If this formula requires a
minimum Ruby version not provided by the system you should
use the RubyRequirement:
depends_on :ruby => "1.8"
where "1.8" is the minimum version of Ruby required.
EOS
when "open-mpi", "mpich"
problem <<~EOS
There are multiple conflicting ways to install MPI. Use an MPIRequirement:
depends_on :mpi => [<lang list>]
Where <lang list> is a comma delimited list that can include:
:cc, :cxx, :f77, :f90
EOS
problem "Don't use git as a dependency (it's always available)"
when *BUILD_TIME_DEPS
next if dep.build? || dep.run?
problem <<~EOS

View File

@ -1,9 +1,4 @@
class DependencyCollector
def ant_dep_if_needed(tags)
return if MacOS.version < :mavericks
Dependency.new("ant", tags)
end
def cvs_dep_if_needed(tags)
return if MacOS.version < :lion
Dependency.new("cvs", tags)
@ -14,12 +9,6 @@ class DependencyCollector
Dependency.new("xz", tags)
end
def expat_dep_if_needed(tags)
# Tiger doesn't ship expat in /usr/lib
return if MacOS.version > :tiger
Dependency.new("expat", tags)
end
def ld64_dep_if_needed(*)
# Tiger's ld is too old to properly link some software
return if MacOS.version > :tiger

View File

@ -13,7 +13,6 @@ require "pkg_version"
require "tap"
require "keg"
require "migrator"
require "gpg"
require "extend/ENV"
# A formula provides instructions and metadata for Homebrew to install a piece

View File

@ -1,18 +1,12 @@
require "requirement"
require "requirements/fortran_requirement"
require "requirements/linux_requirement"
require "requirements/macos_requirement"
require "requirements/maximum_macos_requirement"
require "requirements/mpi_requirement"
require "requirements/osxfuse_requirement"
require "requirements/perl_requirement"
require "requirements/python_requirement"
require "requirements/java_requirement"
require "requirements/ruby_requirement"
require "requirements/tuntap_requirement"
require "requirements/unsigned_kext_requirement"
require "requirements/x11_requirement"
require "requirements/emacs_requirement"
require "requirements/arch_requirement"
require "requirements/xcode_requirement"

View File

@ -10,7 +10,7 @@ class JavaRequirement < Requirement
next true
end
def initialize(tags)
def initialize(tags = [])
@version = tags.shift if /(\d+\.)+\d/ =~ tags.first
super
end

View File

@ -5,7 +5,7 @@ class XcodeRequirement < Requirement
satisfy(build_env: false) { xcode_installed_version }
def initialize(tags)
def initialize(tags = [])
@version = tags.find { |tag| tags.delete(tag) if tag =~ /(\d\.)+\d/ }
super
end

View File

@ -6,12 +6,14 @@ module RuboCop
# This cop checks for various miscellaneous Homebrew coding styles
class Lines < FormulaCop
def audit_formula(_node, _class_node, _parent_class_node, _body_node)
[:automake, :autoconf, :libtool, :mysql, :postgresql, :rbenv].each do |dependency|
[:automake, :ant, :autoconf, :emacs, :expat, :libtool, :mysql, :perl,
:postgresql, :python, :python3, :rbenv, :ruby].each do |dependency|
next unless depends_on?(dependency)
problem ":#{dependency} is deprecated. Usage should be \"#{dependency}\"."
end
{ apr: "apr-util", gpg: "gnupg" }.each do |requirement, dependency|
{ apr: "apr-util", fortran: "gcc", gpg: "gnupg", hg: "mercurial",
mpi: "open-mpi", python2: "python" }.each do |requirement, dependency|
next unless depends_on?(requirement)
problem ":#{requirement} is deprecated. Usage should be \"#{dependency}\"."
end
@ -239,11 +241,6 @@ module RuboCop
problem "Use 'build.head?' instead of inspecting 'version'"
end
find_instance_method_call(body_node, "ENV", :fortran) do
next if depends_on?(:fortran)
problem "Use `depends_on :fortran` instead of `ENV.fortran`"
end
find_instance_method_call(body_node, "ARGV", :include?) do |method|
param = parameters(method).first
next unless match = regex_match_group(param, /^--(HEAD|devel)/)
@ -279,6 +276,10 @@ module RuboCop
problem "'fails_with :llvm' is now a no-op so should be removed"
end
find_method_with_args(body_node, :needs, :openmp) do
problem "'needs :openmp' should be replaced with 'depends_on \"gcc\"'"
end
find_method_with_args(body_node, :system, /^(otool|install_name_tool|lipo)/) do
next if @formula_name == "cctools"
problem "Use ruby-macho instead of calling #{@offensive_node.source}"

View File

@ -66,7 +66,7 @@ describe DependencyCollector do
expect(dep).to be_optional
end
specify "ant dependency" do
specify "ant dependency", :needs_compat do
subject.add ant: :build
expect(find_dependency("ant")).to eq(Dependency.new("ant", [:build]))
end

View File

@ -133,7 +133,7 @@ describe FormulaInstaller do
}.to raise_error(CannotInstallFormulaError)
end
describe "#install_requirement_formula?" do
describe "#install_requirement_formula?", :needs_compat do
before do
@requirement = Python3Requirement.new
@requirement_dependency = @requirement.to_dependency

View File

@ -711,21 +711,21 @@ describe Formula do
f1 = formula "f1" do
url "f1-1"
depends_on :python
depends_on :java
depends_on x11: :recommended
depends_on xcode: ["1.0", :optional]
end
stub_formula_loader(f1)
python = PythonRequirement.new
java = JavaRequirement.new
x11 = X11Requirement.new("x11", [:recommended])
xcode = XcodeRequirement.new(["1.0", :optional])
expect(Set.new(f1.recursive_requirements)).to eq(Set[python, x11])
expect(Set.new(f1.recursive_requirements)).to eq(Set[java, x11])
f1.build = BuildOptions.new(["--with-xcode", "--without-x11"], f1.options)
expect(Set.new(f1.recursive_requirements)).to eq(Set[python, xcode])
expect(Set.new(f1.recursive_requirements)).to eq(Set[java, xcode])
f1.build = f1.stable.build
f2 = formula "f2" do
@ -734,11 +734,11 @@ describe Formula do
depends_on "f1"
end
expect(Set.new(f2.recursive_requirements)).to eq(Set[python, x11])
expect(Set.new(f2.recursive_requirements {})).to eq(Set[python, x11, xcode])
expect(Set.new(f2.recursive_requirements)).to eq(Set[java, x11])
expect(Set.new(f2.recursive_requirements {})).to eq(Set[java, x11, xcode])
requirements = f2.recursive_requirements do |_dependent, requirement|
Requirement.prune if requirement.is_a?(PythonRequirement)
Requirement.prune if requirement.is_a?(JavaRequirement)
end
expect(Set.new(requirements)).to eq(Set[x11, xcode])

View File

@ -1,6 +1,6 @@
require "requirements/mpi_requirement"
require "compat/requirements/mpi_requirement"
describe MPIRequirement do
describe MPIRequirement, :needs_compat do
describe "::new" do
subject { described_class.new(*(wrappers + tags)) }
let(:wrappers) { [:cc, :cxx, :f77] }

View File

@ -22,18 +22,6 @@ describe DependencyCollector do
expect(subject.build(:ld64)).to be nil
end
specify "ant Mavericks or newer dependency" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.9"))
subject.add ant: :build
expect(subject.deps.find { |dep| dep.name == "ant" }).to eq(Dependency.new("ant", [:build]))
end
specify "ant pre-Mavericks dependency" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.7"))
subject.add ant: :build
expect(subject.deps.find { |dep| dep.name == "ant" }).to be nil
end
specify "Resource xz pre-Mavericks dependency" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.8"))
resource = Resource.new

View File

@ -717,19 +717,6 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
RUBY
end
it "deprecated ENV.fortran usage" do
expect_offense(<<~RUBY)
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
test do
ENV.fortran
^^^^^^^^^^^ Use `depends_on :fortran` instead of `ENV.fortran`
end
end
RUBY
end
it "deprecated ARGV.include? (--HEAD) usage" do
expect_offense(<<~RUBY)
class Foo < Formula
@ -744,6 +731,17 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
RUBY
end
it "deprecated needs :openmp usage" do
expect_offense(<<~RUBY)
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
needs :openmp
^^^^^^^^^^^^^ 'needs :openmp' should be replaced with 'depends_on \"gcc\"'
end
RUBY
end
it "deprecated MACOS_VERSION const usage" do
expect_offense(<<~RUBY)
class Foo < Formula