Class: SoftwareSpec

Inherits:
Object show all
Extended by:
Forwardable
Includes:
OnSystem::MacOSAndLinux
Defined in:
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

Methods included from OnSystem::MacOSAndLinux

included

Constructor Details

#initialize(flags: []) ⇒ SoftwareSpec

Returns a new instance of SoftwareSpec.



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

def initialize(flags: [])
  # Ensure this is synced with `initialize_dup` and `freeze` (excluding simple objects like integers and booleans)
  @resource = Resource.new
  @resources = {}
  @dependency_collector = DependencyCollector.new
  @bottle_specification = BottleSpecification.new
  @patches = []
  @options = Options.new
  @flags = flags
  @deprecated_flags = []
  @deprecated_options = []
  @build = BuildOptions.new(Options.create(@flags), options)
  @compiler_failures = []
end

Instance Attribute Details

#bottle_specificationObject (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 the value of attribute bottle_specification.



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

def bottle_specification
  @bottle_specification
end

#buildObject (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 the value of attribute build.



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

def build
  @build
end

#compiler_failuresObject (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 the value of attribute compiler_failures.



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

def compiler_failures
  @compiler_failures
end

#dependency_collectorObject (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 the value of attribute dependency_collector.



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

def dependency_collector
  @dependency_collector
end

#deprecated_flagsObject (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 the value of attribute deprecated_flags.



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

def deprecated_flags
  @deprecated_flags
end

#deprecated_optionsObject (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 the value of attribute deprecated_options.



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

def deprecated_options
  @deprecated_options
end

#full_nameObject (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 the value of attribute full_name.



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

def full_name
  @full_name
end

#nameObject (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 the value of attribute name.



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

def name
  @name
end

#optionsObject (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 the value of attribute options.



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

def options
  @options
end

#ownerObject

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 the value of attribute owner.



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

def owner
  @owner
end

#patchesObject (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 the value of attribute patches.



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

def patches
  @patches
end

#resourcesObject (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 the value of attribute resources.



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

def resources
  @resources
end

Instance Method Details

#add_dep_option(dep) ⇒ Object



266
267
268
269
270
271
272
273
274
# File 'software_spec.rb', line 266

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

#bottle(&block) ⇒ Object



118
119
120
# File 'software_spec.rb', line 118

def bottle(&block)
  bottle_specification.instance_eval(&block)
end

#bottle_defined?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'software_spec.rb', line 105

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

#bottle_tag?(tag = nil) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
# File 'software_spec.rb', line 109

def bottle_tag?(tag = nil)
  bottle_specification.tag?(Utils::Bottles.tag(tag))
end

#bottled?(tag = nil) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
116
# File 'software_spec.rb', line 113

def bottled?(tag = nil)
  bottle_tag?(tag) &&
    (tag.present? || bottle_specification.compatible_locations? || owner.force_bottle)
end

#declared_depsObject



219
220
221
# File 'software_spec.rb', line 219

def declared_deps
  dependency_collector.deps
end

#depends_on(spec) ⇒ Object



190
191
192
193
# File 'software_spec.rb', line 190

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

#deprecated_option(hash) ⇒ Object

Raises:

  • (ArgumentError)


168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'software_spec.rb', line 168

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



215
216
217
# File 'software_spec.rb', line 215

def deps
  dependency_collector.deps.dup_without_system_deps
end

#fails_with(compiler, &block) ⇒ Object



256
257
258
# File 'software_spec.rb', line 256

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

#freezeObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'software_spec.rb', line 66

def freeze
  @resource.freeze
  @resources.freeze
  @dependency_collector.freeze
  @bottle_specification.freeze
  @patches.freeze
  @options.freeze
  @flags.freeze
  @deprecated_flags.freeze
  @deprecated_options.freeze
  @build.freeze
  @compiler_failures.freeze
  super
end

#go_resource(name, &block) ⇒ Object



145
146
147
148
# File 'software_spec.rb', line 145

def go_resource(name, &block)
  odeprecated "`SoftwareSpec#go_resource`", "Go modules"
  resource name, Resource::Go, &block
end

#initialize_dup(other) ⇒ Object



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

def initialize_dup(other)
  super
  @resource = @resource.dup
  @resources = @resources.dup
  @dependency_collector = @dependency_collector.dup
  @bottle_specification = @bottle_specification.dup
  @patches = @patches.dup
  @options = @options.dup
  @flags = @flags.dup
  @deprecated_flags = @deprecated_flags.dup
  @deprecated_options = @deprecated_options.dup
  @build = @build.dup
  @compiler_failures = @compiler_failures.dup
end

#needs(*standards) ⇒ Object



260
261
262
263
264
# File 'software_spec.rb', line 260

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

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



154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'software_spec.rb', line 154

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}" if 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)


150
151
152
# File 'software_spec.rb', line 150

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

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



248
249
250
251
252
253
254
# File 'software_spec.rb', line 248

def patch(strip = :p1, src = nil, &block)
  p = Patch.create(strip, src, &block)
  return if p.is_a?(ExternalPatch) && p.url.blank?

  dependency_collector.add(p.resource) if p.is_a? ExternalPatch
  patches << p
end

#recursive_dependenciesObject



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'software_spec.rb', line 223

def recursive_dependencies
  deps_f = []
  recursive_dependencies = deps.filter_map do |dep|
    deps_f << dep.to_formula
    dep
  rescue TapFormulaUnavailableError
    # Don't complain about missing cross-tap dependencies
    next
  end.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



244
245
246
# File 'software_spec.rb', line 244

def recursive_requirements
  Requirement.expand(self)
end

#requirementsObject



240
241
242
# File 'software_spec.rb', line 240

def requirements
  dependency_collector.requirements
end

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

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
136
137
138
139
140
141
142
143
# File 'software_spec.rb', line 130

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

    res = klass.new(name, &block)
    return unless res.url

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

#resource_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
# File 'software_spec.rb', line 122

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

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



98
99
100
101
102
103
# File 'software_spec.rb', line 98

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

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

#uses_from_macos(dep, bounds = {}) ⇒ 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:



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'software_spec.rb', line 201

def uses_from_macos(dep, bounds = {})
  if dep.is_a?(Hash)
    bounds = dep.dup
    dep, tags = bounds.shift
    dep = T.cast(dep, String)
    tags = [*tags]
    bounds = T.cast(bounds, T::Hash[Symbol, Symbol])
  else
    tags = []
  end

  depends_on UsesFromMacOSDependency.new(dep, tags, bounds:)
end