Merge pull request #11065 from Bo98/cellar-non-host
software_spec: fix handling of default non-host Cellar
This commit is contained in:
		
						commit
						093e6e4f79
					
				@ -285,7 +285,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
 | 
			
		||||
@ -299,7 +303,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
 | 
			
		||||
 | 
			
		||||
@ -344,16 +348,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
 | 
			
		||||
@ -487,7 +483,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?
 | 
			
		||||
 | 
			
		||||
@ -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"
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
          /
 | 
			
		||||
            ^((?<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?
 | 
			
		||||
      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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -430,7 +430,6 @@ class BottleSpecification
 | 
			
		||||
  def initialize
 | 
			
		||||
    @rebuild = 0
 | 
			
		||||
    @prefix = Homebrew::DEFAULT_PREFIX
 | 
			
		||||
    @all_tags_cellar = Homebrew::DEFAULT_CELLAR
 | 
			
		||||
    @repository = Homebrew::DEFAULT_REPOSITORY
 | 
			
		||||
    @collector = Utils::Bottles::Collector.new
 | 
			
		||||
    @root_url_specs = {}
 | 
			
		||||
@ -471,7 +470,9 @@ class BottleSpecification
 | 
			
		||||
    #   )
 | 
			
		||||
    # 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
 | 
			
		||||
  end
 | 
			
		||||
@ -494,7 +495,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,24 +533,36 @@ class BottleSpecification
 | 
			
		||||
      # end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    tag = Utils::Bottles::Tag.from_symbol(tag)
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
  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|
 | 
			
		||||
      {
 | 
			
		||||
 | 
			
		||||
@ -572,7 +572,7 @@ describe "brew bottle" do
 | 
			
		||||
        new_catalina_sha256 = "ec6d7f08412468f28dee2be17ad8cd8b883b16b34329efcecce019b8c9736428"
 | 
			
		||||
        new_hash = { "tags" => { "catalina" => { "sha256" => new_catalina_sha256 } } }
 | 
			
		||||
        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 [
 | 
			
		||||
          ["sha256 catalina: old: #{old_catalina_sha256.inspect}, new: #{new_catalina_sha256.inspect}"],
 | 
			
		||||
          [expected_checksum_hash],
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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|
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										39
									
								
								Library/Homebrew/test/utils/bottles/tag_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Library/Homebrew/test/utils/bottles/tag_spec.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
@ -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)
 | 
			
		||||
          /
 | 
			
		||||
            ^((?<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.
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user