Class: DependencyCollector Private

Inherits:
Object show all
Extended by:
Cacheable, T::Generic
Includes:
OS::Linux::DependencyCollector, OS::Mac::DependencyCollector
Defined in:
dependency_collector.rb

Overview

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

This class is used by depends_on in the formula DSL to turn dependency specifications into the proper kinds of dependencies and requirements.

Constant Summary collapse

Cache =

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

type_template { { fixed: T::Hash[T.untyped, T.untyped] } }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cacheable

cache, clear_cache

Methods included from OS::Linux::DependencyCollector

#global_dep_tree

Constructor Details

#initialize ⇒ 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.



33
34
35
36
37
38
39
# File 'dependency_collector.rb', line 33

def initialize
  # Ensure this is synced with `initialize_dup` and `freeze` (excluding simple objects like integers and booleans)
  @deps = T.let(Dependencies.new, Dependencies)
  @requirements = T.let(Requirements.new, Requirements)

  init_global_dep_tree_if_needed!
end

Instance Attribute Details

#deps ⇒ Dependencies (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.

Returns:



27
28
29
# File 'dependency_collector.rb', line 27

def deps
  @deps
end

#requirements ⇒ Requirements (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.

Returns:



30
31
32
# File 'dependency_collector.rb', line 30

def requirements
  @requirements
end

Class Method Details

.tar_needs_bzip2_dependency? ⇒ 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.

Returns:

  • (Boolean)


181
182
183
# File 'dependency_collector.rb', line 181

def self.tar_needs_bzip2_dependency?
  !new.bzip2_dep_if_needed([]).nil?
end

.tar_needs_xz_dependency? ⇒ 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.

Returns:

  • (Boolean)


176
177
178
# File 'dependency_collector.rb', line 176

def self.tar_needs_xz_dependency?
  !new.xz_dep_if_needed([]).nil?
end

Instance Method Details

#add(spec) ⇒ T.untyped

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:

  • spec (T.untyped)

Returns:

  • (T.untyped)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'dependency_collector.rb', line 56

def add(spec)
  case dep = fetch(spec)
  when Array
    dep.compact.each { |dep| @deps << dep }
  when Dependency
    @deps << dep
  when Requirement
    @requirements << dep
  when nil
    # no-op when we have a nil value
    nil
  else
    raise ArgumentError, "DependencyCollector#add passed something that isn't a Dependency or Requirement!"
  end
  dep
end

#build(spec) ⇒ T.untyped

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:

  • spec (T.untyped)

Returns:

  • (T.untyped)

Raises:

  • (ArgumentError)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'dependency_collector.rb', line 92

def build(spec)
  spec, tags = spec.is_a?(Hash) ? spec.first : spec
  tags = Array(tags)
  raise ArgumentError, "Implicit dependencies cannot be manually specified" if tags.include?(:implicit)

  case spec
  when String
    Dependency.new(spec, tags)
  when Resource
    resource_dep(spec, tags)
  when Symbol
    parse_symbol_spec(spec, tags)
  when Requirement, Dependency
    spec
  when Class
    raise TypeError, "#{spec.inspect} is not a Requirement subclass" unless spec < Requirement

    spec.new(tags)
  end
end

#bzip2_dep_if_needed(tags) ⇒ 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:



171
172
173
# File 'dependency_collector.rb', line 171

def bzip2_dep_if_needed(tags)
  Dependency.new("bzip2", [*tags, :implicit]) unless which("bzip2")
end

#cache_key(spec) ⇒ T.untyped

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:

  • spec (T.untyped)

Returns:

  • (T.untyped)


79
80
81
82
83
84
85
86
87
88
89
# File 'dependency_collector.rb', line 79

def cache_key(spec)
  if spec.is_a?(Resource)
    if spec.download_strategy <= CurlDownloadStrategy
      extension = File.extname(resource_url(spec)).split("?").first
      return "#{spec.download_strategy}#{extension}#{spec.test?}"
    end

    return [spec.download_strategy, spec.test?]
  end
  spec
end

#curl_dep_if_needed(tags) ⇒ 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:



138
139
140
# File 'dependency_collector.rb', line 138

def curl_dep_if_needed(tags)
  Dependency.new("curl", [*tags, :implicit])
end

#cvs_dep_if_needed(tags) ⇒ 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:



151
152
153
# File 'dependency_collector.rb', line 151

def cvs_dep_if_needed(tags)
  Dependency.new("cvs", [*tags, :implicit]) unless which("cvs")
end

#fetch(spec) ⇒ T.untyped

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:

  • spec (T.untyped)

Returns:

  • (T.untyped)


74
75
76
# File 'dependency_collector.rb', line 74

def fetch(spec)
  self.class.cache.fetch(cache_key(spec)) { |key| self.class.cache[key] = build(spec) }
end

#freeze ⇒ 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.



49
50
51
52
53
# File 'dependency_collector.rb', line 49

def freeze
  @deps.freeze
  @requirements.freeze
  super
end

#gcc_dep_if_needed(related_formula_names) ⇒ 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:

  • related_formula_names (Set<String>)

Returns:



114
# File 'dependency_collector.rb', line 114

def gcc_dep_if_needed(related_formula_names); end

#git_dep_if_needed(tags) ⇒ 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:



130
131
132
133
134
135
# File 'dependency_collector.rb', line 130

def git_dep_if_needed(tags)
  require "utils/git"
  return if Utils::Git.available?

  Dependency.new("git", [*tags, :implicit])
end

#glibc_dep_if_needed(related_formula_names) ⇒ 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:

  • related_formula_names (Set<String>)

Returns:



117
# File 'dependency_collector.rb', line 117

def glibc_dep_if_needed(related_formula_names); end

#implicit_dependency_names ⇒ Set<String>

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.

Names implicitly added to any formula's deps right now, reusing the same checks Formula#add_global_deps_to_spec uses to inject them onto a real formula.

Returns:



122
123
124
125
126
127
# File 'dependency_collector.rb', line 122

def implicit_dependency_names
  [
    gcc_dep_if_needed(Set.new),
    glibc_dep_if_needed(Set.new),
  ].compact.to_set(&:name)
end

#initialize_dup(other) ⇒ 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.

Parameters:



42
43
44
45
46
# File 'dependency_collector.rb', line 42

def initialize_dup(other)
  super
  @deps = @deps.dup
  @requirements = @requirements.dup
end

#subversion_dep_if_needed(tags) ⇒ 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:



143
144
145
146
147
148
# File 'dependency_collector.rb', line 143

def subversion_dep_if_needed(tags)
  require "utils/svn"
  return if Utils::Svn.available?

  Dependency.new("subversion", [*tags, :implicit])
end

#unzip_dep_if_needed(tags) ⇒ 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:



166
167
168
# File 'dependency_collector.rb', line 166

def unzip_dep_if_needed(tags)
  Dependency.new("unzip", [*tags, :implicit]) unless which("unzip")
end

#xz_dep_if_needed(tags) ⇒ 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:



156
157
158
# File 'dependency_collector.rb', line 156

def xz_dep_if_needed(tags)
  Dependency.new("xz", [*tags, :implicit]) unless which("xz")
end

#zstd_dep_if_needed(tags) ⇒ 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:



161
162
163
# File 'dependency_collector.rb', line 161

def zstd_dep_if_needed(tags)
  Dependency.new("zstd", [*tags, :implicit]) unless which("zstd")
end