diff options
| author | Jack Nagel | 2013-01-23 00:26:23 -0600 |
|---|---|---|
| committer | Jack Nagel | 2013-01-26 11:37:02 -0600 |
| commit | 5088fdd54324b9ab053794909aab05fa2d81454b (patch) | |
| tree | b7d35d58bbf88c37bbb4f3b72dd5b7e2af64ea93 /Library/Homebrew/build_options.rb | |
| parent | 70ff06c827ce0da3d3dabe9e9c4927061e6c7f4c (diff) | |
| download | brew-5088fdd54324b9ab053794909aab05fa2d81454b.tar.bz2 | |
Move BuildOptions to a separate file
Diffstat (limited to 'Library/Homebrew/build_options.rb')
| -rw-r--r-- | Library/Homebrew/build_options.rb | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb new file mode 100644 index 000000000..d0b1f0469 --- /dev/null +++ b/Library/Homebrew/build_options.rb @@ -0,0 +1,74 @@ +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_writer :args + include Enumerable + + def initialize args + @args = Array.new(args).extend(HomebrewArgvExtension) + @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 head? + @args.flag? '--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((as_flags & @args.options_only).map { |o| Option.new(o) }) + end + + def unused_options + Options.new((as_flags - @args.options_only).map { |o| Option.new(o) }) + end +end |
