Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependency: cleanup unused code #16421

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 9 additions & 29 deletions Library/Homebrew/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@
include Dependable
extend Cachable

attr_reader :name, :env_proc, :option_names, :tap
attr_reader :name, :tap

DEFAULT_ENV_PROC = proc {}.freeze
private_constant :DEFAULT_ENV_PROC

def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name&.split("/")&.last])
def initialize(name, tags = [])
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
Expand Down Expand Up @@ -90,8 +85,8 @@
required
end

def modify_build_environment
env_proc&.call
def option_names
[name.split("/").last].freeze
end

sig { overridable.returns(T::Boolean) }
Expand All @@ -104,18 +99,9 @@
"#<#{self.class.name}: #{name.inspect} #{tags.inspect}>"
end

# Define marshaling semantics because we cannot serialize @env_proc.
def _dump(*)
Marshal.dump([name, tags])
end

def self._load(marshaled)
new(*Marshal.load(marshaled)) # rubocop:disable Security/MarshalLoad
end

sig { params(formula: Formula).returns(T.self_type) }
def dup_with_formula_name(formula)
self.class.new(formula.full_name.to_s, tags, env_proc, option_names)
self.class.new(formula.full_name.to_s, tags)
end

class << self
Expand Down Expand Up @@ -202,15 +188,9 @@
deps = grouped.fetch(name)
dep = deps.first
tags = merge_tags(deps)
option_names = deps.flat_map(&:option_names).uniq
kwargs = {}
kwargs[:bounds] = dep.bounds if dep.uses_from_macos?
# TODO: simpify to just **kwargs when we require Ruby >= 2.7
if kwargs.empty?
dep.class.new(name, tags, dep.env_proc, option_names)
else
dep.class.new(name, tags, dep.env_proc, option_names, **kwargs)
end
dep.class.new(name, tags, **kwargs)
end
end

Expand Down Expand Up @@ -250,8 +230,8 @@
class UsesFromMacOSDependency < Dependency
attr_reader :bounds

def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name], bounds:)
super(name, tags, env_proc, option_names)
def initialize(name, tags = [], bounds:)
super(name, tags)

@bounds = bounds
end
Expand Down Expand Up @@ -293,7 +273,7 @@

sig { override.params(formula: Formula).returns(T.self_type) }
def dup_with_formula_name(formula)
self.class.new(formula.full_name.to_s, tags, env_proc, option_names, bounds: bounds)
self.class.new(formula.full_name.to_s, tags, bounds: bounds)

Check warning on line 276 in Library/Homebrew/dependency.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dependency.rb#L276

Added line #L276 was not covered by tests
end

sig { returns(String) }
Expand Down
9 changes: 0 additions & 9 deletions Library/Homebrew/test/dependency_expansion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ def build_dep(name, tags = [], deps = [])
end
end

it "merges dependencies and preserves env_proc" do
env_proc = double
dep = described_class.new("foo", [], env_proc)
allow(dep).to receive(:to_formula).and_return \
instance_double(Formula, deps: [], name: "foo", full_name: "foo")
deps.replace([dep])
expect(described_class.expand(formula).first.env_proc).to eq(env_proc)
end

it "merges tags without duplicating them" do
foo2 = build_dep(:foo, ["option"])
foo3 = build_dep(:foo, ["option"])
Expand Down
10 changes: 3 additions & 7 deletions Library/Homebrew/test/dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,18 @@

describe "::merge_repeats" do
it "merges duplicate dependencies" do
dep = described_class.new("foo", [:build], nil, "foo")
dep2 = described_class.new("foo", ["bar"], nil, "foo2")
dep3 = described_class.new("xyz", ["abc"], nil, "foo")
dep = described_class.new("foo", [:build])
dep2 = described_class.new("foo", ["bar"])
dep3 = described_class.new("xyz", ["abc"])
merged = described_class.merge_repeats([dep, dep2, dep3])
expect(merged.count).to eq(2)
expect(merged.first).to be_a described_class

foo_named_dep = merged.find { |d| d.name == "foo" }
expect(foo_named_dep.tags).to eq(["bar"])
expect(foo_named_dep.option_names).to include("foo")
expect(foo_named_dep.option_names).to include("foo2")

xyz_named_dep = merged.find { |d| d.name == "xyz" }
expect(xyz_named_dep.tags).to eq(["abc"])
expect(xyz_named_dep.option_names).to include("foo")
expect(xyz_named_dep.option_names).not_to include("foo2")
end

it "merges necessity tags" do
Expand Down