2024-08-12 10:30:59 +01:00
|
|
|
# typed: true # rubocop:todo Sorbet/StrictSigil
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-18 21:42:43 -04:00
|
|
|
# Used to track formulae that cannot be installed at the same time.
|
2013-06-09 13:44:59 -05:00
|
|
|
FormulaConflict = Struct.new(:name, :reason)
|
|
|
|
|
2020-11-05 17:17:03 -05:00
|
|
|
# Used to annotate formulae that duplicate macOS-provided software
|
2012-02-04 18:45:08 -08:00
|
|
|
# or cause conflicts when linked in.
|
|
|
|
class KegOnlyReason
|
2017-03-19 20:45:21 +02:00
|
|
|
attr_reader :reason
|
|
|
|
|
2014-08-08 01:34:45 -05:00
|
|
|
def initialize(reason, explanation)
|
2012-02-04 18:45:08 -08:00
|
|
|
@reason = reason
|
|
|
|
@explanation = explanation
|
|
|
|
end
|
|
|
|
|
2020-04-11 14:15:42 +01:00
|
|
|
def versioned_formula?
|
|
|
|
@reason == :versioned_formula
|
|
|
|
end
|
|
|
|
|
|
|
|
def provided_by_macos?
|
|
|
|
@reason == :provided_by_macos
|
|
|
|
end
|
|
|
|
|
|
|
|
def shadowed_by_macos?
|
|
|
|
@reason == :shadowed_by_macos
|
|
|
|
end
|
|
|
|
|
|
|
|
def by_macos?
|
|
|
|
provided_by_macos? || shadowed_by_macos?
|
|
|
|
end
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(T::Boolean) }
|
2020-04-11 14:15:42 +01:00
|
|
|
def applicable?
|
|
|
|
# macOS reasons aren't applicable on other OSs
|
|
|
|
# (see extend/os/mac/formula_support for override on macOS)
|
|
|
|
!by_macos?
|
2012-08-09 02:00:58 -05:00
|
|
|
end
|
2012-02-04 18:45:08 -08:00
|
|
|
|
2024-04-26 14:04:55 +02:00
|
|
|
sig { returns(String) }
|
2012-08-09 02:00:58 -05:00
|
|
|
def to_s
|
2015-07-24 00:49:34 +02:00
|
|
|
return @explanation unless @explanation.empty?
|
2018-01-18 09:47:33 +00:00
|
|
|
|
2020-04-11 14:15:42 +01:00
|
|
|
if versioned_formula?
|
2018-04-16 22:17:48 +01:00
|
|
|
<<~EOS
|
|
|
|
this is an alternate version of another formula
|
|
|
|
EOS
|
2020-04-11 14:15:42 +01:00
|
|
|
elsif provided_by_macos?
|
2018-04-16 22:17:48 +01:00
|
|
|
<<~EOS
|
|
|
|
macOS already provides this software and installing another version in
|
|
|
|
parallel can cause all kinds of trouble
|
|
|
|
EOS
|
2020-04-11 14:15:42 +01:00
|
|
|
elsif shadowed_by_macos?
|
2018-04-16 22:17:48 +01:00
|
|
|
<<~EOS
|
|
|
|
macOS provides similar software and installing this software in
|
|
|
|
parallel can cause all kinds of trouble
|
|
|
|
EOS
|
2012-02-04 18:45:08 -08:00
|
|
|
else
|
2012-08-09 02:00:58 -05:00
|
|
|
@reason
|
|
|
|
end.strip
|
2012-02-04 18:45:08 -08:00
|
|
|
end
|
2021-12-11 23:30:06 +00:00
|
|
|
|
|
|
|
def to_hash
|
|
|
|
reason_string = if @reason.is_a?(Symbol)
|
|
|
|
@reason.inspect
|
|
|
|
else
|
|
|
|
@reason.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
"reason" => reason_string,
|
|
|
|
"explanation" => @explanation,
|
|
|
|
}
|
|
|
|
end
|
2012-02-04 18:45:08 -08:00
|
|
|
end
|
2015-09-14 19:51:04 +08:00
|
|
|
|
2018-08-15 10:14:17 -07:00
|
|
|
require "extend/os/formula_support"
|