From 20d86c01850df6855e5e8b5958d3e6892de87190 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Thu, 8 Apr 2021 13:45:15 +0100 Subject: [PATCH] Refactor some tag handling into a Utils::Bottles::Tag class --- Library/Homebrew/dev-cmd/bottle.rb | 22 ++-- .../Homebrew/dev-cmd/dispatch-build-bottle.rb | 31 ++--- Library/Homebrew/dev-cmd/unbottled.rb | 10 +- .../Homebrew/extend/os/mac/utils/bottles.rb | 14 +-- Library/Homebrew/os/mac/version.rb | 38 +----- Library/Homebrew/software_spec.rb | 40 ++++--- Library/Homebrew/test/formula_spec.rb | 2 +- Library/Homebrew/test/os/mac/version_spec.rb | 20 ---- .../test/software_spec/bottle_spec.rb | 16 +-- .../test/support/fixtures/testball_bottle.rb | 2 +- .../fixtures/testball_bottle_cellar.rb | 2 +- .../test/utils/bottles/collector_spec.rb | 12 +- .../Homebrew/test/utils/bottles/tag_spec.rb | 39 +++++++ Library/Homebrew/utils/bottles.rb | 109 +++++++++++++++++- 14 files changed, 228 insertions(+), 129 deletions(-) create mode 100644 Library/Homebrew/test/utils/bottles/tag_spec.rb diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 3a3f771c70..a196a8196f 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -284,7 +284,11 @@ module Homebrew [tag_string.to_sym, rebuild_string.to_i] 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 0 @@ -298,7 +302,7 @@ module Homebrew rebuilds.empty? ? 0 : rebuilds.max.to_i + 1 end - filename = Bottle::Filename.create(f, bottle_tag, rebuild) + filename = Bottle::Filename.create(f, bottle_tag.to_sym, rebuild) local_filename = filename.to_s bottle_path = Pathname.pwd/filename @@ -343,16 +347,8 @@ module Homebrew relocatable = [:any, :any_skip_relocation].include?(bottle_cellar) skip_relocation = bottle_cellar == :any_skip_relocation - if bottle_tag.to_s.end_with?("_linux") - prefix = HOMEBREW_LINUX_DEFAULT_PREFIX.to_s - 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 + prefix = bottle_tag.default_prefix + cellar = bottle_tag.default_cellar else tar_filename = filename.to_s.sub(/.gz$/, "") tar_path = Pathname.pwd/tar_filename @@ -486,7 +482,7 @@ module Homebrew end bottle.rebuild rebuild sha256 = bottle_path.sha256 - bottle.sha256 sha256 => bottle_tag + bottle.sha256 sha256 => bottle_tag.to_sym old_spec = f.bottle_specification if args.keep_old? && !old_spec.checksums.empty? diff --git a/Library/Homebrew/dev-cmd/dispatch-build-bottle.rb b/Library/Homebrew/dev-cmd/dispatch-build-bottle.rb index 915e3d5106..cb857df69d 100644 --- a/Library/Homebrew/dev-cmd/dispatch-build-bottle.rb +++ b/Library/Homebrew/dev-cmd/dispatch-build-bottle.rb @@ -46,25 +46,28 @@ module Homebrew repo.gsub!("linux", "home") unless args.tap if (macos = args.macos) - # Fixup version for ARM/Apple Silicon - # TODO: fix label name to be 11-arm64 instead and remove this. - macos.gsub!(/^11-arm$/, "11-arm64") - - macos = macos.yield_self do |s| - MacOS::Version.from_symbol(s.to_sym) - rescue MacOSVersionError - MacOS::Version.new(s) + # We accept runner name syntax (11-arm64) or bottle syntax (arm64_big_sur) + os, arch = macos.yield_self do |s| + tag = Utils::Bottles::Tag.from_symbol(s.to_sym) + [tag.to_macos_version, tag.arch] + rescue ArgumentError, MacOSVersionError + os, arch = s.split("-", 2) + [MacOS::Version.new(os), arch&.to_sym] end - # Fixup label for ARM/Apple Silicon - macos_label = if macos.arch == :arm64 - # TODO: fix label name to be 11-arm64 instead. - "#{macos}-arm" + # TODO: fix label name to be 11-arm64 instead. + arch = :arm if arch == :arm64 + + macos_label = if arch.present? && arch != :x86_64 + "#{os}-#{arch}" else - macos.to_s + os.to_s 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? workflow = args.workflow || "linux-#{workflow}" dispatching_for = "Linux" diff --git a/Library/Homebrew/dev-cmd/unbottled.rb b/Library/Homebrew/dev-cmd/unbottled.rb index d25d46a06e..d7bf41554c 100644 --- a/Library/Homebrew/dev-cmd/unbottled.rb +++ b/Library/Homebrew/dev-cmd/unbottled.rb @@ -34,7 +34,11 @@ module Homebrew 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? ohai "Getting formulae..." @@ -165,7 +169,7 @@ module Homebrew end requirements = f.recursive_requirements - if @bottle_tag.to_s.end_with?("_linux") + if @bottle_tag.linux? if requirements.any?(MacOSRequirement) puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires macOS" if any_named_args next @@ -174,7 +178,7 @@ module Homebrew puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires Linux" if any_named_args next else - macos_version = MacOS::Version.from_symbol(@bottle_tag) + macos_version = @bottle_tag.to_macos_version macos_satisfied = requirements.all? do |r| case r when MacOSRequirement diff --git a/Library/Homebrew/extend/os/mac/utils/bottles.rb b/Library/Homebrew/extend/os/mac/utils/bottles.rb index 61141336a1..03a302a0ca 100644 --- a/Library/Homebrew/extend/os/mac/utils/bottles.rb +++ b/Library/Homebrew/extend/os/mac/utils/bottles.rb @@ -7,11 +7,7 @@ module Utils undef tag def tag - if Hardware::CPU.intel? - MacOS.version.to_sym - else - "#{Hardware::CPU.arch}_#{MacOS.version.to_sym}".to_sym - end + Utils::Bottles::Tag.new(system: MacOS.version.to_sym, arch: Hardware::CPU.arch) end end @@ -34,7 +30,7 @@ module Utils # Find a bottle built for a previous version of macOS. def find_older_compatible_tag(tag) tag_version = begin - MacOS::Version.from_symbol(tag) + tag.to_macos_version rescue MacOSVersionError nil end @@ -42,10 +38,10 @@ module Utils return if tag_version.blank? keys.find do |key| - key_version = MacOS::Version.from_symbol(key) - next if key_version.arch != tag_version.arch + key_tag = Tag.from_symbol(key) + next if key_tag.arch != tag.arch - key_version <= tag_version + key_tag.to_macos_version <= tag_version rescue MacOSVersionError false end diff --git a/Library/Homebrew/os/mac/version.rb b/Library/Homebrew/os/mac/version.rb index 389b3d739d..6b5c6aaa57 100644 --- a/Library/Homebrew/os/mac/version.rb +++ b/Library/Homebrew/os/mac/version.rb @@ -13,9 +13,6 @@ module OS class Version < ::Version extend T::Sig - sig { returns(Symbol) } - attr_reader :arch - SYMBOLS = { big_sur: "11", catalina: "10.15", @@ -26,43 +23,20 @@ module OS yosemite: "10.10", }.freeze - sig { params(sym: Symbol).returns(T.attached_class) } - def self.from_symbol(sym) - version, arch = version_arch(sym) - version ||= sym - str = SYMBOLS.fetch(version.to_sym) { raise MacOSVersionError, sym } - new(str, arch: arch) + sig { params(version: Symbol).returns(T.attached_class) } + def self.from_symbol(version) + str = SYMBOLS.fetch(version) { raise MacOSVersionError, version } + new(str) end - sig { params(value: T.any(String, Symbol)).returns(T.any([], [String, T.nilable(String)])) } - def self.version_arch(value) - @all_archs_regex ||= begin - all_archs = Hardware::CPU::ALL_ARCHS.map(&:to_s) - / - ^((?#{Regexp.union(all_archs)})_)? - (?[\w.]+) - (-(?#{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? + sig { params(value: T.nilable(String)).void } + def initialize(value) version ||= value - arch ||= "intel" raise MacOSVersionError, version unless /\A1\d+(?:\.\d+){0,2}\Z/.match?(version) super(version) - @arch = arch.to_sym @comparison_cache = {} end diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 9ff5d55aac..f72fd8ea05 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -471,7 +471,9 @@ class BottleSpecification # ) # end - return collector.dig(Utils::Bottles.tag, :cellar) || @all_tags_cellar || Homebrew::DEFAULT_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 end @@ -494,7 +496,7 @@ class BottleSpecification cellar == :any_skip_relocation 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) checksum_for(tag, exact: exact) ? true : false end @@ -532,32 +534,36 @@ class BottleSpecification # end end - cellar ||= all_tags_cellar - cellar ||= if tag.to_s.end_with?("_linux") - Homebrew::DEFAULT_LINUX_CELLAR - elsif tag.to_s.start_with?("arm64_") - Homebrew::DEFAULT_MACOS_ARM_CELLAR - else - Homebrew::DEFAULT_MACOS_CELLAR - end + tag = Utils::Bottles::Tag.from_symbol(tag) - collector[tag] = { checksum: Checksum.new(digest), cellar: cellar } + cellar ||= all_tags_cellar + cellar ||= tag.default_cellar + + collector[tag.to_sym] = { checksum: Checksum.new(digest), cellar: cellar } 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) collector.fetch_checksum_for(tag, exact: exact) end def checksums - tags = collector.keys.sort_by do |tag| - version = OS::Mac::Version.from_symbol(tag) + tags = collector.keys.sort_by do |sym| + tag = Utils::Bottles::Tag.from_symbol(sym) + version = tag.to_macos_version # Give arm64 bottles a higher priority so they are first - priority = version.arch == :arm64 ? "2" : "1" - "#{priority}.#{version}_#{tag}" + priority = tag.arch == :arm64 ? "2" : "1" + "#{priority}.#{version}_#{sym}" rescue MacOSVersionError # Sort non-MacOS tags below MacOS tags. - "0.#{tag}" + "0.#{sym}" end tags.reverse.map do |tag| { diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 937aeb4d59..e5c5550e71 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -831,7 +831,7 @@ describe Formula do bottle do cellar(:any) - sha256(TEST_SHA256 => Utils::Bottles.tag) + sha256(TEST_SHA256 => Utils::Bottles.tag.to_sym) end end diff --git a/Library/Homebrew/test/os/mac/version_spec.rb b/Library/Homebrew/test/os/mac/version_spec.rb index c69e0239bc..f9f50db7a2 100644 --- a/Library/Homebrew/test/os/mac/version_spec.rb +++ b/Library/Homebrew/test/os/mac/version_spec.rb @@ -66,19 +66,6 @@ describe OS::Mac::Version do it "creates a new version from a valid macOS version" do string_version = described_class.new("11") 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 @@ -92,13 +79,6 @@ describe OS::Mac::Version do it "creates a new version from a valid macOS version" do symbol_version = described_class.from_symbol(:mojave) 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 diff --git a/Library/Homebrew/test/software_spec/bottle_spec.rb b/Library/Homebrew/test/software_spec/bottle_spec.rb index 360f159bed..521b557f00 100644 --- a/Library/Homebrew/test/software_spec/bottle_spec.rb +++ b/Library/Homebrew/test/software_spec/bottle_spec.rb @@ -9,10 +9,10 @@ describe BottleSpecification do describe "#sha256" do it "works without cellar" do checksums = { - snow_leopard_32: "deadbeef" * 8, - snow_leopard: "faceb00c" * 8, - lion: "baadf00d" * 8, - mountain_lion: "8badf00d" * 8, + arm64_big_sur: "deadbeef" * 8, + big_sur: "faceb00c" * 8, + catalina: "baadf00d" * 8, + mojave: "8badf00d" * 8, } checksums.each_pair do |cat, digest| @@ -24,10 +24,10 @@ describe BottleSpecification do it "works with cellar" do checksums = [ - { cellar: :any_skip_relocation, tag: :snow_leopard_32, digest: "deadbeef" * 8 }, - { cellar: :any, tag: :snow_leopard, digest: "faceb00c" * 8 }, - { cellar: "/usr/local/Cellar", tag: :lion, digest: "baadf00d" * 8 }, - { cellar: Homebrew::DEFAULT_CELLAR, tag: :mountain_lion, digest: "8badf00d" * 8 }, + { cellar: :any_skip_relocation, tag: :arm64_big_sur, digest: "deadbeef" * 8 }, + { cellar: :any, tag: :big_sur, digest: "faceb00c" * 8 }, + { cellar: "/usr/local/Cellar", tag: :catalina, digest: "baadf00d" * 8 }, + { cellar: Homebrew::DEFAULT_CELLAR, tag: :mojave, digest: "8badf00d" * 8 }, ] checksums.each do |checksum| diff --git a/Library/Homebrew/test/support/fixtures/testball_bottle.rb b/Library/Homebrew/test/support/fixtures/testball_bottle.rb index d3f159eaf9..bcf9e81a62 100644 --- a/Library/Homebrew/test/support/fixtures/testball_bottle.rb +++ b/Library/Homebrew/test/support/fixtures/testball_bottle.rb @@ -10,7 +10,7 @@ class TestballBottle < Formula stable.bottle do cellar :any_skip_relocation root_url "file://#{TEST_FIXTURE_DIR}/bottles" - sha256 "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" => Utils::Bottles.tag + sha256 "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" => Utils::Bottles.tag.to_sym end cxxstdlib_check :skip end diff --git a/Library/Homebrew/test/support/fixtures/testball_bottle_cellar.rb b/Library/Homebrew/test/support/fixtures/testball_bottle_cellar.rb index c647c97971..58bd8edfeb 100644 --- a/Library/Homebrew/test/support/fixtures/testball_bottle_cellar.rb +++ b/Library/Homebrew/test/support/fixtures/testball_bottle_cellar.rb @@ -10,7 +10,7 @@ class TestballBottleCellar < Formula hexdigest = "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" stable.bottle do 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 cxxstdlib_check :skip end diff --git a/Library/Homebrew/test/utils/bottles/collector_spec.rb b/Library/Homebrew/test/utils/bottles/collector_spec.rb index aa9d0aa065..d0f264e338 100644 --- a/Library/Homebrew/test/utils/bottles/collector_spec.rb +++ b/Library/Homebrew/test/utils/bottles/collector_spec.rb @@ -24,8 +24,8 @@ describe Utils::Bottles::Collector do it "uses older tags when needed", :needs_macos do collector[:mojave] = "foo" - expect(collector.send(:find_matching_tag, :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(:mojave))).to eq(:mojave) + expect(collector.send(:find_matching_tag, Utils::Bottles::Tag.from_symbol(:catalina))).to eq(:mojave) end 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(OS::Mac).to receive(:prerelease?).and_return(true) collector[:mojave] = "foo" - expect(collector.send(:find_matching_tag, :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(:mojave))).to eq(:mojave) + expect(collector.send(:find_matching_tag, Utils::Bottles::Tag.from_symbol(:catalina))).to be_nil end 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(OS::Mac).to receive(:prerelease?).and_return(false) collector[:mojave] = "foo" - expect(collector.send(:find_matching_tag, :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(:mojave))).to eq(:mojave) + expect(collector.send(:find_matching_tag, Utils::Bottles::Tag.from_symbol(:catalina))).to eq(:mojave) end end end diff --git a/Library/Homebrew/test/utils/bottles/tag_spec.rb b/Library/Homebrew/test/utils/bottles/tag_spec.rb new file mode 100644 index 0000000000..1f2d5d4163 --- /dev/null +++ b/Library/Homebrew/test/utils/bottles/tag_spec.rb @@ -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 diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index d01b8582a6..adcf14a0f3 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -12,7 +12,8 @@ module Utils extend T::Sig 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 def built_as?(f) @@ -78,6 +79,98 @@ module Utils 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) + / + ^((?#{Regexp.union(all_archs)})_)? + (?[\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. module Bintray def self.package(formula_name) @@ -109,16 +202,24 @@ module Utils @checksums = {} 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) - 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 end private def find_matching_tag(tag, exact: false) - tag if key?(tag) + tag if key?(tag.to_sym) end end end