From 5088fdd54324b9ab053794909aab05fa2d81454b Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 23 Jan 2013 00:26:23 -0600 Subject: [PATCH] Move BuildOptions to a separate file --- Library/Homebrew/build_options.rb | 74 +++++++++++++++++++++++++++++ Library/Homebrew/formula.rb | 1 + Library/Homebrew/formula_support.rb | 74 ----------------------------- 3 files changed, 75 insertions(+), 74 deletions(-) create mode 100644 Library/Homebrew/build_options.rb diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb new file mode 100644 index 0000000000..d0b1f04693 --- /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 diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 37a9461734..e3d199718c 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -6,6 +6,7 @@ require 'bottles' require 'patches' require 'compilers' require 'build_environment' +require 'build_options' require 'extend/set' diff --git a/Library/Homebrew/formula_support.rb b/Library/Homebrew/formula_support.rb index 52fe42e034..6e231e7e36 100644 --- a/Library/Homebrew/formula_support.rb +++ b/Library/Homebrew/formula_support.rb @@ -1,7 +1,6 @@ require 'download_strategy' require 'checksums' require 'version' -require 'options' class SoftwareSpec attr_reader :checksum, :mirrors, :specs @@ -161,76 +160,3 @@ class KegOnlyReason end.strip end end - -# 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