Merge pull request #11065 from Bo98/cellar-non-host

software_spec: fix handling of default non-host Cellar
This commit is contained in:
Bo Anderson 2021-04-08 21:44:11 +01:00 committed by GitHub
commit 093e6e4f79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 229 additions and 123 deletions

View File

@ -285,7 +285,11 @@ module Homebrew
[tag_string.to_sym, rebuild_string.to_i] [tag_string.to_sym, rebuild_string.to_i]
end end
bottle_tag ||= Utils::Bottles.tag bottle_tag = if bottle_tag
Utils::Bottles::Tag.from_symbol(bottle_tag)
else
Utils::Bottles.tag
end
rebuild ||= if args.no_rebuild? || !tap rebuild ||= if args.no_rebuild? || !tap
0 0
@ -299,7 +303,7 @@ module Homebrew
rebuilds.empty? ? 0 : rebuilds.max.to_i + 1 rebuilds.empty? ? 0 : rebuilds.max.to_i + 1
end end
filename = Bottle::Filename.create(f, bottle_tag, rebuild) filename = Bottle::Filename.create(f, bottle_tag.to_sym, rebuild)
local_filename = filename.to_s local_filename = filename.to_s
bottle_path = Pathname.pwd/filename bottle_path = Pathname.pwd/filename
@ -344,16 +348,8 @@ module Homebrew
relocatable = [:any, :any_skip_relocation].include?(bottle_cellar) relocatable = [:any, :any_skip_relocation].include?(bottle_cellar)
skip_relocation = bottle_cellar == :any_skip_relocation skip_relocation = bottle_cellar == :any_skip_relocation
if bottle_tag.to_s.end_with?("_linux") prefix = bottle_tag.default_prefix
prefix = HOMEBREW_LINUX_DEFAULT_PREFIX.to_s cellar = bottle_tag.default_cellar
cellar = Homebrew::DEFAULT_LINUX_CELLAR
elsif bottle_tag.to_s.start_with?("arm64_")
prefix = HOMEBREW_MACOS_ARM_DEFAULT_PREFIX.to_s
cellar = Homebrew::DEFAULT_MACOS_ARM_CELLAR
else
prefix = HOMEBREW_DEFAULT_PREFIX.to_s
cellar = Homebrew::DEFAULT_MACOS_CELLAR
end
else else
tar_filename = filename.to_s.sub(/.gz$/, "") tar_filename = filename.to_s.sub(/.gz$/, "")
tar_path = Pathname.pwd/tar_filename tar_path = Pathname.pwd/tar_filename
@ -487,7 +483,7 @@ module Homebrew
end end
bottle.rebuild rebuild bottle.rebuild rebuild
sha256 = bottle_path.sha256 sha256 = bottle_path.sha256
bottle.sha256 sha256 => bottle_tag bottle.sha256 sha256 => bottle_tag.to_sym
old_spec = f.bottle_specification old_spec = f.bottle_specification
if args.keep_old? && !old_spec.checksums.empty? if args.keep_old? && !old_spec.checksums.empty?

View File

@ -46,25 +46,28 @@ module Homebrew
repo.gsub!("linux", "home") unless args.tap repo.gsub!("linux", "home") unless args.tap
if (macos = args.macos) if (macos = args.macos)
# Fixup version for ARM/Apple Silicon # We accept runner name syntax (11-arm64) or bottle syntax (arm64_big_sur)
# TODO: fix label name to be 11-arm64 instead and remove this. os, arch = macos.yield_self do |s|
macos.gsub!(/^11-arm$/, "11-arm64") tag = Utils::Bottles::Tag.from_symbol(s.to_sym)
[tag.to_macos_version, tag.arch]
macos = macos.yield_self do |s| rescue ArgumentError, MacOSVersionError
MacOS::Version.from_symbol(s.to_sym) os, arch = s.split("-", 2)
rescue MacOSVersionError [MacOS::Version.new(os), arch&.to_sym]
MacOS::Version.new(s)
end end
# Fixup label for ARM/Apple Silicon
macos_label = if macos.arch == :arm64
# TODO: fix label name to be 11-arm64 instead. # TODO: fix label name to be 11-arm64 instead.
"#{macos}-arm" arch = :arm if arch == :arm64
macos_label = if arch.present? && arch != :x86_64
"#{os}-#{arch}"
else else
macos.to_s os.to_s
end end
dispatching_for = "macOS #{macos}" # TODO: fix label name to be 11 instead.
macos_label = "11.0" if macos_label == "11"
dispatching_for = "macOS #{macos_label}"
elsif T.unsafe(args).linux? elsif T.unsafe(args).linux?
workflow = args.workflow || "linux-#{workflow}" workflow = args.workflow || "linux-#{workflow}"
dispatching_for = "Linux" dispatching_for = "Linux"

