From d1d52b3467d0b20e99c240247ef01005c49cb62b Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Mon, 30 Jul 2012 11:32:56 -0700 Subject: Add `option` to the DSL Closes Homebrew/homebrew#9982 --- Library/Homebrew/formula_support.rb | 77 +++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'Library/Homebrew/formula_support.rb') 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 -- cgit v1.2.3