Skip to content

Commit

Permalink
dependency_helpers: include required & use public_send
Browse files Browse the repository at this point in the history
- Use .required? instead of .tags.empty?
- use .public_send
- modify .reject_ignores to be .select_includes
  - checks ignores first now
- Don't use runtime deps with --missing in `brew deps` command
  • Loading branch information
apainintheneck committed Aug 25, 2023
1 parent 3cba4cb commit e314a43
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
11 changes: 6 additions & 5 deletions Library/Homebrew/cmd/deps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def self.deps
!args.include_build? &&
!args.include_test? &&
!args.include_optional? &&
!args.skip_recommended?
!args.skip_recommended? &&
!args.missing?

if args.tree? || args.graph?
dependents = if args.named.present?
Expand Down Expand Up @@ -197,8 +198,8 @@ def self.deps_for_dependent(dependency, args:, recursive: false)
deps ||= recursive_includes(Dependency, dependency, includes, ignores)
reqs = recursive_includes(Requirement, dependency, includes, ignores)
else
deps ||= reject_ignores(dependency.deps, ignores, includes)
reqs = reject_ignores(dependency.requirements, ignores, includes)
deps ||= select_includes(dependency.deps, ignores, includes)
reqs = select_includes(dependency.requirements, ignores, includes)
end

deps + reqs.to_a
Expand Down Expand Up @@ -269,8 +270,8 @@ def self.puts_deps_tree(dependents, args:, recursive: false)
def self.dependables(formula, args:)
includes, ignores = args_includes_ignores(args)
deps = @use_runtime_dependencies ? formula.runtime_dependencies : formula.deps
deps = reject_ignores(deps, ignores, includes)
reqs = reject_ignores(formula.requirements, ignores, includes) if args.include_requirements?
deps = select_includes(deps, ignores, includes)
reqs = select_includes(formula.requirements, ignores, includes) if args.include_requirements?
reqs ||= []
reqs + deps
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/uses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def self.select_used_dependents(dependents, used_formulae, recursive, includes,
deps = if recursive
recursive_includes(Dependency, d, includes, ignores)
else
reject_ignores(d.deps, ignores, includes)
select_includes(d.deps, ignores, includes)
end

used_formulae.all? do |ff|
Expand Down
18 changes: 8 additions & 10 deletions Library/Homebrew/dependencies_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# @api private
module DependenciesHelpers
def args_includes_ignores(args)
includes = [:recommended?] # included by default
includes = [:required?, :recommended?] # included by default
includes << :build? if args.include_build?
includes << :test? if args.include_test?
includes << :optional? if args.include_optional?
Expand All @@ -26,14 +26,12 @@ def recursive_includes(klass, root_dependent, includes, ignores)
cache_key = "recursive_includes_#{includes}_#{ignores}"

klass.expand(root_dependent, cache_key: cache_key) do |dependent, dep|
klass.prune if ignores.any? { |ignore| dep.send(ignore) }

# NOTE: Untagged dependencies are runtime dependencies and are included by default.
klass.prune if !dep.tags.empty? && includes.none? do |include|
klass.prune if ignores.any? { |ignore| dep.public_send(ignore) }
klass.prune if includes.none? do |include|
# Ignore indirect test dependencies
next if include == :test? && dependent != root_dependent

dep.send(include)
dep.public_send(include)
end

# If a tap isn't installed, we can't find the dependencies of one of
Expand All @@ -42,11 +40,11 @@ def recursive_includes(klass, root_dependent, includes, ignores)
end
end

def reject_ignores(dependables, ignores, includes)
dependables.reject do |dep|
next false unless ignores.any? { |ignore| dep.send(ignore) }
def select_includes(dependables, ignores, includes)
dependables.select do |dep|
next false if ignores.any? { |ignore| dep.public_send(ignore) }

includes.none? { |include| dep.send(include) }
includes.any? { |include| dep.public_send(include) }
end
end

Expand Down

0 comments on commit e314a43

Please sign in to comment.