View File

@ -34,7 +34,11 @@ module Homebrew
Formulary.enable_factory_cache! Formulary.enable_factory_cache!
@bottle_tag = args.tag.presence&.to_sym || Utils::Bottles.tag @bottle_tag = if (tag = args.tag)
Utils::Bottles::Tag.from_symbol(tag.to_sym)
else
Utils::Bottles.tag
end
if args.named.blank? if args.named.blank?
ohai "Getting formulae..." ohai "Getting formulae..."
@ -165,7 +169,7 @@ module Homebrew
end end
requirements = f.recursive_requirements requirements = f.recursive_requirements
if @bottle_tag.to_s.end_with?("_linux") if @bottle_tag.linux?
if requirements.any?(MacOSRequirement) if requirements.any?(MacOSRequirement)
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires macOS" if any_named_args puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires macOS" if any_named_args
next next
@ -174,7 +178,7 @@ module Homebrew
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires Linux" if any_named_args puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires Linux" if any_named_args
next next
else else
macos_version = MacOS::Version.from_symbol(@bottle_tag) macos_version = @bottle_tag.to_macos_version
macos_satisfied = requirements.all? do |r| macos_satisfied = requirements.all? do |r|
case r case r
when MacOSRequirement when MacOSRequirement

View File

@ -7,11 +7,7 @@ module Utils
undef tag undef tag
def tag def tag
if Hardware::CPU.intel? Utils::Bottles::Tag.new(system: MacOS.version.to_sym, arch: Hardware::CPU.arch)
MacOS.version.to_sym
else
"#{Hardware::CPU.arch}_#{MacOS.version.to_sym}".to_sym
end
end end
end end
@ -34,7 +30,7 @@ module Utils
# Find a bottle built for a previous version of macOS. # Find a bottle built for a previous version of macOS.
def find_older_compatible_tag(tag) def find_older_compatible_tag(tag)
tag_version = begin tag_version = begin
MacOS::Version.from_symbol(tag) tag.to_macos_version
rescue MacOSVersionError rescue MacOSVersionError
nil nil
end end
@ -42,10 +38,10 @@ module Utils
return if tag_version.blank? return if tag_version.blank?
keys.find do |key| keys.find do |key|
key_version = MacOS::Version.from_symbol(key) key_tag = Tag.from_symbol(key)
next if key_version.arch != tag_version.arch next if key_tag.arch != tag.arch
key_version <= tag_version key_tag.to_macos_version <= tag_version
rescue MacOSVersionError rescue MacOSVersionError
false false
end end

View File

