| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  | require 'options' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # This class holds the build-time options defined for a Formula, | 
					
						
							|  |  |  | # and provides named access to those options during install. | 
					
						
							|  |  |  | class BuildOptions | 
					
						
							|  |  |  |   include Enumerable | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   attr_accessor :args | 
					
						
							|  |  |  |   attr_accessor :universal | 
					
						
							| 
									
										
										
										
											2013-10-07 00:40:32 -07:00
										 |  |  |   attr_accessor :cxx11 | 
					
						
							| 
									
										
										
										
											2013-09-14 17:03:56 -05:00
										 |  |  |   attr_reader :options | 
					
						
							|  |  |  |   protected :options | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   def initialize args | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |     @args = Options.coerce(args) | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |     @options = Options.new | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-14 17:03:56 -05:00
										 |  |  |   def initialize_copy(other) | 
					
						
							|  |  |  |     super | 
					
						
							|  |  |  |     @options = other.options.dup | 
					
						
							|  |  |  |     @args = other.args.dup | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   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" | 
					
						
							| 
									
										
										
										
											2013-10-07 00:40:32 -07:00
										 |  |  |       when "c++11" then "Build using C++11 mode" | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |       end.to_s | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @options << Option.new(name, description) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-31 16:10:35 -05:00
										 |  |  |   def add_dep_option(dep) | 
					
						
							| 
									
										
										
										
											2014-02-28 11:16:55 -06:00
										 |  |  |     name = dep.option_name | 
					
						
							| 
									
										
										
										
											2013-08-31 16:10:35 -05:00
										 |  |  |     if dep.optional? && !has_option?("with-#{name}") | 
					
						
							|  |  |  |       add("with-#{name}", "Build with #{name} support") | 
					
						
							|  |  |  |     elsif dep.recommended? && !has_option?("without-#{name}") | 
					
						
							|  |  |  |       add("without-#{name}", "Build without #{name} support") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |     args.include? '--' + name | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-09 14:36:10 -06:00
										 |  |  |   def with? val | 
					
						
							|  |  |  |     if val.respond_to?(:option_name) | 
					
						
							|  |  |  |       name = val.option_name | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       name = val | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:26 -06:00
										 |  |  |     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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-08 10:12:44 +01:00
										 |  |  |   def bottle? | 
					
						
							|  |  |  |     args.include? '--build-bottle' | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   def head? | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |     args.include? '--HEAD' | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def devel? | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |     args.include? '--devel' | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def stable? | 
					
						
							|  |  |  |     not (head? or devel?) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # True if the user requested a universal build. | 
					
						
							|  |  |  |   def universal? | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |     universal || args.include?('--universal') && has_option?('universal') | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-07 00:40:32 -07:00
										 |  |  |   # True if the user requested to enable C++11 mode. | 
					
						
							|  |  |  |   def cxx11? | 
					
						
							|  |  |  |     cxx11 || args.include?('--c++11') && has_option?('c++11') | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   # 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? | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |     args.include?('--32-bit') && has_option?('32-bit') | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def used_options | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |     Options.new(@options & @args) | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def unused_options | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |     Options.new(@options - @args) | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-21 10:33:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # Some options are implicitly ON because they are not explictly turned off | 
					
						
							|  |  |  |   # by their counterpart option. This applies only to with-/without- options. | 
					
						
							|  |  |  |   # implicit_options are needed because `depends_on 'spam' => 'with-stuff'` | 
					
						
							|  |  |  |   # complains if 'spam' has stuff as default and only defines `--without-stuff`. | 
					
						
							|  |  |  |   def implicit_options | 
					
						
							| 
									
										
										
										
											2013-06-13 15:52:23 +02:00
										 |  |  |     implicit = unused_options.map do |option| | 
					
						
							|  |  |  |       opposite_of option unless has_opposite_of? option | 
					
						
							| 
									
										
										
										
											2013-01-21 10:33:56 +01:00
										 |  |  |     end.compact | 
					
						
							|  |  |  |     Options.new(implicit) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-06-13 15:52:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def has_opposite_of? option | 
					
						
							| 
									
										
										
										
											2013-09-05 18:50:42 -05:00
										 |  |  |     @options.include? opposite_of(option) | 
					
						
							| 
									
										
										
										
											2013-06-13 15:52:23 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def opposite_of option | 
					
						
							| 
									
										
										
										
											2013-12-05 22:17:56 -06:00
										 |  |  |     option = Option.new(option) unless Option === option | 
					
						
							| 
									
										
										
										
											2013-12-05 22:16:23 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-13 15:52:23 +02:00
										 |  |  |     if option.name =~ /^with-(.+)$/ | 
					
						
							|  |  |  |       Option.new("without-#{$1}") | 
					
						
							|  |  |  |     elsif option.name =~ /^without-(.+)$/ | 
					
						
							|  |  |  |       Option.new("with-#{$1}") | 
					
						
							|  |  |  |     elsif option.name =~ /^enable-(.+)$/ | 
					
						
							|  |  |  |       Option.new("disable-#{$1}") | 
					
						
							|  |  |  |     elsif option.name =~ /^disable-(.+)$/ | 
					
						
							|  |  |  |       Option.new("enable-#{$1}") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  | end |