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

Returns a new instance of SoftwareSpec



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

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



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

def bottle_disable_reason
  @bottle_disable_reason
end

#bottle_specificationObject (readonly)

Returns the value of attribute bottle_specification



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

def bottle_specification
  @bottle_specification
end

#buildObject (readonly)

Returns the value of attribute build



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

def build
  @build
end

#compiler_failuresObject (readonly)

Returns the value of attribute compiler_failures



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

def compiler_failures
  @compiler_failures
end

#dependency_collectorObject (readonly)

Returns the value of attribute dependency_collector



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

def dependency_collector
  @dependency_collector
end

#deprecated_flagsObject (readonly)

Returns the value of attribute deprecated_flags



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

def deprecated_flags
  @deprecated_flags
end

#deprecated_optionsObject (readonly)

Returns the value of attribute deprecated_options



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

def deprecated_options
  @deprecated_options
end

#full_nameObject (readonly)

Returns the value of attribute full_name



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

def full_name
  @full_name
end

#nameObject (readonly)

Returns the value of attribute name



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

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options



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

def options
  @options
end

#ownerObject

Returns the value of attribute owner



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

def owner
  @owner
end

#patchesObject (readonly)

Returns the value of attribute patches



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

def patches
  @patches
end

#resourcesObject (readonly)

Returns the value of attribute resources



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

def resources
  @resources
end

Instance Method Details

#add_dep_option(dep) ⇒ Object



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

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



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

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



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

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)


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

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

#bottle_disabled?Boolean

Returns:

  • (Boolean)


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

def bottle_disabled?
  @bottle_disable_reason ? true : false
end

#bottle_unneeded?Boolean

Returns:

  • (Boolean)


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

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

#bottled?Boolean

Returns:

  • (Boolean)


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

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
# File 'Library/Homebrew/software_spec.rb', line 174

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

#go_resource(name, &block) ⇒ Object



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

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

#needs(*standards) ⇒ Object



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

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

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



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

def option(name, description = "")
  opt = PREDEFINED_OPTIONS.fetch(name) do
    if name.is_a?(Symbol)
      odeprecated "passing arbitrary symbols (i.e. #{name.inspect}) to `option`"
      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

Returns:

  • (Boolean)


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

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



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

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)


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

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

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



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

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