Class: SoftwareSpec

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
Library/Homebrew/software_spec.rb

Direct Known Subclasses

HeadSoftwareSpec

Constant Summary

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



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'Library/Homebrew/software_spec.rb', line 33

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

Instance Attribute Details

#bottle_disable_reasonObject (readonly)

Returns the value of attribute bottle_disable_reason



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

def bottle_disable_reason
  @bottle_disable_reason
end

#bottle_specificationObject (readonly)

Returns the value of attribute bottle_specification



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

def bottle_specification
  @bottle_specification
end

#buildObject (readonly)

Returns the value of attribute build



21
22
23
# File 'Library/Homebrew/software_spec.rb', line 21

def build
  @build
end

#compiler_failuresObject (readonly)

Returns the value of attribute compiler_failures



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

def compiler_failures
  @compiler_failures
end

#dependency_collectorObject (readonly)

Returns the value of attribute dependency_collector



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

def dependency_collector
  @dependency_collector
end

#deprecated_flagsObject (readonly)

Returns the value of attribute deprecated_flags



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

def deprecated_flags
  @deprecated_flags
end

#deprecated_optionsObject (readonly)

Returns the value of attribute deprecated_options



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

def deprecated_options
  @deprecated_options
end

#full_nameObject (readonly)

Returns the value of attribute full_name



20
21
22
# File 'Library/Homebrew/software_spec.rb', line 20

def full_name
  @full_name
end

#nameObject (readonly)

Returns the value of attribute name



20
21
22
# File 'Library/Homebrew/software_spec.rb', line 20

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options



21
22
23
# File 'Library/Homebrew/software_spec.rb', line 21

def options
  @options
end

#ownerObject

Returns the value of attribute owner



20
21
22
# File 'Library/Homebrew/software_spec.rb', line 20

def owner
  @owner
end

#patchesObject (readonly)

Returns the value of attribute patches



21
22
23
# File 'Library/Homebrew/software_spec.rb', line 21

def patches
  @patches
end

#resourcesObject (readonly)

Returns the value of attribute resources



21
22
23
# File 'Library/Homebrew/software_spec.rb', line 21

def resources
  @resources
end

Instance Method Details

#add_dep_option(dep) ⇒ Object



192
193
194
195
196
197
198
199
200
# File 'Library/Homebrew/software_spec.rb', line 192

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



186
187
188
189
190
# File 'Library/Homebrew/software_spec.rb', line 186

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



86
87
88
89
90
91
92
# File 'Library/Homebrew/software_spec.rb', line 86

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



77
78
79
# File 'Library/Homebrew/software_spec.rb', line 77

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

#bottle_disabled?Boolean



71
72
73
# File 'Library/Homebrew/software_spec.rb', line 71

def bottle_disabled?
  @bottle_disable_reason ? true : false
end

#bottle_unneeded?Boolean



66
67
68
69
# File 'Library/Homebrew/software_spec.rb', line 66

def bottle_unneeded?
  return false unless @bottle_disable_reason
  @bottle_disable_reason.unneeded?
end

#bottled?Boolean



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

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

#depends_on(spec) ⇒ Object



155
156
157
158
# File 'Library/Homebrew/software_spec.rb', line 155

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

#deprecated_option(hash) ⇒ Object

Raises:

  • (ArgumentError)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'Library/Homebrew/software_spec.rb', line 135

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



160
161
162
# File 'Library/Homebrew/software_spec.rb', line 160

def deps
  dependency_collector.deps
end

#fails_with(compiler, &block) ⇒ Object



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

def fails_with(compiler, &block)
  # TODO: deprecate this in future.
  # odeprecated "fails_with :llvm" if compiler == :llvm
  compiler_failures << CompilerFailure.create(compiler, &block)
end

#go_resource(name, &block) ⇒ Object



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

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

#needs(*standards) ⇒ Object



180
181
182
183
184
# File 'Library/Homebrew/software_spec.rb', line 180

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

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'Library/Homebrew/software_spec.rb', line 117

def option(name, description = "")
  opt = PREDEFINED_OPTIONS.fetch(name) do
    if name.is_a?(Symbol)
      opoo "Passing arbitrary symbols to `option` is deprecated: #{name.inspect}"
      puts "Symbols are reserved for future use, please pass a string instead"
      name = name.to_s
    end
    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



113
114
115
# File 'Library/Homebrew/software_spec.rb', line 113

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

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



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

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

#requirementsObject



164
165
166
# File 'Library/Homebrew/software_spec.rb', line 164

def requirements
  dependency_collector.requirements
end

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



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

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



94
95
96
# File 'Library/Homebrew/software_spec.rb', line 94

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

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



60
61
62
63
64
# File 'Library/Homebrew/software_spec.rb', line 60

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