Merge pull request #14870 from nandahkrishna/fix-requirement

Fix `{MacOS,Xcode}Requirement` handling and improve output
This commit is contained in:
Mike McQuaid 2023-03-07 19:26:47 +00:00 committed by GitHub
commit 3e2c713c92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 12 deletions

View File

@ -159,9 +159,11 @@ module Homebrew
sig { params(json: Hash).returns(Hash) } sig { params(json: Hash).returns(Hash) }
def self.merge_variations(json) def self.merge_variations(json)
if (bottle_tag = ::Utils::Bottles.tag.to_s.presence) && bottle_tag = ::Utils::Bottles::Tag.new(system: Homebrew::SimulateSystem.current_os,
(variations = json["variations"].presence) && arch: Homebrew::SimulateSystem.current_arch)
(variation = variations[bottle_tag].presence)
if (variations = json["variations"].presence) &&
(variation = variations[bottle_tag.to_s].presence)
json = json.merge(variation) json = json.merge(variation)
end end

View File

@ -4,6 +4,7 @@
require "cli/parser" require "cli/parser"
require "formula" require "formula"
require "api" require "api"
require "os/mac/xcode"
module Homebrew module Homebrew
extend T::Sig extend T::Sig

View File

@ -51,12 +51,12 @@ class MacOSRequirement < Requirement
end end
def version_specified? def version_specified?
OS.mac? && @version @version.present?
end end
satisfy(build_env: false) do satisfy(build_env: false) do
T.bind(self, MacOSRequirement) T.bind(self, MacOSRequirement)
next Array(@version).any? { |v| MacOS.version.public_send(@comparator, v) } if version_specified? next Array(@version).any? { |v| MacOS.version.public_send(@comparator, v) } if OS.mac? && version_specified?
next true if OS.mac? next true if OS.mac?
next true if @version next true if @version
@ -68,7 +68,7 @@ class MacOSRequirement < Requirement
case @comparator case @comparator
when ">=" when ">="
"macOS #{@version.pretty_name} or newer is required for this software." "This software does not run on macOS versions older than #{@version.pretty_name}."
when "<=" when "<="
case type case type
when :formula when :formula
@ -82,10 +82,10 @@ class MacOSRequirement < Requirement
else else
if @version.respond_to?(:to_ary) if @version.respond_to?(:to_ary)
*versions, last = @version.map(&:pretty_name) *versions, last = @version.map(&:pretty_name)
return "macOS #{versions.join(", ")} or #{last} is required for this software." return "This software does not run on macOS versions other than #{versions.join(", ")} and #{last}."
end end
"macOS #{@version.pretty_name} is required for this software." "This software does not run on macOS versions other than #{@version.pretty_name}."
end end
end end
@ -107,9 +107,9 @@ class MacOSRequirement < Requirement
def display_s def display_s
if version_specified? if version_specified?
if @version.respond_to?(:to_ary) if @version.respond_to?(:to_ary)
"macOS #{@comparator} #{version.join(" / ")}" "macOS #{@comparator} #{version.join(" / ")} (or Linux)"
else else
"macOS #{@comparator} #{@version}" "macOS #{@comparator} #{@version} (or Linux)"
end end
else else
"macOS" "macOS"

View File

@ -58,9 +58,9 @@ class XcodeRequirement < Requirement
end end
def display_s def display_s
return name.capitalize unless @version return "#{name.capitalize} (on macOS)" unless @version
"#{name.capitalize} >= #{@version}" "#{name.capitalize} >= #{@version} (on macOS)"
end end
end end