Class: BottleSpecification Private

Inherits:
Object show all
Extended by:
Attrable
Defined in:
extend/os/linux/bottle_specification.rb,
bottle_specification.rb,
sorbet/rbi/dsl/bottle_specification.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Constant Summary collapse

RELOCATABLE_CELLARS =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

[:any, :any_skip_relocation].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attrable

attr_predicate, attr_rw

Constructor Details

#initializevoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



13
14
15
16
17
18
# File 'bottle_specification.rb', line 13

def initialize
  @rebuild = 0
  @repository = Homebrew::DEFAULT_REPOSITORY
  @collector = Utils::Bottles::Collector.new
  @root_url_specs = {}
end

Instance Attribute Details

#collectorObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
11
12
# File 'bottle_specification.rb', line 10

def collector
  @collector
end

#repositoryObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
11
12
# File 'bottle_specification.rb', line 10

def repository
  @repository
end

#root_url_specsObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
11
12
# File 'bottle_specification.rb', line 10

def root_url_specs
  @root_url_specs
end

#tapObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



9
10
11
# File 'bottle_specification.rb', line 9

def tap
  @tap
end

Instance Method Details

#checksumsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'bottle_specification.rb', line 114

def checksums
  tags = collector.tags.sort_by do |tag|
    version = tag.to_macos_version
    # Give `arm64` bottles a higher priority so they are first.
    priority = (tag.arch == :arm64) ? 2 : 1
    "#{priority}.#{version}_#{tag}"
  rescue MacOSVersion::Error
    # Sort non-macOS tags below macOS tags.
    "0.#{tag}"
  end
  tags.reverse.map do |tag|
    spec = collector.specification_for(tag)
    {
      "tag"    => spec.tag.to_sym,
      "digest" => spec.checksum,
      "cellar" => spec.cellar,
    }
  end
end

#compatible_locations?(tag: Utils::Bottles.tag) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'bottle_specification.rb', line 54

def compatible_locations?(tag: Utils::Bottles.tag)
  cellar = tag_to_cellar(tag)

  return true if RELOCATABLE_CELLARS.include?(cellar)

  prefix = Pathname(cellar.to_s).parent.to_s

  cellar_relocatable = cellar.size >= HOMEBREW_CELLAR.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present?
  prefix_relocatable = prefix.size >= HOMEBREW_PREFIX.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present?

  compatible_cellar = cellar == HOMEBREW_CELLAR.to_s || cellar_relocatable
  compatible_prefix = prefix == HOMEBREW_PREFIX.to_s || prefix_relocatable

  compatible_cellar && compatible_prefix
end

#rebuild(arg = nil) ⇒ T.untyped

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • arg (T.untyped) (defaults to: nil)

Returns:

  • (T.untyped)


10
# File 'sorbet/rbi/dsl/bottle_specification.rbi', line 10

def rebuild(arg = nil); end

#root_url(var = nil, specs = {}) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'bottle_specification.rb', line 20

def root_url(var = nil, specs = {})
  if var.nil?
    @root_url ||= if (github_packages_url = GitHubPackages.root_url_if_match(Homebrew::EnvConfig.bottle_domain))
      github_packages_url
    else
      Homebrew::EnvConfig.bottle_domain
    end
  else
    @root_url = if (github_packages_url = GitHubPackages.root_url_if_match(var))
      github_packages_url
    else
      var
    end
    @root_url_specs.merge!(specs)
  end
end

#sha256(hash) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Checksum methods in the DSL's bottle block take a Hash, which indicates the platform the checksum applies on. Example bottle block syntax: bottle do sha256 cellar: :any_skip_relocation, big_sur: "69489ae397e4645..." sha256 cellar: :any, catalina: "449de5ea35d0e94..." end



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'bottle_specification.rb', line 89

def sha256(hash)
  sha256_regex = /^[a-f0-9]{64}$/i

  # find new `sha256 big_sur: "69489ae397e4645..."` format
  tag, digest = hash.find do |key, value|
    key.is_a?(Symbol) && value.is_a?(String) && value.match?(sha256_regex)
  end

  cellar = hash[:cellar] if digest && tag

  tag = Utils::Bottles::Tag.from_symbol(tag)

  cellar ||= tag.default_cellar

  collector.add(tag, checksum: Checksum.new(digest), cellar:)
end

#skip_relocation?(tag: Utils::Bottles.tag) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Does the Bottle this BottleSpecification belongs to need to be relocated?

Parameters:

Returns:

  • (Boolean)


6
7
8
# File 'extend/os/linux/bottle_specification.rb', line 6

def skip_relocation?(tag: Utils::Bottles.tag)
  false
end

#tag?(tag, no_older_versions: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


78
79
80
# File 'bottle_specification.rb', line 78

def tag?(tag, no_older_versions: false)
  collector.tag?(tag, no_older_versions:)
end

#tag_specification_for(tag, no_older_versions: false) ⇒ Utils::Bottles::TagSpecification?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



110
111
112
# File 'bottle_specification.rb', line 110

def tag_specification_for(tag, no_older_versions: false)
  collector.specification_for(tag, no_older_versions:)
end

#tag_to_cellar(tag = Utils::Bottles.tag) ⇒ Symbol, String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



44
45
46
47
48
49
50
51
# File 'bottle_specification.rb', line 44

def tag_to_cellar(tag = Utils::Bottles.tag)
  spec = collector.specification_for(tag)
  if spec.present?
    spec.cellar
  else
    tag.default_cellar
  end
end