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
# 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 = []
  @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



230
231
232
233
234
235
236
237
238
# File 'software_spec.rb', line 230

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



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

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 'software_spec.rb', line 92

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

#bottle_disabled?Boolean

Returns:

  • (Boolean)


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

def bottle_disabled?
  @bottle_disable_reason ? true : false
end

#bottle_tag?Boolean

Returns:

  • (Boolean)


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

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

#bottle_unneeded?Boolean

Returns:

  • (Boolean)


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

def bottle_unneeded?
  return false unless @bottle_disable_reason

  @bottle_disable_reason.unneeded?
end

#bottled?Boolean

Returns:

  • (Boolean)


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

def bottled?
  bottle_tag? && \
    (bottle_specification.compatible_locations? || owner.force_bottle)
end

#depends_on(spec) ⇒ Object



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

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

#deprecated_option(hash) ⇒ Object

Raises:

  • (ArgumentError)


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

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



185
186
187
# File 'software_spec.rb', line 185

def deps
  dependency_collector.deps
end

#fails_with(compiler, &block) ⇒ Object



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

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

#go_resource(name, &block) ⇒ Object



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

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

#needs(*standards) ⇒ Object



224
225
226
227
228
# File 'software_spec.rb', line 224

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

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



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

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)


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

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

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



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

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



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'software_spec.rb', line 189

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



210
211
212
# File 'software_spec.rb', line 210

def recursive_requirements
  Requirement.expand(self)
end

#requirementsObject



206
207
208
# File 'software_spec.rb', line 206

def requirements
  dependency_collector.requirements
end

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



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

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)


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

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

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



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

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
# File 'extend/os/mac/software_spec.rb', line 9

def uses_from_macos(deps, bounds = {})
  @uses_from_macos_elements ||= []

  if deps.is_a?(Hash)
    bounds = deps.dup
    deps = bounds.shift
  end

  bounds = bounds.transform_values { |v| MacOS::Version.from_symbol(v) }
  if MacOS.version >= bounds[:since] ||
     (Homebrew::EnvConfig.simulate_macos_on_linux? && !bounds.key?(:since))
    @uses_from_macos_elements << deps
  else
    depends_on deps
  end
end