From faf2182495e770041274c59e3b9ac80b98326fae Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 30 Dec 2017 18:57:23 +0000 Subject: [PATCH 1/4] gpg: move to compat. --- Library/Homebrew/compat.rb | 1 + Library/Homebrew/{ => compat}/gpg.rb | 0 Library/Homebrew/formula.rb | 1 - 3 files changed, 1 insertion(+), 1 deletion(-) rename Library/Homebrew/{ => compat}/gpg.rb (100%) diff --git a/Library/Homebrew/compat.rb b/Library/Homebrew/compat.rb index 8b3d72ec7b..d829e900cb 100644 --- a/Library/Homebrew/compat.rb +++ b/Library/Homebrew/compat.rb @@ -27,3 +27,4 @@ require "compat/ENV/std" require "compat/ENV/super" require "compat/utils/shell" require "compat/extend/string" +require "compat/gpg" diff --git a/Library/Homebrew/gpg.rb b/Library/Homebrew/compat/gpg.rb similarity index 100% rename from Library/Homebrew/gpg.rb rename to Library/Homebrew/compat/gpg.rb diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index eec2c9045e..8e4f80260b 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -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 From d54e670a6491ae3e6681448cfcf9332635149aa8 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 30 Dec 2017 18:58:30 +0000 Subject: [PATCH 2/4] requirements: move more to compat. --- Library/Homebrew/caveats.rb | 1 + .../Homebrew/compat/dependency_collector.rb | 52 +++++++++++++++---- Library/Homebrew/compat/requirements.rb | 6 +++ .../requirements/emacs_requirement.rb | 0 .../requirements/fortran_requirement.rb | 0 .../requirements/mpi_requirement.rb | 0 .../requirements/perl_requirement.rb | 0 .../requirements/python_requirement.rb | 0 .../requirements/ruby_requirement.rb | 0 Library/Homebrew/dependency_collector.rb | 20 ------- Library/Homebrew/dev-cmd/audit.rb | 19 +------ .../extend/os/mac/dependency_collector.rb | 11 ---- Library/Homebrew/requirements.rb | 6 --- .../Homebrew/requirements/java_requirement.rb | 2 +- .../requirements/xcode_requirement.rb | 2 +- .../test/dependency_collector_spec.rb | 2 +- .../Homebrew/test/formula_installer_spec.rb | 2 +- Library/Homebrew/test/formula_spec.rb | 14 ++--- Library/Homebrew/test/mpi_requirement_spec.rb | 4 +- .../test/os/mac/dependency_collector_spec.rb | 12 ----- .../Homebrew/test/rubocops/lines_cop_spec.rb | 13 ----- 21 files changed, 62 insertions(+), 104 deletions(-) rename Library/Homebrew/{ => compat}/requirements/emacs_requirement.rb (100%) rename Library/Homebrew/{ => compat}/requirements/fortran_requirement.rb (100%) rename Library/Homebrew/{ => compat}/requirements/mpi_requirement.rb (100%) rename Library/Homebrew/{ => compat}/requirements/perl_requirement.rb (100%) rename Library/Homebrew/{ => compat}/requirements/python_requirement.rb (100%) rename Library/Homebrew/{ => compat}/requirements/ruby_requirement.rb (100%) diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index ca1c2a9f89..8cd1053fbf 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -1,4 +1,5 @@ require "forwardable" +require "language/python" class Caveats extend Forwardable diff --git a/Library/Homebrew/compat/dependency_collector.rb b/Library/Homebrew/compat/dependency_collector.rb index 2e97d9d7fb..82511bcc74 100644 --- a/Library/Homebrew/compat/dependency_collector.rb +++ b/Library/Homebrew/compat/dependency_collector.rb @@ -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 diff --git a/Library/Homebrew/compat/requirements.rb b/Library/Homebrew/compat/requirements.rb index da6d867b3d..48911b52be 100644 --- a/Library/Homebrew/compat/requirements.rb +++ b/Library/Homebrew/compat/requirements.rb @@ -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 diff --git a/Library/Homebrew/requirements/emacs_requirement.rb b/Library/Homebrew/compat/requirements/emacs_requirement.rb similarity index 100% rename from Library/Homebrew/requirements/emacs_requirement.rb rename to Library/Homebrew/compat/requirements/emacs_requirement.rb diff --git a/Library/Homebrew/requirements/fortran_requirement.rb b/Library/Homebrew/compat/requirements/fortran_requirement.rb similarity index 100% rename from Library/Homebrew/requirements/fortran_requirement.rb rename to Library/Homebrew/compat/requirements/fortran_requirement.rb diff --git a/Library/Homebrew/requirements/mpi_requirement.rb b/Library/Homebrew/compat/requirements/mpi_requirement.rb similarity index 100% rename from Library/Homebrew/requirements/mpi_requirement.rb rename to Library/Homebrew/compat/requirements/mpi_requirement.rb diff --git a/Library/Homebrew/requirements/perl_requirement.rb b/Library/Homebrew/compat/requirements/perl_requirement.rb similarity index 100% rename from Library/Homebrew/requirements/perl_requirement.rb rename to Library/Homebrew/compat/requirements/perl_requirement.rb diff --git a/Library/Homebrew/requirements/python_requirement.rb b/Library/Homebrew/compat/requirements/python_requirement.rb similarity index 100% rename from Library/Homebrew/requirements/python_requirement.rb rename to Library/Homebrew/compat/requirements/python_requirement.rb diff --git a/Library/Homebrew/requirements/ruby_requirement.rb b/Library/Homebrew/compat/requirements/ruby_requirement.rb similarity index 100% rename from Library/Homebrew/requirements/ruby_requirement.rb rename to Library/Homebrew/compat/requirements/ruby_requirement.rb diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 2e955a5e2c..3164d237e1 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -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 diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 6da591f1ad..4982bfbc5e 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -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 => [] - Where 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 diff --git a/Library/Homebrew/extend/os/mac/dependency_collector.rb b/Library/Homebrew/extend/os/mac/dependency_collector.rb index 66dcf3afe6..03534bab96 100644 --- a/Library/Homebrew/extend/os/mac/dependency_collector.rb +++ b/Library/Homebrew/extend/os/mac/dependency_collector.rb @@ -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 diff --git a/Library/Homebrew/requirements.rb b/Library/Homebrew/requirements.rb index 456dabd0a7..e8c33465bc 100644 --- a/Library/Homebrew/requirements.rb +++ b/Library/Homebrew/requirements.rb @@ -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" diff --git a/Library/Homebrew/requirements/java_requirement.rb b/Library/Homebrew/requirements/java_requirement.rb index c49fdcba92..213203ff39 100644 --- a/Library/Homebrew/requirements/java_requirement.rb +++ b/Library/Homebrew/requirements/java_requirement.rb @@ -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 diff --git a/Library/Homebrew/requirements/xcode_requirement.rb b/Library/Homebrew/requirements/xcode_requirement.rb index ff167c6fdf..a5f078c629 100644 --- a/Library/Homebrew/requirements/xcode_requirement.rb +++ b/Library/Homebrew/requirements/xcode_requirement.rb @@ -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 diff --git a/Library/Homebrew/test/dependency_collector_spec.rb b/Library/Homebrew/test/dependency_collector_spec.rb index 5ba3c20bdc..cfbd260b35 100644 --- a/Library/Homebrew/test/dependency_collector_spec.rb +++ b/Library/Homebrew/test/dependency_collector_spec.rb @@ -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 diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index b85e75b81f..d3710a4cbc 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -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 diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 6ba6af3078..a9d09cb00b 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -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]) diff --git a/Library/Homebrew/test/mpi_requirement_spec.rb b/Library/Homebrew/test/mpi_requirement_spec.rb index f32b279934..87f99eb3ac 100644 --- a/Library/Homebrew/test/mpi_requirement_spec.rb +++ b/Library/Homebrew/test/mpi_requirement_spec.rb @@ -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] } diff --git a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb index 688149021c..357c35c2d6 100644 --- a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb +++ b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb @@ -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 diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 0d2146339c..ee1de059c9 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -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 From 4fff56ca4f04c710db4000c65ec4e1502b50b62b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 30 Dec 2017 18:58:41 +0000 Subject: [PATCH 3/4] lines_cop: check for more deprecated requirements. --- Library/Homebrew/rubocops/lines_cop.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index c96efd0b1c..fdeb165ed5 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -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)/) From f9b6407110d7fb98a65b470d166fc5b7be6052ee Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 30 Dec 2017 19:15:52 +0000 Subject: [PATCH 4/4] lines_cop: deprecate 'needs :openmp'. --- Library/Homebrew/rubocops/lines_cop.rb | 4 ++++ Library/Homebrew/test/rubocops/lines_cop_spec.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index fdeb165ed5..4e7aa1adb2 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -276,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}" diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index ee1de059c9..19492c252b 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -731,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