diff options
| author | Adam Vandenberg | 2012-07-30 11:32:56 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2012-08-08 22:01:27 -0700 |
| commit | d1d52b3467d0b20e99c240247ef01005c49cb62b (patch) | |
| tree | e050891e60e76d38dd671ddba97f9f9035771a07 /Library/Homebrew/formula_support.rb | |
| parent | 0df4c6a703d67db76fc31ee78aed3fc1eed12cfd (diff) | |
| download | brew-d1d52b3467d0b20e99c240247ef01005c49cb62b.tar.bz2 | |
Add `option` to the DSL
Closes Homebrew/homebrew#9982
Diffstat (limited to 'Library/Homebrew/formula_support.rb')
| -rw-r--r-- | Library/Homebrew/formula_support.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Library/Homebrew/formula_support.rb b/Library/Homebrew/formula_support.rb index 30cbee4e8..6118441e2 100644 --- a/Library/Homebrew/formula_support.rb +++ b/Library/Homebrew/formula_support.rb @@ -151,3 +151,80 @@ EOS end end end + + +# This class holds the build-time options defined for a Formula, +# and provides named access to those options during install. +class BuildOptions + + def initialize args + # Take a copy of the args (any string array, actually) + @args = Array.new(args) + # Extend it into an ARGV extension + @args.extend(HomebrewArgvExtension) + @options = [] + end + + def add name, description=nil + if description.nil? + case name + when :universal, "universal" + description = "Build a universal binary." + when "32-bit" + description = "Build 32-bit only." + else + description = "" + end + end + + @options << [name, description] + end + + def has_option? name + @options.any? {|o| o[0] == name} + end + + def empty? + @options.empty? + end + + def collect + @options.collect {|o| yield o[0], o[1]} + end + + def each + @options.each {|o| yield o[0], o[1]} + end + + def include? name + @args.include? '--' + name + end + + def using? 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' + 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' + end +end |
