Class: Dependency
Overview
This class is part of an internal API. This class may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
A dependency on another Homebrew formula.
Direct Known Subclasses
Constant Summary
Constants included from Dependable
Instance Attribute Summary collapse
- #name ⇒ String readonly private
- #tap ⇒ Tap? readonly private
Attributes included from Dependable
Class Method Summary collapse
- .action(dependent, dep, &block) ⇒ Object internal
- .cache(key, cache_timestamp: nil) ⇒ Object internal
- .clear_cache ⇒ Object internal
- .delete_timestamped_cache_entry(key, cache_timestamp) ⇒ Object internal
-
.expand(dependent, deps = dependent.deps, cache_key: nil, cache_timestamp: nil, &block) ⇒ Object
internal
Expand the dependencies of each dependent recursively, optionally yielding
[dependent, dep]pairs to allow callers to apply arbitrary filters to the list. -
.keep_but_prune_recursive_deps ⇒ void
internal
Keep a dependency, but prune its dependencies.
- .merge_repeats(all) ⇒ Object internal
-
.prune ⇒ void
private
Prune a dependency and its dependencies recursively.
-
.skip ⇒ void
private
Prune a single dependency but do not prune its dependencies.
Instance Method Summary collapse
- #dup_with_formula_name(formula) ⇒ T.self_type private
-
#initialize(name, tags = []) ⇒ Dependency
constructor
internal
A new instance of Dependency.
- #installed?(minimum_version: nil, minimum_revision: nil, minimum_compatibility_version: nil, bottle_os_version: nil) ⇒ Boolean private
- #missing_options(inherited_options) ⇒ Object internal
- #option_names ⇒ Object internal
- #satisfied?(inherited_options = [], minimum_version: nil, minimum_revision: nil, minimum_compatibility_version: nil, bottle_os_version: nil) ⇒ Boolean internal
- #to_formula ⇒ Object internal
- #to_installed_formula ⇒ Object internal
- #uses_from_macos? ⇒ Boolean private
Methods included from Dependable
#build?, #implicit?, #no_linkage?, #option_tags, #optional?, #options, #prune_from_option?, #prune_if_build_and_not_dependent?, #recommended?, #required?, #test?
Constructor Details
#initialize(name, tags = []) ⇒ Dependency
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a new instance of Dependency.
18 19 20 21 22 23 24 25 26 27 |
# File 'dependency.rb', line 18 def initialize(name, = []) raise ArgumentError, "Dependency must have a name!" unless name @name = name @tags = return unless (tap_with_name = Tap.with_formula_name(name)) @tap, = tap_with_name end |
Instance Attribute Details
#name ⇒ String (readonly)
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.
13 14 15 |
# File 'dependency.rb', line 13 def name @name end |
#tap ⇒ Tap? (readonly)
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.
16 17 18 |
# File 'dependency.rb', line 16 def tap @tap end |
Class Method Details
.action(dependent, dep, &block) ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
198 199 200 201 202 203 204 205 206 |
# File 'dependency.rb', line 198 def action(dependent, dep, &block) catch(:action) do if block yield dependent, dep elsif dep.optional? || dep.recommended? prune unless dependent.build.with?(dep) end end end |
.cache(key, cache_timestamp: nil) ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
241 242 243 244 245 246 247 248 249 250 |
# File 'dependency.rb', line 241 def cache(key, cache_timestamp: nil) @cache ||= { timestamped: {}, not_timestamped: {} } if @cache[:timestamped][] ||= {} @cache[:timestamped][][key] ||= {} else @cache[:not_timestamped][key] ||= {} end end |
.clear_cache ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
252 253 254 255 256 257 258 |
# File 'dependency.rb', line 252 def clear_cache return unless @cache # No need to clear the timestamped cache as it's timestamped, and doing so causes problems in `expand`. # See https://github.com/Homebrew/brew/pull/20896#issuecomment-3419257460 @cache[:not_timestamped].clear end |
.delete_timestamped_cache_entry(key, cache_timestamp) ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
260 261 262 263 264 265 266 |
# File 'dependency.rb', line 260 def (key, ) return unless @cache return unless ( = @cache[:timestamped][]) .delete(key) @cache[:timestamped].delete() if .empty? end |
.expand(dependent, deps = dependent.deps, cache_key: nil, cache_timestamp: nil, &block) ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Expand the dependencies of each dependent recursively, optionally yielding
[dependent, dep] pairs to allow callers to apply arbitrary filters to
the list.
The default filter, which is applied when a block is not given, omits
optionals and recommends based on what the dependent has asked for
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'dependency.rb', line 152 def (dependent, deps = dependent.deps, cache_key: nil, cache_timestamp: nil, &block) # Keep track dependencies to avoid infinite cyclic dependency recursion. @expand_stack ||= [] @expand_stack.push dependent.name if cache_key.present? cache_key = "#{cache_key}-#{}" if if (entry = cache(cache_key, cache_timestamp:)[cache_id dependent]) return entry.dup end end = [] deps.each do |dep| next if dependent.name == dep.name case action(dependent, dep, &block) when :prune next when :skip next if @expand_stack.include? dep.name .concat((dep.to_formula, cache_key:, &block)) when :keep_but_prune_recursive_deps << dep else next if @expand_stack.include? dep.name dep_formula = dep.to_formula .concat((dep_formula, cache_key:, &block)) # Fixes names for renamed/aliased formulae. dep = dep.dup_with_formula_name(dep_formula) << dep end end = merge_repeats() cache(cache_key, cache_timestamp:)[cache_id dependent] = .dup if cache_key.present? ensure @expand_stack.pop end |
.keep_but_prune_recursive_deps ⇒ void
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Keep a dependency, but prune its dependencies.
224 225 226 |
# File 'dependency.rb', line 224 def keep_but_prune_recursive_deps throw(:action, :keep_but_prune_recursive_deps) end |
.merge_repeats(all) ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'dependency.rb', line 228 def merge_repeats(all) grouped = all.group_by(&:name) all.map(&:name).uniq.map do |name| deps = grouped.fetch(name) dep = deps.first = (deps) kwargs = {} kwargs[:bounds] = dep.bounds if dep.uses_from_macos? dep.class.new(name, , **kwargs) end end |
.prune ⇒ void
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 method returns an undefined value.
Prune a dependency and its dependencies recursively.
210 211 212 |
# File 'dependency.rb', line 210 def prune throw(:action, :prune) end |
.skip ⇒ void
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 method returns an undefined value.
Prune a single dependency but do not prune its dependencies.
216 217 218 |
# File 'dependency.rb', line 216 def skip throw(:action, :skip) end |
Instance Method Details
#dup_with_formula_name(formula) ⇒ T.self_type
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.
140 141 142 |
# File 'dependency.rb', line 140 def dup_with_formula_name(formula) self.class.new(formula.full_name.to_s, ) end |
#installed?(minimum_version: nil, minimum_revision: nil, minimum_compatibility_version: nil, bottle_os_version: nil) ⇒ Boolean
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.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'dependency.rb', line 58 def installed?(minimum_version: nil, minimum_revision: nil, minimum_compatibility_version: nil, bottle_os_version: nil) formula = begin to_installed_formula rescue FormulaUnavailableError nil end return false unless formula # If the opt prefix doesn't exist: we likely have an incomplete installation. return false unless formula.opt_prefix.exist? return true if formula.latest_version_installed? return false if minimum_version.blank? installed_keg = formula.any_installed_keg return false unless installed_keg # If the keg name doesn't match, we may have moved from an alias to a full formula and need to upgrade. return false unless formula.possible_names.include?(installed_keg.name) installed_version = installed_keg.version # If both the formula and minimum dependency have a compatibility_version set, # and they match, the dependency is satisfied regardless of version/revision. if minimum_compatibility_version.present? && formula.compatibility_version.present? installed_tab = Tab.for_keg(installed_keg) installed_compatibility_version = installed_tab.source&.dig("versions", "compatibility_version") # If installed version has same compatibility_version as required, it's compatible return true if installed_compatibility_version == minimum_compatibility_version && formula.compatibility_version == minimum_compatibility_version end # Tabs prior to 4.1.18 did not have revision or pkg_version fields. # As a result, we have to be more conversative when we do not have # a minimum revision from the tab and assume that if the formula has a # the same version and a non-zero revision that it needs upgraded. if minimum_revision.present? minimum_pkg_version = PkgVersion.new(minimum_version, minimum_revision) installed_version >= minimum_pkg_version elsif installed_version.version == minimum_version formula.revision.zero? else installed_version.version > minimum_version end end |
#missing_options(inherited_options) ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
113 114 115 116 117 118 119 120 |
# File 'dependency.rb', line 113 def () formula = to_installed_formula required = required |= required &= formula..to_a required -= Tab.for_formula(formula). required end |
#option_names ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
122 123 124 |
# File 'dependency.rb', line 122 def option_names [name.split("/").last].freeze end |
#satisfied?(inherited_options = [], minimum_version: nil, minimum_revision: nil, minimum_compatibility_version: nil, bottle_os_version: nil) ⇒ Boolean
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
107 108 109 110 111 |
# File 'dependency.rb', line 107 def satisfied?( = [], minimum_version: nil, minimum_revision: nil, minimum_compatibility_version: nil, bottle_os_version: nil) installed?(minimum_version:, minimum_revision:, minimum_compatibility_version:, bottle_os_version:) && ().empty? end |
#to_formula ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
44 45 46 47 48 |
# File 'dependency.rb', line 44 def to_formula formula = Formulary.factory(name, warn: false) formula.build = BuildOptions.new(, formula.) formula end |
#to_installed_formula ⇒ Object
This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
38 39 40 41 42 |
# File 'dependency.rb', line 38 def to_installed_formula formula = Formulary.resolve(name) formula.build = BuildOptions.new(, formula.) formula end |
#uses_from_macos? ⇒ Boolean
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.
127 128 129 |
# File 'dependency.rb', line 127 def uses_from_macos? false end |