@ -13,9 +13,6 @@ module OS
class Version < ::Version class Version < ::Version
extend T::Sig extend T::Sig
sig { returns(Symbol) }
attr_reader :arch
SYMBOLS = { SYMBOLS = {
big_sur: "11", big_sur: "11",
catalina: "10.15", catalina: "10.15",
@ -26,43 +23,20 @@ module OS
yosemite: "10.10", yosemite: "10.10",
}.freeze }.freeze
sig { params(sym: Symbol).returns(T.attached_class) } sig { params(version: Symbol).returns(T.attached_class) }
def self.from_symbol(sym) def self.from_symbol(version)
version, arch = version_arch(sym) str = SYMBOLS.fetch(version) { raise MacOSVersionError, version }
version ||= sym new(str)
str = SYMBOLS.fetch(version.to_sym) { raise MacOSVersionError, sym }
new(str, arch: arch)
end end
sig { params(value: T.any(String, Symbol)).returns(T.any([], [String, T.nilable(String)])) } sig { params(value: T.nilable(String)).void }
def self.version_arch(value) def initialize(value)
@all_archs_regex ||= begin
all_archs = Hardware::CPU::ALL_ARCHS.map(&:to_s)
/
^((?<prefix_arch>#{Regexp.union(all_archs)})_)?
(?<version>[\w.]+)
(-(?<suffix_arch>#{Regexp.union(all_archs)}))?$
/x
end
match = @all_archs_regex.match(value.to_s)
return [] unless match
version = match[:version]
arch = match[:prefix_arch] || match[:suffix_arch]
[version, arch]
end
sig { params(value: T.nilable(String), arch: T.nilable(String)).void }
def initialize(value, arch: nil)
version, arch = Version.version_arch(value) if value.present? && arch.nil?
version ||= value version ||= value
arch ||= "intel"
raise MacOSVersionError, version unless /\A1\d+(?:\.\d+){0,2}\Z/.match?(version) raise MacOSVersionError, version unless /\A1\d+(?:\.\d+){0,2}\Z/.match?(version)
super(version) super(version)
@arch = arch.to_sym
@comparison_cache = {} @comparison_cache = {}
end end

View File

@ -430,7 +430,6 @@ class BottleSpecification
def initialize def initialize
@rebuild = 0 @rebuild = 0
@prefix = Homebrew::DEFAULT_PREFIX @prefix = Homebrew::DEFAULT_PREFIX
@all_tags_cellar = Homebrew::DEFAULT_CELLAR
@repository = Homebrew::DEFAULT_REPOSITORY @repository = Homebrew::DEFAULT_REPOSITORY
@collector = Utils::Bottles::Collector.new @collector = Utils::Bottles::Collector.new
@root_url_specs = {} @root_url_specs = {}
@ -471,7 +470,9 @@ class BottleSpecification
# ) # )
# end # end
return collector.dig(Utils::Bottles.tag, :cellar) || @all_tags_cellar if val.nil? if val.nil?
return collector.dig(Utils::Bottles.tag.to_sym, :cellar) || @all_tags_cellar || Homebrew::DEFAULT_CELLAR
end
@all_tags_cellar = val @all_tags_cellar = val
end end
@ -494,7 +495,7 @@ class BottleSpecification
cellar == :any_skip_relocation cellar == :any_skip_relocation
end end
sig { params(tag: Symbol, exact: T::Boolean).returns(T::Boolean) } sig { params(tag: T.any(Symbol, Utils::Bottles::Tag), exact: T::Boolean).returns(T::Boolean) }
def tag?(tag, exact: false) def tag?(tag, exact: false)
checksum_for(tag, exact: exact) ? true : false checksum_for(tag, exact: exact) ? true : false
end end
@ -532,24 +533,36 @@ class BottleSpecification
# end # end
end end
tag = Utils::Bottles::Tag.from_symbol(tag)
cellar ||= all_tags_cellar cellar ||= all_tags_cellar
collector[tag] = { checksum: Checksum.new(digest), cellar: cellar } cellar ||= tag.default_cellar
collector[tag.to_sym] = { checksum: Checksum.new(digest), cellar: cellar }
end end
sig { params(tag: Symbol, exact: T::Boolean).returns(T.nilable([Checksum, Symbol, T.any(Symbol, String)])) } sig {
params(
tag: T.any(Symbol, Utils::Bottles::Tag),
exact: T::Boolean,
).returns(
T.nilable([Checksum, Symbol, T.any(Symbol, String)]),
)
}
def checksum_for(tag, exact: false) def checksum_for(tag, exact: false)
collector.fetch_checksum_for(tag, exact: exact) collector.fetch_checksum_for(tag, exact: exact)
end end
def checksums def checksums
tags = collector.keys.sort_by do |tag| tags = collector.keys.sort_by do |sym|
version = OS::Mac::Version.from_symbol(tag) tag = Utils::Bottles::Tag.from_symbol(sym)
version = tag.to_macos_version
# Give arm64 bottles a higher priority so they are first # Give arm64 bottles a higher priority so they are first
priority = version.arch == :arm64 ? "2" : "1" priority = tag.arch == :arm64 ? "2" : "1"
"#{priority}.#{version}_#{tag}" "#{priority}.#{version}_#{sym}"
rescue MacOSVersionError rescue MacOSVersionError
# Sort non-MacOS tags below MacOS tags. # Sort non-MacOS tags below MacOS tags.
"0.#{tag}" "0.#{sym}"
end end
tags.reverse.map do |tag| tags.reverse.map do |tag|
{ {

View File

@ -572,7 +572,7 @@ describe "brew bottle" do
new_catalina_sha256 = "ec6d7f08412468f28dee2be17ad8cd8b883b16b34329efcecce019b8c9736428" new_catalina_sha256 = "ec6d7f08412468f28dee2be17ad8cd8b883b16b34329efcecce019b8c9736428"
new_hash = { "tags" => { "catalina" => { "sha256" => new_catalina_sha256 } } } new_hash = { "tags" => { "catalina" => { "sha256" => new_catalina_sha256 } } }
expected_checksum_hash = { mojave: "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" } expected_checksum_hash = { mojave: "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" }
expected_checksum_hash[:cellar] = Homebrew::DEFAULT_CELLAR expected_checksum_hash[:cellar] = Homebrew::DEFAULT_MACOS_CELLAR
expect(homebrew.merge_bottle_spec([:sha256], old_spec, new_hash)).to eq [ expect(homebrew.merge_bottle_spec([:sha256], old_spec, new_hash)).to eq [
["sha256 catalina: old: #{old_catalina_sha256.inspect}, new: #{new_catalina_sha256.inspect}"], ["sha256 catalina: old: #{old_catalina_sha256.inspect}, new: #{new_catalina_sha256.inspect}"],
[expected_checksum_hash], [expected_checksum_hash],

View File

@ -831,7 +831,7 @@ describe Formula do
bottle do bottle do
cellar(:any) cellar(:any)
sha256(TEST_SHA256 => Utils::Bottles.tag) sha256(TEST_SHA256 => Utils::Bottles.tag.to_sym)
end end
end end

View File

@ -66,19 +66,6 @@ describe OS::Mac::Version do
it "creates a new version from a valid macOS version" do it "creates a new version from a valid macOS version" do
string_version = described_class.new("11") string_version = described_class.new("11")
expect(string_version).to eq(:big_sur) expect(string_version).to eq(:big_sur)
expect(string_version.arch).to eq(:intel)
end
it "creates a new version from a valid macOS version with architecture" do
string_version = described_class.new("11-arm64")
expect(string_version).to eq(:big_sur)
expect(string_version.arch).to eq(:arm64)
end
it "creates a new version from a valid macOS version and architecture" do
string_version = described_class.new("11", arch: "arm64")
expect(string_version).to eq(:big_sur)
expect(string_version.arch).to eq(:arm64)
end end
end end
@ -92,13 +79,6 @@ describe OS::Mac::Version do
it "creates a new version from a valid macOS version" do it "creates a new version from a valid macOS version" do
symbol_version = described_class.from_symbol(:mojave) symbol_version = described_class.from_symbol(:mojave)
expect(symbol_version).to eq(version) expect(symbol_version).to eq(version)
expect(symbol_version.arch).to eq(:intel)
end
it "creates a new version from a valid macOS version with architecture" do
symbol_version = described_class.from_symbol(:arm64_big_sur)
expect(symbol_version).to eq(:big_sur)
expect(symbol_version.arch).to eq(:arm64)
end end
end end

View File

@ -9,10 +9,10 @@ describe BottleSpecification do
describe "#sha256" do describe "#sha256" do
it "works without cellar" do it "works without cellar" do
checksums = { checksums = {
snow_leopard_32: "deadbeef" * 8, arm64_big_sur: "deadbeef" * 8,
snow_leopard: "faceb00c" * 8, big_sur: "faceb00c" * 8,
lion: "baadf00d" * 8, catalina: "baadf00d" * 8,
mountain_lion: "8badf00d" * 8, mojave: "8badf00d" * 8,
} }
checksums.each_pair do |cat, digest| checksums.each_pair do |cat, digest|
@ -24,10 +24,10 @@ describe BottleSpecification do
it "works with cellar" do it "works with cellar" do
checksums = [ checksums = [
{ cellar: :any_skip_relocation, tag: :snow_leopard_32, digest: "deadbeef" * 8 }, { cellar: :any_skip_relocation, tag: :arm64_big_sur, digest: "deadbeef" * 8 },
{ cellar: :any, tag: :snow_leopard, digest: "faceb00c" * 8 }, { cellar: :any, tag: :big_sur, digest: "faceb00c" * 8 },
{ cellar: "/usr/local/Cellar", tag: :lion, digest: "baadf00d" * 8 }, { cellar: "/usr/local/Cellar", tag: :catalina, digest: "baadf00d" * 8 },
{ cellar: Homebrew::DEFAULT_CELLAR, tag: :mountain_lion, digest: "8badf00d" * 8 }, { cellar: Homebrew::DEFAULT_CELLAR, tag: :mojave, digest: "8badf00d" * 8 },
] ]
checksums.each do |checksum| checksums.each do |checksum|

View File

@ -10,7 +10,7 @@ class TestballBottle < Formula
stable.bottle do stable.bottle do
cellar :any_skip_relocation cellar :any_skip_relocation
root_url "file://#{TEST_FIXTURE_DIR}/bottles" root_url "file://#{TEST_FIXTURE_DIR}/bottles"
sha256 "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" => Utils::Bottles.tag sha256 "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" => Utils::Bottles.tag.to_sym
end end
cxxstdlib_check :skip cxxstdlib_check :skip
end end

View File

@ -10,7 +10,7 @@ class TestballBottleCellar < Formula
hexdigest = "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" hexdigest = "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149"
stable.bottle do stable.bottle do
root_url "file://#{TEST_FIXTURE_DIR}/bottles" root_url "file://#{TEST_FIXTURE_DIR}/bottles"
sha256 cellar: :any_skip_relocation, Utils::Bottles.tag => hexdigest sha256 cellar: :any_skip_relocation, Utils::Bottles.tag.to_sym => hexdigest
end end
cxxstdlib_check :skip cxxstdlib_check :skip
end end

View File

@ -24,8 +24,8 @@ describe Utils::Bottles::Collector do
it "uses older tags when needed", :needs_macos do it "uses older tags when needed", :needs_macos do
collector[:mojave] = "foo" collector[:mojave] = "foo"
expect(collector.send(:find_matching_tag, :mojave)).to eq(:mojave) expect(collector.send(:find_matching_tag, Utils::Bottles::Tag.from_symbol(:mojave))).to eq(:mojave)
expect(collector.send(:find_matching_tag, :catalina)).to eq(:mojave) expect(collector.send(:find_matching_tag, Utils::Bottles::Tag.from_symbol(:catalina))).to eq(:mojave)
end end
it "does not use older tags when requested not to", :needs_macos do it "does not use older tags when requested not to", :needs_macos do
@ -33,16 +33,16 @@ describe Utils::Bottles::Collector do
allow(Homebrew::EnvConfig).to receive(:skip_or_later_bottles?).and_return(true) allow(Homebrew::EnvConfig).to receive(:skip_or_later_bottles?).and_return(true)
allow(OS::Mac).to receive(:prerelease?).and_return(true) allow(OS::Mac).to receive(:prerelease?).and_return(true)
collector[:mojave] = "foo" collector[:mojave] = "foo"
expect(collector.send(:find_matching_tag, :mojave)).to eq(:mojave) expect(collector.send(:find_matching_tag, Utils::Bottles::Tag.from_symbol(:mojave))).to eq(:mojave)
expect(collector.send(:find_matching_tag, :catalina)).to be_nil expect(collector.send(:find_matching_tag, Utils::Bottles::Tag.from_symbol(:catalina))).to be_nil
end end
it "ignores HOMEBREW_SKIP_OR_LATER_BOTTLES on release versions", :needs_macos do it "ignores HOMEBREW_SKIP_OR_LATER_BOTTLES on release versions", :needs_macos do
allow(Homebrew::EnvConfig).to receive(:skip_or_later_bottles?).and_return(true) allow(Homebrew::EnvConfig).to receive(:skip_or_later_bottles?).and_return(true)
allow(OS::Mac).to receive(:prerelease?).and_return(false) allow(OS::Mac).to receive(:prerelease?).and_return(false)
collector[:mojave] = "foo" collector[:mojave] = "foo"
expect(collector.send(:find_matching_tag, :mojave)).to eq(:mojave) expect(collector.send(:find_matching_tag, Utils::Bottles::Tag.from_symbol(:mojave))).to eq(:mojave)
expect(collector.send(:find_matching_tag, :catalina)).to eq(:mojave) expect(collector.send(:find_matching_tag, Utils::Bottles::Tag.from_symbol(:catalina))).to eq(:mojave)
end end
end end
end end

View File

@ -0,0 +1,39 @@
# typed: false
# frozen_string_literal: true
require "utils/bottles"
describe Utils::Bottles::Tag do
it "can parse macOS symbols with archs" do
symbol = :arm64_big_sur
tag = described_class.from_symbol(symbol)
expect(tag.system).to eq(:big_sur)
expect(tag.arch).to eq(:arm64)
expect(tag.to_macos_version).to eq(OS::Mac::Version.from_symbol(:big_sur))
expect(tag.macos?).to be true
expect(tag.linux?).to be false
expect(tag.to_sym).to eq(symbol)
end
it "can parse macOS symbols without archs" do
symbol = :big_sur
tag = described_class.from_symbol(symbol)
expect(tag.system).to eq(:big_sur)
expect(tag.arch).to eq(:x86_64)
expect(tag.to_macos_version).to eq(OS::Mac::Version.from_symbol(:big_sur))
expect(tag.macos?).to be true
expect(tag.linux?).to be false
expect(tag.to_sym).to eq(symbol)
end
it "can parse Linux symbols" do
symbol = :x86_64_linux
tag = described_class.from_symbol(symbol)
expect(tag.system).to eq(:linux)
expect(tag.arch).to eq(:x86_64)
expect { tag.to_macos_version }.to raise_error(MacOSVersionError)
expect(tag.macos?).to be false
expect(tag.linux?).to be true
expect(tag.to_sym).to eq(symbol)
end
end

View File

@ -12,7 +12,8 @@ module Utils
extend T::Sig extend T::Sig
def tag def tag
@tag ||= "#{ENV["HOMEBREW_PROCESSOR"]}_#{ENV["HOMEBREW_SYSTEM"]}".downcase.to_sym @tag ||= Tag.new(system: T.must(ENV["HOMEBREW_SYSTEM"]).downcase.to_sym,
arch: T.must(ENV["HOMEBREW_PROCESSOR"]).downcase.to_sym)
end end
def built_as?(f) def built_as?(f)
@ -78,6 +79,98 @@ module Utils
end end
end end
# Denotes the arch and OS of a bottle.
class Tag
extend T::Sig
attr_reader :system, :arch
sig { params(value: Symbol).returns(T.attached_class) }
def self.from_symbol(value)
@all_archs_regex ||= begin
all_archs = Hardware::CPU::ALL_ARCHS.map(&:to_s)
/
^((?<arch>#{Regexp.union(all_archs)})_)?
(?<system>[\w.]+)$
/x
end
match = @all_archs_regex.match(value.to_s)
raise ArgumentError, "Invalid bottle tag symbol" unless match
system = match[:system].to_sym
arch = match[:arch]&.to_sym || :x86_64
new(system: system, arch: arch)
end
sig { params(system: Symbol, arch: Symbol).void }
def initialize(system:, arch:)
@system = system
@arch = arch
end
def ==(other)
if other.is_a?(Symbol)
to_sym == other
else
self.class == other.class && system == other.system && arch == other.arch
end
end
sig { returns(Symbol) }
def to_sym
if macos? && arch == :x86_64
system
else
"#{arch}_#{system}".to_sym
end
end
sig { returns(String) }
def to_s
to_sym.to_s
end
sig { returns(OS::Mac::Version) }
def to_macos_version
@to_macos_version ||= OS::Mac::Version.from_symbol(system)
end
sig { returns(T::Boolean) }
def linux?
system == :linux
end
sig { returns(T::Boolean) }
def macos?
to_macos_version
true
rescue MacOSVersionError
false
end
sig { returns(String) }
def default_prefix
if linux?
HOMEBREW_LINUX_DEFAULT_PREFIX
elsif arch == :arm64
HOMEBREW_MACOS_ARM_DEFAULT_PREFIX
else
HOMEBREW_DEFAULT_PREFIX
end
end
sig { returns(String) }
def default_cellar
if linux?
Homebrew::DEFAULT_LINUX_CELLAR
elsif arch == :arm64
Homebrew::DEFAULT_MACOS_ARM_CELLAR
else
Homebrew::DEFAULT_MACOS_CELLAR
end
end
end
# Helper functions for bottles hosted on Bintray. # Helper functions for bottles hosted on Bintray.
module Bintray module Bintray
def self.package(formula_name) def self.package(formula_name)
@ -109,16 +202,24 @@ module Utils
@checksums = {} @checksums = {}
end end
sig { params(tag: Symbol, exact: T::Boolean).returns(T.nilable([Checksum, Symbol, T.any(Symbol, String)])) } sig {
params(
tag: T.any(Symbol, Utils::Bottles::Tag),
exact: T::Boolean,
).returns(
T.nilable([Checksum, Symbol, T.any(Symbol, String)]),
)
}
def fetch_checksum_for(tag, exact: false) def fetch_checksum_for(tag, exact: false)
tag = find_matching_tag(tag, exact: exact) tag = Utils::Bottles::Tag.from_symbol(tag) if tag.is_a?(Symbol)
tag = find_matching_tag(tag, exact: exact)&.to_sym
return self[tag][:checksum], tag, self[tag][:cellar] if tag return self[tag][:checksum], tag, self[tag][:cellar] if tag
end end
private private
def find_matching_tag(tag, exact: false) def find_matching_tag(tag, exact: false)
tag if key?(tag) tag if key?(tag.to_sym)
end end
end end
end end