diff --git a/Library/Homebrew/compat.rb b/Library/Homebrew/compat.rb index 6c3fa2dbba..a882f5a699 100644 --- a/Library/Homebrew/compat.rb +++ b/Library/Homebrew/compat.rb @@ -29,3 +29,4 @@ require "compat/ENV/super" require "compat/utils/shell" require "compat/extend/string" require "compat/gpg" +require "compat/dependable" diff --git a/Library/Homebrew/compat/dependable.rb b/Library/Homebrew/compat/dependable.rb new file mode 100644 index 0000000000..faeeb9b183 --- /dev/null +++ b/Library/Homebrew/compat/dependable.rb @@ -0,0 +1,5 @@ +module Dependable + def run? + tags.include? :run + end +end diff --git a/Library/Homebrew/compat/dependency_collector.rb b/Library/Homebrew/compat/dependency_collector.rb index 8bea8a5aa9..9ee2b14035 100644 --- a/Library/Homebrew/compat/dependency_collector.rb +++ b/Library/Homebrew/compat/dependency_collector.rb @@ -33,7 +33,6 @@ class DependencyCollector output_deprecation(spec) Dependency.new(spec.to_s, tags) when :libltdl - tags << :run output_deprecation("libtool") Dependency.new("libtool", tags) when :apr @@ -68,7 +67,7 @@ class DependencyCollector private def autotools_dep(spec, tags) - tags << :build unless tags.include? :run + tags << :build Dependency.new(spec.to_s, tags) end diff --git a/Library/Homebrew/dependable.rb b/Library/Homebrew/dependable.rb index 8722188388..b6196e939c 100644 --- a/Library/Homebrew/dependable.rb +++ b/Library/Homebrew/dependable.rb @@ -1,6 +1,8 @@ require "options" module Dependable + # :run and :linked are no longer used but keep them here to avoid them being + # misused in future. RESERVED_TAGS = [:build, :optional, :recommended, :run, :test, :linked].freeze def build? @@ -15,10 +17,6 @@ module Dependable tags.include? :recommended end - def run? - tags.include? :run - end - def test? tags.include? :test end diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb index d64d46f66a..0697ba7ff3 100644 --- a/Library/Homebrew/dependency.rb +++ b/Library/Homebrew/dependency.rb @@ -163,13 +163,9 @@ class Dependency end def merge_temporality(deps) - if deps.all?(&:build?) - [:build] - elsif deps.all?(&:run?) - [:run] - else - [] # Means both build and runtime dependency. - end + # Means both build and runtime dependency. + return [] unless deps.all?(&:build?) + [:build] end end end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index dddf8a2030..8db1ce2f75 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -172,23 +172,6 @@ class FormulaAuditor attr_reader :formula, :text, :problems - BUILD_TIME_DEPS = %w[ - autoconf - automake - boost-build - bsdmake - cmake - godep - imake - intltool - libtool - pkg-config - scons - smake - sphinx-doc - swig - ].freeze - def initialize(formula, options = {}) @formula = formula @new_formula = options[:new_formula] @@ -377,17 +360,12 @@ class FormulaAuditor problem "Dependency #{dep} does not define option #{opt.name.inspect}" end - case dep.name - when "git" + if dep.name == "git" problem "Don't use git as a dependency (it's always available)" - when *BUILD_TIME_DEPS - next if dep.build? || dep.run? - problem <<~EOS - #{dep} dependency should be - depends_on "#{dep}" => :build - Or if it is indeed a runtime dependency - depends_on "#{dep}" => :run - EOS + end + + if dep.tags.include?(:run) + problem "Dependency '#{dep.name}' is marked as :run. Remove :run; it is a no-op." end end end diff --git a/Library/Homebrew/rubocops/dependency_order_cop.rb b/Library/Homebrew/rubocops/dependency_order_cop.rb index 1d1481f280..ef93141a4d 100644 --- a/Library/Homebrew/rubocops/dependency_order_cop.rb +++ b/Library/Homebrew/rubocops/dependency_order_cop.rb @@ -48,7 +48,7 @@ module RuboCop def sort_dependencies_by_type(dependency_nodes) ordered = [] ordered.concat(dependency_nodes.select { |dep| buildtime_dependency? dep }.to_a) - ordered.concat(dependency_nodes.select { |dep| runtime_dependency? dep }.to_a) + ordered.concat(dependency_nodes.select { |dep| test_dependency? dep }.to_a) ordered.concat(dependency_nodes.reject { |dep| negate_normal_dependency? dep }.to_a) ordered.concat(dependency_nodes.select { |dep| recommended_dependency? dep }.to_a) ordered.concat(dependency_nodes.select { |dep| optional_dependency? dep }.to_a) @@ -106,11 +106,11 @@ module RuboCop def_node_search :recommended_dependency?, "(sym :recommended)" - def_node_search :runtime_dependency?, "(sym :run)" + def_node_search :test_dependency?, "(sym :test)" def_node_search :optional_dependency?, "(sym :optional)" - def_node_search :negate_normal_dependency?, "(sym {:build :recommended :run :optional})" + def_node_search :negate_normal_dependency?, "(sym {:build :recommended :test :optional})" # Node pattern method to extract `name` in `depends_on :name` def_node_search :dependency_name_node, <<~EOS diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 2c20e62dec..ae343a9fc2 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -171,7 +171,7 @@ module RuboCop when :required type_match = required_dependency?(node) name_match ||= required_dependency_name?(node, name) if type_match - when :build, :optional, :recommended, :run + when :build, :test, :optional, :recommended type_match = dependency_type_hash_match?(node, type) name_match ||= dependency_name_hash_match?(node, name) if type_match when :any diff --git a/Library/Homebrew/test/dependency_spec.rb b/Library/Homebrew/test/dependency_spec.rb index 4f1e8d474c..6ac2acca2c 100644 --- a/Library/Homebrew/test/dependency_spec.rb +++ b/Library/Homebrew/test/dependency_spec.rb @@ -2,7 +2,6 @@ require "dependency" describe Dependency do alias_matcher :be_a_build_dependency, :be_build - alias_matcher :be_a_runtime_dependency, :be_run describe "::new" do it "accepts a single tag" do @@ -73,22 +72,10 @@ describe Dependency do it "merges temporality tags" do normal_dep = described_class.new("foo") build_dep = described_class.new("foo", [:build]) - run_dep = described_class.new("foo", [:run]) deps = described_class.merge_repeats([normal_dep, build_dep]) expect(deps.count).to eq(1) expect(deps.first).not_to be_a_build_dependency - expect(deps.first).not_to be_a_runtime_dependency - - deps = described_class.merge_repeats([normal_dep, run_dep]) - expect(deps.count).to eq(1) - expect(deps.first).not_to be_a_build_dependency - expect(deps.first).not_to be_a_runtime_dependency - - deps = described_class.merge_repeats([build_dep, run_dep]) - expect(deps.count).to eq(1) - expect(deps.first).not_to be_a_build_dependency - expect(deps.first).not_to be_a_runtime_dependency end end diff --git a/docs/Formula-Cookbook.md b/docs/Formula-Cookbook.md index 1f2b2e89e2..3f6902409a 100644 --- a/docs/Formula-Cookbook.md +++ b/docs/Formula-Cookbook.md @@ -130,7 +130,7 @@ to favour finding `keg_only` formulae first. ```ruby class Foo < Formula - depends_on "pkg-config" => :run + depends_on "pkg-config" depends_on "jpeg" depends_on "readline" => :recommended depends_on "gtk+" => :optional @@ -144,16 +144,13 @@ A Symbol (e.g. `:x11`) specifies a [`Requirement`](http://www.rubydoc.info/githu A Hash (e.g. `=>`) specifies a formula dependency with some additional information. Given a single string key, the value can take several forms: -* a Symbol (currently one of `:build`, `:optional`, `:run` or `:recommended`) +* a Symbol (currently one of `:build`, `:test`, `:optional` or `:recommended`) - `:build` means that dependency is a build-time only dependency so it can be skipped when installing from a bottle or when listing missing dependencies using `brew missing`. + - `:test` means that dependency is only required when running `brew test`. - `:optional` generates an implicit `with-foo` option for the formula. This means that, given `depends_on "foo" => :optional`, the user must pass `--with-foo` in order to use the dependency. - - `:run` can mean the dependency is only required at runtime, or it can be used - to declare build dependencies such as `pkg-config` that are needed at - runtime as well, which will silence the audit warning. `:run` dependencies - are currently available at build time. - `:recommended` generates an implicit `without-foo` option, meaning that the dependency is enabled by default and the user must pass `--without-foo` to disable this dependency. The default