Class: Homebrew::DevCmd::Bottle Private

Inherits:
AbstractCommand show all
Includes:
FileUtils
Defined in:
extend/os/mac/dev-cmd/bottle.rb,
dev-cmd/bottle.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/bottle.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.

Defined Under Namespace

Classes: Args

Constant Summary collapse

BOTTLE_ERB =

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.

T.let(<<-EOS.freeze, String)
  bottle do
    <% if [HOMEBREW_BOTTLE_DEFAULT_DOMAIN.to_s,
     "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}/bottles"].exclude?(root_url) %>
    root_url "<%= root_url %>"<% if root_url_using.present? %>,
using: <%= root_url_using %>
    <% end %>
    <% end %>
    <% if rebuild.positive? %>
    rebuild <%= rebuild %>
    <% end %>
    <% sha256_lines.each do |line| %>
    <%= line %>
    <% end %>
  end
EOS
MAXIMUM_STRING_MATCHES =

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.

100
T.let([
  %r{#{Regexp.escape(HOMEBREW_LIBRARY)}/Homebrew/os/(mac|linux)/pkgconfig},
].freeze, T::Array[Regexp])

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, #raise_sh_command_error!

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::DevCmd::Bottle::Args

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
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/bottle.rbi', line 10

def args; end

#bottle_output(bottle, root_url_using) ⇒ 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:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'dev-cmd/bottle.rb', line 134

def bottle_output(bottle, root_url_using)
  cellars = bottle.checksums.filter_map do |checksum|
    cellar = checksum["cellar"]
    next unless cellar_parameter_needed? cellar

    case cellar
    when String
      %Q("#{cellar}")
    when Symbol
      ":#{cellar}"
    end
  end
  tag_column = cellars.empty? ? 0 : "cellar: #{cellars.max_by(&:length)}, ".length

  tags = bottle.checksums.map { |checksum| checksum["tag"] }
  # Start where the tag ends, add the max length of the tag, add two for the `: `
  digest_column = tag_column + tags.max_by(&:length).length + 2

  sha256_lines = bottle.checksums.map do |checksum|
    generate_sha256_line(checksum["tag"], checksum["digest"], checksum["cellar"], tag_column, digest_column)
  end
  erb_binding = bottle.instance_eval { binding }
  erb_binding.local_variable_set(:sha256_lines, sha256_lines)
  erb_binding.local_variable_set(:root_url_using, root_url_using)
  erb = ERB.new BOTTLE_ERB
  erb.result(erb_binding).gsub(/^\s*$\n/, "")
end

#generate_sha256_line(tag, digest, cellar, tag_column, digest_column) ⇒ 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:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'dev-cmd/bottle.rb', line 118

def generate_sha256_line(tag, digest, cellar, tag_column, digest_column)
  line = "sha256 "
  tag_column += line.length
  digest_column += line.length
  if cellar.is_a?(Symbol)
    line += "cellar: :#{cellar},"
  elsif cellar_parameter_needed?(cellar)
    line += %Q(cellar: "#{cellar}",)
  end
  line += " " * (tag_column - line.length)
  line += "#{tag}:"
  line += " " * (digest_column - line.length)
  %Q(#{line}"#{digest}")
end

#gnu_tar(gnu_tar_formula) ⇒ 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:



21
22
23
# File 'extend/os/mac/dev-cmd/bottle.rb', line 21

def gnu_tar(gnu_tar_formula)
  "#{gnu_tar_formula.opt_bin}/gtar"
end

#merge_bottle_spec(old_keys, old_bottle_spec, new_bottle_hash) ⇒ Array<Array<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:



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'dev-cmd/bottle.rb', line 187

def merge_bottle_spec(old_keys, old_bottle_spec, new_bottle_hash)
  mismatches = []
  checksums = []

  new_values = {
    root_url: new_bottle_hash["root_url"],
    rebuild:  new_bottle_hash["rebuild"],
  }

  skip_keys = [:sha256, :cellar]
  old_keys.each do |key|
    next if skip_keys.include?(key)

    old_value = old_bottle_spec.send(key).to_s
    new_value = new_values[key].to_s

    next if old_value.present? && new_value == old_value

    mismatches << "#{key}: old: #{old_value.inspect}, new: #{new_value.inspect}"
  end

  return [mismatches, checksums] if old_keys.exclude? :sha256

  old_bottle_spec.collector.each_tag do |tag|
    old_tag_spec = old_bottle_spec.collector.specification_for(tag)
    old_hexdigest = old_tag_spec.checksum.hexdigest
    old_cellar = old_tag_spec.cellar
    new_value = new_bottle_hash.dig("tags", tag.to_s)
    if new_value.present? && new_value["sha256"] != old_hexdigest
      mismatches << "sha256 #{tag}: old: #{old_hexdigest.inspect}, new: #{new_value["sha256"].inspect}"
    elsif new_value.present? && new_value["cellar"] != old_cellar.to_s
      mismatches << "cellar #{tag}: old: #{old_cellar.to_s.inspect}, new: #{new_value["cellar"].inspect}"
    else
      checksums << { cellar: old_cellar, tag.to_sym => old_hexdigest }
    end
  end

  [mismatches, checksums]
end

#merge_json_files(json_files) ⇒ Hash{String => 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:

Returns:



170
171
172
173
174
175
176
177
178
179
180
181
# File 'dev-cmd/bottle.rb', line 170

def merge_json_files(json_files)
  json_files.reduce({}) do |hash, json_file|
    json_file.each_value do |json_hash|
      json_bottle = json_hash["bottle"]
      cellar = json_bottle.delete("cellar")
      json_bottle["tags"].each_value do |json_platform|
        json_platform["cellar"] ||= cellar
      end
    end
    hash.deep_merge(json_file)
  end
end

#parse_json_files(filenames) ⇒ Array<Hash{String => 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:

Returns:



163
164
165
166
167
# File 'dev-cmd/bottle.rb', line 163

def parse_json_files(filenames)
  filenames.map do |filename|
    JSON.parse(File.read(filename))
  end
end

#runvoid

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.

This method returns an undefined value.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'dev-cmd/bottle.rb', line 99

def run
  if args.merge?
    Homebrew.install_bundler_gems!(groups: ["ast"])
    return merge
  end

  Homebrew.install_bundler_gems!(groups: ["bottle"])

  gnu_tar_formula_ensure_installed_if_needed!

  args.named.to_resolved_formulae(uniq: false).each do |formula|
    bottle_formula formula
  end
end

#tar_argsArray<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.

Returns:



10
11
12
13
14
15
16
# File 'extend/os/mac/dev-cmd/bottle.rb', line 10

def tar_args
  if MacOS.version >= :catalina
    ["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze
  else
    [].freeze
  end
end