| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 19:53:37 +02:00
										 |  |  | # A formula option. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # @api private | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  | class Option | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   attr_reader :name, :description, :flag | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def initialize(name, description = "") | 
					
						
							| 
									
										
										
										
											2014-08-29 19:38:32 -05:00
										 |  |  |     @name = name | 
					
						
							|  |  |  |     @flag = "--#{name}" | 
					
						
							| 
									
										
										
										
											2014-08-07 00:48:13 -05:00
										 |  |  |     @description = description | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def to_s | 
					
						
							|  |  |  |     flag | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def <=>(other) | 
					
						
							| 
									
										
										
										
											2016-09-20 22:03:08 +02:00
										 |  |  |     return unless other.is_a?(Option) | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |     name <=> other.name | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 19:29:18 -05:00
										 |  |  |   def ==(other) | 
					
						
							| 
									
										
										
										
											2013-06-27 01:18:32 -05:00
										 |  |  |     instance_of?(other.class) && name == other.name | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |   alias eql? == | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def hash | 
					
						
							|  |  |  |     name.hash | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2013-05-24 10:56:02 -05:00
										 |  |  |   def inspect | 
					
						
							| 
									
										
										
										
											2014-07-01 15:07:06 -05:00
										 |  |  |     "#<#{self.class.name}: #{flag.inspect}>" | 
					
						
							| 
									
										
										
										
											2013-05-24 10:56:02 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 19:53:37 +02:00
										 |  |  | # A deprecated formula option. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # @api private | 
					
						
							| 
									
										
										
										
											2014-10-16 12:58:34 +01:00
										 |  |  | class DeprecatedOption | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-16 12:58:34 +01:00
										 |  |  |   attr_reader :old, :current | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def initialize(old, current) | 
					
						
							|  |  |  |     @old = old | 
					
						
							|  |  |  |     @current = current | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2014-10-16 12:58:34 +01:00
										 |  |  |   def old_flag | 
					
						
							|  |  |  |     "--#{old}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2014-10-16 12:58:34 +01:00
										 |  |  |   def current_flag | 
					
						
							|  |  |  |     "--#{current}" | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-10-16 13:00:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def ==(other) | 
					
						
							|  |  |  |     instance_of?(other.class) && old == other.old && current == other.current | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |   alias eql? == | 
					
						
							| 
									
										
										
										
											2014-10-16 12:58:34 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 19:53:37 +02:00
										 |  |  | # A collection of formula options. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # @api private | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  | class Options | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   include Enumerable | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-13 11:09:57 -05:00
										 |  |  |   def self.create(array) | 
					
						
							| 
									
										
										
										
											2020-10-02 13:48:26 +01:00
										 |  |  |     new Array(array).map { |e| Option.new(e[/^--([^=]+=?)(.+)?$/, 1] || e) } | 
					
						
							| 
									
										
										
										
											2014-08-13 11:09:57 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   def initialize(*args) | 
					
						
							|  |  |  |     @options = Set.new(*args) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def each(*args, &block) | 
					
						
							|  |  |  |     @options.each(*args, &block) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |   def <<(other) | 
					
						
							|  |  |  |     @options << other | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |     self | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |   def +(other) | 
					
						
							|  |  |  |     self.class.new(@options + other) | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |   def -(other) | 
					
						
							|  |  |  |     self.class.new(@options - other) | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |   def &(other) | 
					
						
							|  |  |  |     self.class.new(@options & other) | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |   def |(other) | 
					
						
							|  |  |  |     self.class.new(@options | other) | 
					
						
							| 
									
										
										
										
											2014-02-27 14:22:42 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |   def *(other) | 
					
						
							|  |  |  |     @options.to_a * other | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 03:21:27 +00:00
										 |  |  |   def ==(other) | 
					
						
							|  |  |  |     instance_of?(other.class) && | 
					
						
							|  |  |  |       to_a == other.to_a | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   alias eql? == | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   def empty? | 
					
						
							|  |  |  |     @options.empty? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def as_flags | 
					
						
							|  |  |  |     map(&:flag) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def include?(o) | 
					
						
							|  |  |  |     any? { |opt| opt == o || opt.name == o || opt.flag == o } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |   alias to_ary to_a | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2013-05-24 10:56:02 -05:00
										 |  |  |   def inspect | 
					
						
							| 
									
										
										
										
											2014-07-01 15:07:06 -05:00
										 |  |  |     "#<#{self.class.name}: #{to_a.inspect}>" | 
					
						
							| 
									
										
										
										
											2013-05-24 10:56:02 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 19:53:37 +02:00
										 |  |  |   def self.dump_for_formula(f) | 
					
						
							| 
									
										
										
										
											2015-12-27 19:12:27 +01:00
										 |  |  |     f.options.sort_by(&:flag).each do |opt| | 
					
						
							|  |  |  |       puts "#{opt.flag}\n\t#{opt.description}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     puts "--HEAD\n\tInstall HEAD version" if f.head | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |