Class: SoftwareSpec

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, T::Sig
Includes:
OnOS
Defined in:
extend/os/mac/software_spec.rb,
software_spec.rb

Overview

The Library/Homebrew/extend/os/software_spec.rb conditional logic will need to be more nuanced if this file ever includes more than uses_from_macos.

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 OnOS

#on_linux, #on_macos

Constructor Details

#initialize(flags: []) ⇒ SoftwareSpec

Returns a new instance of SoftwareSpec.



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

def initialize(flags: [])
  @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 = []
  @uses_from_macos_elements = []
  @bottle_disable_reason = nil
end

Instance Attribute Details

#bottle_disable_reasonObject (readonly)

Returns the value of attribute bottle_disable_reason.



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

def bottle_disable_reason
  @bottle_disable_reason
end

#bottle_specificationObject (readonly)

Returns the value of attribute bottle_specification.



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

def bottle_specification
  @bottle_specification
end

#buildObject (readonly)

Returns the value of attribute build.



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

def build
  @build
end

#compiler_failuresObject (readonly)

Returns the value of attribute compiler_failures.



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

def compiler_failures
  @compiler_failures
end

#dependency_collectorObject (readonly)

Returns the value of attribute dependency_collector.



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

def dependency_collector
  @dependency_collector
end

#deprecated_flagsObject (readonly)

Returns the value of attribute deprecated_flags.



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

def deprecated_flags
  @deprecated_flags
end

#deprecated_optionsObject (readonly)

Returns the value of attribute deprecated_options.



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

def deprecated_options
  @deprecated_options
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



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

def full_name
  @full_name
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#ownerObject

Returns the value of attribute owner.



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

def owner
  @owner
end

#patchesObject (readonly)

Returns the value of attribute patches.



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

def patches
  @patches
end

#resourcesObject (readonly)

Returns the value of attribute resources.



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

def resources
  @resources
end

#uses_from_macos_elementsObject (readonly)

Returns the value of attribute uses_from_macos_elements.



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

def uses_from_macos_elements
  @uses_from_macos_elements
end

Instance Method Details

#add_dep_option(dep) ⇒ Object



238
239
240
241
242
243
244
245
246
# File 'software_spec.rb', line 238

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(disable_type = nil, disable_reason = nil, &block) ⇒ Object



106
107
108
109
110
111
112
# File 'software_spec.rb', line 106

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)


93
94
95
# File 'software_spec.rb', line 93

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

#bottle_disabled?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'software_spec.rb', line 89

def bottle_disabled?
  @bottle_disable_reason ? true : false
end

#bottle_tag?(tag = nil) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'software_spec.rb', line 97

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

#bottle_unneeded?Boolean

Returns:

  • (Boolean)


82
83
84
85
86
# File 'software_spec.rb', line 82

def bottle_unneeded?
  return false unless @bottle_disable_reason

  @bottle_disable_reason.unneeded?
end

#bottled?(tag = nil) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
104
# File 'software_spec.rb', line 101

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

#depends_on(spec) ⇒ Object



176
177
178
179
# File 'software_spec.rb', line 176

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

#deprecated_option(hash) ⇒ Object

Raises:

  • (ArgumentError)


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'software_spec.rb', line 154

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



193
194
195
# File 'software_spec.rb', line 193

def deps
  dependency_collector.deps
end

#fails_with(compiler, &block) ⇒ Object



228
229
230
# File 'software_spec.rb', line 228

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

#go_resource(name, &block) ⇒ Object



132
133
134
# File 'software_spec.rb', line 132

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

#needs(*standards) ⇒ Object



232
233
234
235
236
# File 'software_spec.rb', line 232

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

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



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'software_spec.rb', line 140

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)


136
137
138
# File 'software_spec.rb', line 136

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

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



222
223
224
225
226
# File 'software_spec.rb', line 222

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



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

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



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

def recursive_requirements
  Requirement.expand(self)
end

#requirementsObject



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

def requirements
  dependency_collector.requirements
end

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



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'software_spec.rb', line 118

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)
  else
    resources.fetch(name) { raise ResourceMissingError.new(owner, name) }
  end
end

#resource_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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



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

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

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

#uses_from_macos(spec, _bounds = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'extend/os/mac/software_spec.rb', line 9

def uses_from_macos(deps, bounds = {})
  if deps.is_a?(Hash)
    bounds = deps.dup
    deps = [bounds.shift].to_h
  end

  @uses_from_macos_elements << deps

  bounds = bounds.transform_values { |v| MacOS::Version.from_symbol(v) }

  # Linux simulating macOS. Assume oldest macOS version.
  return if Homebrew::EnvConfig.simulate_macos_on_linux? && !bounds.key?(:since)

  # macOS new enough for dependency to not be required.
  return if MacOS.version >= bounds[:since]

  depends_on deps
end

#uses_from_macos_namesObject



189
190
191
# File 'software_spec.rb', line 189

def uses_from_macos_names
  uses_from_macos_elements.flat_map { |e| e.is_a?(Hash) ? e.keys : e }
end