Class: Bottle

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
software_spec.rb

Defined Under Namespace

Classes: Filename

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formula, spec, tag = nil) ⇒ Bottle

Returns a new instance of Bottle.



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'software_spec.rb', line 302

def initialize(formula, spec, tag = nil)
  @name = formula.name
  @resource = Resource.new
  @resource.owner = formula
  @resource.specs[:bottle] = true
  @spec = spec

  bottle_tag = if tag.present?
    Utils::Bottles::Tag.from_symbol(tag)
  else
    Utils::Bottles.tag
  end
  checksum, tag, cellar = spec.checksum_for(bottle_tag)

  @prefix = spec.prefix
  @tag = tag
  @cellar = cellar
  @rebuild = spec.rebuild

  @resource.version = formula.pkg_version
  @resource.checksum = checksum

  root_url(spec.root_url, spec.root_url_specs)
end

Instance Attribute Details

#cellarObject (readonly)

Returns the value of attribute cellar.



297
298
299
# File 'software_spec.rb', line 297

def cellar
  @cellar
end

#nameObject (readonly)

Returns the value of attribute name.



297
298
299
# File 'software_spec.rb', line 297

def name
  @name
end

#prefixObject (readonly)

Returns the value of attribute prefix.



297
298
299
# File 'software_spec.rb', line 297

def prefix
  @prefix
end

#rebuildObject (readonly)

Returns the value of attribute rebuild.



297
298
299
# File 'software_spec.rb', line 297

def rebuild
  @rebuild
end

#resourceObject (readonly)

Returns the value of attribute resource.



297
298
299
# File 'software_spec.rb', line 297

def resource
  @resource
end

Instance Method Details

#clear_cacheObject



327
328
329
330
# File 'software_spec.rb', line 327

def clear_cache
  @resource.clear_cache
  github_packages_manifest_resource&.clear_cache
end

#compatible_locations?Boolean

Returns:

  • (Boolean)


332
333
334
# File 'software_spec.rb', line 332

def compatible_locations?
  @spec.compatible_locations?
end

#fetch_tabObject



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'software_spec.rb', line 345

def fetch_tab
  return if github_packages_manifest_resource.blank?

  # a checksum is used later identifying the correct tab but we do not have the checksum for the manifest/tab
  github_packages_manifest_resource.fetch(verify_download_integrity: false)

  begin
    JSON.parse(github_packages_manifest_resource.cached_download.read)
  rescue JSON::ParserError
    raise DownloadError.new(
      github_packages_manifest_resource,
      RuntimeError.new("The downloaded GitHub Packages manifest was corrupted or modified (it is not valid JSON):"\
                       "\n#{github_packages_manifest_resource.cached_download}"),
    )
  end
rescue DownloadError
  raise unless fallback_on_error

  retry
end

#skip_relocation?Boolean

Does the bottle need to be relocated?

Returns:

  • (Boolean)


337
338
339
# File 'software_spec.rb', line 337

def skip_relocation?
  @spec.skip_relocation?
end

#stageObject



341
342
343
# File 'software_spec.rb', line 341

def stage
  resource.downloader.stage
end

#tab_attributesObject

Raises:

  • (ArgumentError)


366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'software_spec.rb', line 366

def tab_attributes
  return {} unless github_packages_manifest_resource&.downloaded?

  manifest_json = github_packages_manifest_resource.cached_download.read

  json = begin
    JSON.parse(manifest_json)
  rescue JSON::ParserError
    raise "The downloaded GitHub Packages manifest was corrupted or modified (it is not valid JSON): "\
          "\n#{github_packages_manifest_resource.cached_download}"
  end

  manifests = json["manifests"]
  raise ArgumentError, "Missing 'manifests' section." if manifests.blank?

  manifests_annotations = manifests.map { |m| m["annotations"] }
  raise ArgumentError, "Missing 'annotations' section." if manifests_annotations.blank?

  bottle_digest = @resource.checksum.hexdigest
  image_ref = GitHubPackages.version_rebuild(@resource.version, rebuild, @tag.to_s)
  manifest_annotations = manifests_annotations.find do |m|
    next if m["sh.brew.bottle.digest"] != bottle_digest

    m["org.opencontainers.image.ref.name"] == image_ref
  end
  raise ArgumentError, "Couldn't find manifest matching bottle checksum." if manifest_annotations.blank?

  tab = manifest_annotations["sh.brew.tab"]
  raise ArgumentError, "Couldn't find tab from manifest." if tab.blank?

  begin
    JSON.parse(tab)
  rescue JSON::ParserError
    raise ArgumentError, "Couldn't parse tab JSON."
  end
end