Class: SoftwareSpec

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
Library/Homebrew/software_spec.rb,
Library/Homebrew/extend/os/mac/software_spec.rb

Direct Known Subclasses

HeadSoftwareSpec

Constant Summary collapse

PREDEFINED_OPTIONS =
{
  universal: Option.new("universal", "Build a universal binary"),
  cxx11:     Option.new("c++11",     "Build using C++11 mode"),
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSoftwareSpec

Returns a new instance of SoftwareSpec.


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'Library/Homebrew/software_spec.rb', line 37

def initialize
  @resource = Resource.new
  @resources = {}
  @dependency_collector = DependencyCollector.new
  @bottle_specification = BottleSpecification.new
  @patches = []
  @options = Options.new
  @flags = Homebrew.args.flags_only
  @deprecated_flags = []
  @deprecated_options = []
  @build = BuildOptions.new(Options.create(@flags), options)
  @compiler_failures = []
  @bottle_disable_reason = nil
end

Instance Attribute Details

#bottle_disable_reasonObject (readonly)

Returns the value of attribute bottle_disable_reason


90
91
92
# File 'Library/Homebrew/software_spec.rb', line 90

def bottle_disable_reason
  @bottle_disable_reason
end

#bottle_specificationObject (readonly)

Returns the value of attribute bottle_specification


27
28
29
# File 'Library/Homebrew/software_spec.rb', line 27

def bottle_specification
  @bottle_specification
end

#buildObject (readonly)

Returns the value of attribute build


24
25
26
# File 'Library/Homebrew/software_spec.rb', line 24

def build
  @build
end

#compiler_failuresObject (readonly)

Returns the value of attribute compiler_failures


28
29
30
# File 'Library/Homebrew/software_spec.rb', line 28

def compiler_failures
  @compiler_failures
end

#dependency_collectorObject (readonly)

Returns the value of attribute dependency_collector


26
27
28
# File 'Library/Homebrew/software_spec.rb', line 26

def dependency_collector
  @dependency_collector
end

#deprecated_flagsObject (readonly)

Returns the value of attribute deprecated_flags


25
26
27
# File 'Library/Homebrew/software_spec.rb', line 25

def deprecated_flags
  @deprecated_flags
end

#deprecated_optionsObject (readonly)

Returns the value of attribute deprecated_options


25
26
27
# File 'Library/Homebrew/software_spec.rb', line 25

def deprecated_options
  @deprecated_options
end

#full_nameObject (readonly)

Returns the value of attribute full_name


23
24
25
# File 'Library/Homebrew/software_spec.rb', line 23

def full_name
  @full_name
end

#nameObject (readonly)

Returns the value of attribute name


23
24
25
# File 'Library/Homebrew/software_spec.rb', line 23

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


24
25
26
# File 'Library/Homebrew/software_spec.rb', line 24

def options
  @options
end

#ownerObject

Returns the value of attribute owner


23
24
25
# File 'Library/Homebrew/software_spec.rb', line 23

def owner
  @owner
end

#patchesObject (readonly)

Returns the value of attribute patches


24
25
26
# File 'Library/Homebrew/software_spec.rb', line 24

def patches
  @patches
end

#resourcesObject (readonly)

Returns the value of attribute resources


24
25
26
# File 'Library/Homebrew/software_spec.rb', line 24

def resources
  @resources
end

#uses_from_macos_elementsObject (readonly)

Returns the value of attribute uses_from_macos_elements


29
30
31
# File 'Library/Homebrew/software_spec.rb', line 29

def uses_from_macos_elements
  @uses_from_macos_elements
end

Instance Method Details

#add_dep_option(dep) ⇒ Object


231
232
233
234
235
236
237
238
239
# File 'Library/Homebrew/software_spec.rb', line 231

def add_dep_option(dep)
  dep.option_names.each do |name|
    if dep.optional? && !option_defined?("with-#{name}")
      options << Option.new("with-#{name}", "Build with #{name} support")
    elsif dep.recommended? && !option_defined?("without-#{name}")
      options << Option.new("without-#{name}", "Build without #{name} support")
    end
  end
end

#add_legacy_patches(list) ⇒ Object

TODO


225
226
227
228
229
# File 'Library/Homebrew/software_spec.rb', line 225

def add_legacy_patches(list)
  list = Patch.normalize_legacy_patches(list)
  list.each { |p| p.owner = self }
  patches.concat(list)
end

#bottle(disable_type = nil, disable_reason = nil, &block) ⇒ Object


101
102
103
104
105
106
107
# File 'Library/Homebrew/software_spec.rb', line 101

def bottle(disable_type = nil, disable_reason = nil, &block)
  if disable_type
    @bottle_disable_reason = BottleDisableReason.new(disable_type, disable_reason)
  else
    bottle_specification.instance_eval(&block)
  end
end

#bottle_defined?Boolean

Returns:

  • (Boolean)

92
93
94
# File 'Library/Homebrew/software_spec.rb', line 92

def bottle_defined?
  !bottle_specification.collector.keys.empty?
end

#bottle_disabled?Boolean

Returns:

  • (Boolean)

86
87
88
# File 'Library/Homebrew/software_spec.rb', line 86

def bottle_disabled?
  @bottle_disable_reason ? true : false
end

#bottle_unneeded?Boolean

Returns:

  • (Boolean)

80
81
82
83
84
# File 'Library/Homebrew/software_spec.rb', line 80

def bottle_unneeded?
  return false unless @bottle_disable_reason

  @bottle_disable_reason.unneeded?
end

#bottled?Boolean

Returns:

  • (Boolean)

96
97
98
99
# File 'Library/Homebrew/software_spec.rb', line 96

def bottled?
  bottle_specification.tag?(Utils::Bottles.tag) && \
    (bottle_specification.compatible_cellar? || Homebrew.args.force_bottle?)
end

#depends_on(spec) ⇒ Object


169
170
171
172
# File 'Library/Homebrew/software_spec.rb', line 169

def depends_on(spec)
  dep = dependency_collector.add(spec)
  add_dep_option(dep) if dep
end

#deprecated_option(hash) ⇒ Object

Raises:

  • (ArgumentError)

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'Library/Homebrew/software_spec.rb', line 147

def deprecated_option(hash)
  raise ArgumentError, "deprecated_option hash must not be empty" if hash.empty?

  hash.each do |old_options, new_options|
    Array(old_options).each do |old_option|
      Array(new_options).each do |new_option|
        deprecated_option = DeprecatedOption.new(old_option, new_option)
        deprecated_options << deprecated_option

        old_flag = deprecated_option.old_flag
        new_flag = deprecated_option.current_flag
        next unless @flags.include? old_flag

        @flags -= [old_flag]
        @flags |= [new_flag]
        @deprecated_flags << deprecated_option
      end
    end
  end
  @build = BuildOptions.new(Options.create(@flags), options)
end

#depsObject


179
180
181
# File 'Library/Homebrew/software_spec.rb', line 179

def deps
  dependency_collector.deps
end

#fails_with(compiler, &block) ⇒ Object


214
215
216
# File 'Library/Homebrew/software_spec.rb', line 214

def fails_with(compiler, &block)
  compiler_failures << CompilerFailure.create(compiler, &block)
end

#go_resource(name, &block) ⇒ Object


125
126
127
# File 'Library/Homebrew/software_spec.rb', line 125

def go_resource(name, &block)
  resource name, Resource::Go, &block
end

#needs(*standards) ⇒ Object


218
219
220
221
222
# File 'Library/Homebrew/software_spec.rb', line 218

def needs(*standards)
  standards.each do |standard|
    compiler_failures.concat CompilerFailure.for_standard(standard)
  end
end

#option(name, description = "") ⇒ Object


133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'Library/Homebrew/software_spec.rb', line 133

def option(name, description = "")
  opt = PREDEFINED_OPTIONS.fetch(name) do
    unless name.is_a?(String)
      raise ArgumentError, "option name must be string or symbol; got a #{name.class}: #{name}"
    end
    raise ArgumentError, "option name is required" if name.empty?
    raise ArgumentError, "option name must be longer than one character: #{name}" unless name.length > 1
    raise ArgumentError, "option name must not start with dashes: #{name}" if name.start_with?("-")

    Option.new(name, description)
  end
  options << opt
end

#option_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)

129
130
131
# File 'Library/Homebrew/software_spec.rb', line 129

def option_defined?(name)
  options.include?(name)
end

#patch(strip = :p1, src = nil, &block) ⇒ Object


208
209
210
211
212
# File 'Library/Homebrew/software_spec.rb', line 208

def patch(strip = :p1, src = nil, &block)
  p = Patch.create(strip, src, &block)
  dependency_collector.add(p.resource) if p.is_a? ExternalPatch
  patches << p
end

#recursive_dependenciesObject


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'Library/Homebrew/software_spec.rb', line 183

def recursive_dependencies
  deps_f = []
  recursive_dependencies = deps.map do |dep|
    deps_f << dep.to_formula
    dep
  rescue TapFormulaUnavailableError
    # Don't complain about missing cross-tap dependencies
    next
  end.compact.uniq
  deps_f.compact.each do |f|
    f.recursive_dependencies.each do |dep|
      recursive_dependencies << dep unless recursive_dependencies.include?(dep)
    end
  end
  recursive_dependencies
end

#recursive_requirementsObject


204
205
206
# File 'Library/Homebrew/software_spec.rb', line 204

def recursive_requirements
  Requirement.expand(self)
end

#requirementsObject


200
201
202
# File 'Library/Homebrew/software_spec.rb', line 200

def requirements
  dependency_collector.requirements
end

#resource(name, klass = Resource, &block) ⇒ Object


113
114
115
116
117
118
119
120
121
122
123
# File 'Library/Homebrew/software_spec.rb', line 113

def resource(name, klass = Resource, &block)
  if block_given?
    raise DuplicateResourceError, name if resource_defined?(name)

    res = klass.new(name, &block)
    resources[name] = res
    dependency_collector.add(res)
  else
    resources.fetch(name) { raise ResourceMissingError.new(owner, name) }
  end
end

#resource_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)

109
110
111
# File 'Library/Homebrew/software_spec.rb', line 109

def resource_defined?(name)
  resources.key?(name)
end

#url(val = nil, specs = {}) ⇒ Object


73
74
75
76
77
78
# File 'Library/Homebrew/software_spec.rb', line 73

def url(val = nil, specs = {})
  return @resource.url if val.nil?

  @resource.url(val, specs)
  dependency_collector.add(@resource)
end

#uses_from_macos(deps, bounds = {}) ⇒ Object


174
175
176
177
# File 'Library/Homebrew/software_spec.rb', line 174

def uses_from_macos(spec, _bounds = {})
  spec = Hash[*spec.first] if spec.is_a?(Hash)
  depends_on(spec)
end