Module: DependenciesHelpers Private

Includes:
Kernel
Included in:
Homebrew::Cmd::Deps, Homebrew::Cmd::Uses
Defined in:
dependencies_helpers.rb,
dependencies_helpers.rbi

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Constant Summary

Constants included from Kernel

Kernel::IGNORE_INTERRUPTS_MUTEX

Instance Method Summary collapse

Methods included from Kernel

#disk_usage_readable, #ensure_executable!, #ensure_formula_installed!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #number_readable, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #paths, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #quiet_system, #redact_secrets, #redirect_stdout, #require?, #safe_system, #tap_and_name_comparison, #truncate_text_to_approximate_size, #which, #which_all, #which_editor, #with_custom_locale, #with_env, #with_homebrew_path

Instance Method Details

#args_includes_ignores(args) ⇒ Array<(Array<Symbol>, Array<Symbol>)>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This sig is in an RBI to avoid both circular dependencies and unnecessary requires



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'dependencies_helpers.rb', line 8

def args_includes_ignores(args)
  includes = [:required?, :recommended?] # included by default
  includes << :implicit? if args.include_implicit?
  includes << :build? if args.include_build?
  includes << :test? if args.include_test?
  includes << :optional? if args.include_optional?

  ignores = []
  ignores << :recommended? if args.skip_recommended?
  ignores << :satisfied? if args.missing?

  [includes, ignores]
end

#dependents(formulae_or_casks) ⇒ Array<Formula, CaskDependent>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



87
88
89
90
91
92
93
94
95
96
# File 'dependencies_helpers.rb', line 87

def dependents(formulae_or_casks)
  formulae_or_casks.map do |formula_or_cask|
    case formula_or_cask
    when Formula then formula_or_cask
    when Cask::Cask then CaskDependent.new(formula_or_cask)
    else
      raise TypeError, "Unsupported type: #{formula_or_cask.class}"
    end
  end
end

#recursive_dep_includes(root_dependent, includes, ignores) ⇒ Array<Dependency>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



26
27
28
29
30
# File 'dependencies_helpers.rb', line 26

def recursive_dep_includes(root_dependent, includes, ignores)
  # The use of T.unsafe is recommended by the Sorbet docs:
  #   https://sorbet.org/docs/overloads#multiple-methods-but-sharing-a-common-implementation
  T.unsafe(recursive_includes(Dependency, root_dependent, includes, ignores))
end

#recursive_includes(klass, root_dependent, includes, ignores) ⇒ Array<Dependency>, Requirements

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'dependencies_helpers.rb', line 50

def recursive_includes(klass, root_dependent, includes, ignores)
  cache_key = "recursive_includes_#{includes}_#{ignores}"

  klass.expand(root_dependent, cache_key:) do |dependent, dep|
    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.public_send(include)
    end

    # 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.
    Dependency.keep_but_prune_recursive_deps if klass == Dependency && dep.tap && !dep.tap.installed?
  end
end

#recursive_req_includes(root_dependent, includes, ignores) ⇒ Requirements

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



36
37
38
39
40
# File 'dependencies_helpers.rb', line 36

def recursive_req_includes(root_dependent, includes, ignores)
  # The use of T.unsafe is recommended by the Sorbet docs:
  #   https://sorbet.org/docs/overloads#multiple-methods-but-sharing-a-common-implementation
  T.unsafe(recursive_includes(Requirement, root_dependent, includes, ignores))
end

#select_includes(dependables, ignores, includes) ⇒ Array<Dependency, Requirement>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



75
76
77
78
79
80
81
# File 'dependencies_helpers.rb', line 75

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

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