diff --git a/Library/Homebrew/dependencies_helpers.rb b/Library/Homebrew/dependencies_helpers.rb index 8006882b11..dd2a3acd2e 100644 --- a/Library/Homebrew/dependencies_helpers.rb +++ b/Library/Homebrew/dependencies_helpers.rb @@ -56,11 +56,7 @@ module DependenciesHelpers # If a tap isn't installed, we can't find the dependencies of one of # its formulae, and an exception will be thrown if we try. - if klass == Dependency && - dep.is_a?(TapDependency) && - !dep.tap.installed? - Dependency.keep_but_prune_recursive_deps - end + Dependency.keep_but_prune_recursive_deps if klass == Dependency && dep.tap && !dep.tap.installed? end end diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb index 14b4b9d48b..a371a7d58a 100644 --- a/Library/Homebrew/dependency.rb +++ b/Library/Homebrew/dependency.rb @@ -11,18 +11,20 @@ class Dependency include Dependable extend Cachable - attr_reader :name, :env_proc, :option_names + attr_reader :name, :env_proc, :option_names, :tap DEFAULT_ENV_PROC = proc {}.freeze private_constant :DEFAULT_ENV_PROC - def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name]) + def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name&.split("/")&.last]) raise ArgumentError, "Dependency must have a name!" unless name @name = name @tags = tags @env_proc = env_proc @option_names = option_names + + @tap = Tap.fetch(Regexp.last_match(1), Regexp.last_match(2)) if name =~ HOMEBREW_TAP_FORMULA_REGEX end def to_s @@ -46,6 +48,8 @@ class Dependency def installed? to_formula.latest_version_installed? + rescue FormulaUnavailableError + false end def satisfied?(inherited_options = []) @@ -204,19 +208,3 @@ class Dependency end end end - -# A dependency on another Homebrew formula in a specific tap. -class TapDependency < Dependency - attr_reader :tap - - def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name.split("/").last]) - @tap = Tap.fetch(name.rpartition("/").first) - super(name, tags, env_proc, option_names) - end - - def installed? - super - rescue FormulaUnavailableError - false - end -end diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index b05addd086..6288462cb3 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -144,11 +144,7 @@ class DependencyCollector end def parse_string_spec(spec, tags) - if spec.match?(HOMEBREW_TAP_FORMULA_REGEX) - TapDependency.new(spec, tags) - else - Dependency.new(spec, tags) - end + Dependency.new(spec, tags) end def parse_symbol_spec(spec, tags) diff --git a/Library/Homebrew/test/dependency_spec.rb b/Library/Homebrew/test/dependency_spec.rb index 431006cb57..b9367544c2 100644 --- a/Library/Homebrew/test/dependency_spec.rb +++ b/Library/Homebrew/test/dependency_spec.rb @@ -100,15 +100,20 @@ describe Dependency do expect(foo1).not_to eql(foo3) end - describe TapDependency do - subject(:dependency) { described_class.new("foo/bar/dog") } - - specify "#tap" do + describe "#tap" do + it "returns a tap passed a fully-qualified name" do + dependency = described_class.new("foo/bar/dog") expect(dependency.tap).to eq(Tap.new("foo", "bar")) end - specify "#option_names" do - expect(dependency.option_names).to eq(%w[dog]) + it "returns no tap passed a simple name" do + dependency = described_class.new("dog") + expect(dependency.tap).to be_nil end end + + specify "#option_names" do + dependency = described_class.new("foo/bar/dog") + expect(dependency.option_names).to eq(%w[dog]) + end end