brew/Library/Homebrew/build_options.rb
Jack Nagel cf08b71bf8 FormulaInstaller: construct new ARGV from an Options collection
The array of options that is passed to the spawned build process is a
combination of the current ARGV, options passed in by a dependent
formula, and an existing install receipt. The objects that are
interacting here each expect the resulting collection to have certain
properties, and the expectations are not consistent.

Clear up this confusing mess by only dealing with Options collections.
This keeps our representation of options uniform across the codebase.

We can remove BuildOptions dependency on HomebrewArgvExtension, which
allows us to pass any Array-like collection to Tab.create. The only
other site inside of FormulaInstaller that uses the array is the #exec
call, and there it is splatted and thus we can substitute our Options
collection there as well.
2013-01-26 12:14:47 -06:00

89 lines
1.6 KiB
Ruby

require 'options'
# This class holds the build-time options defined for a Formula,
# and provides named access to those options during install.
class BuildOptions
attr_accessor :args
include Enumerable
def initialize args
@args = Options.coerce(args)
@options = Options.new
end
def add name, description=nil
description ||= case name.to_s
when "universal" then "Build a universal binary"
when "32-bit" then "Build 32-bit only"
end.to_s
@options << Option.new(name, description)
end
def has_option? name
any? { |opt| opt.name == name }
end
def empty?
@options.empty?
end
def each(*args, &block)
@options.each(*args, &block)
end
def as_flags
@options.as_flags
end
def include? name
args.include? '--' + name
end
def with? name
if has_option? "with-#{name}"
include? "with-#{name}"
elsif has_option? "without-#{name}"
not include? "without-#{name}"
else
false
end
end
def without? name
not with? name
end
def head?
args.include? '--HEAD'
end
def devel?
args.include? '--devel'
end
def stable?
not (head? or devel?)
end
# True if the user requested a universal build.
def universal?
args.include?('--universal') && has_option?('universal')
end
# Request a 32-bit only build.
# This is needed for some use-cases though we prefer to build Universal
# when a 32-bit version is needed.
def build_32_bit?
args.include?('--32-bit') && has_option?('32-bit')
end
def used_options
Options.new(@options & @args)
end
def unused_options
Options.new(@options - @args)
end
end