Class: BottleSpecification

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
extend/os/linux/software_spec.rb,
software_spec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializevoid



451
452
453
454
455
456
457
# File 'software_spec.rb', line 451

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

Instance Attribute Details

#all_tags_cellarObject (readonly)

Returns the value of attribute all_tags_cellar.



448
449
450
# File 'software_spec.rb', line 448

def all_tags_cellar
  @all_tags_cellar
end

#collectorObject (readonly)

Returns the value of attribute collector.



448
449
450
# File 'software_spec.rb', line 448

def collector
  @collector
end

#prefixObject (readonly)

Returns the value of attribute prefix.



448
449
450
# File 'software_spec.rb', line 448

def prefix
  @prefix
end

#repositoryObject (readonly)

Returns the value of attribute repository.



448
449
450
# File 'software_spec.rb', line 448

def repository
  @repository
end

#root_url_specsObject (readonly)

Returns the value of attribute root_url_specs.



448
449
450
# File 'software_spec.rb', line 448

def root_url_specs
  @root_url_specs
end

#tapObject

Returns the value of attribute tap.



447
448
449
# File 'software_spec.rb', line 447

def tap
  @tap
end

Instance Method Details

#cellar(val = nil) ⇒ Object



476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'software_spec.rb', line 476

def cellar(val = nil)
  if val.present?
    odeprecated(
      "`cellar` in a bottle block",
      "`brew style --fix` on the formula to update the style or use `sha256` with a `cellar:` argument",
    )
  end

  if val.nil?
    return collector.dig(Utils::Bottles.tag.to_sym, :cellar) || @all_tags_cellar || Homebrew::DEFAULT_CELLAR
  end

  @all_tags_cellar = val
end

#checksum_for(tag, no_older_versions: false) ⇒ Array(Checksum, Symbol, Symbol, String)?

Parameters:

Returns:



562
563
564
# File 'software_spec.rb', line 562

def checksum_for(tag, no_older_versions: false)
  collector.fetch_checksum_for(tag, no_older_versions: no_older_versions)
end

#checksumsObject



566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'software_spec.rb', line 566

def checksums
  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 = tag.arch == :arm64 ? "2" : "1"
    "#{priority}.#{version}_#{sym}"
  rescue MacOSVersionError
    # Sort non-MacOS tags below MacOS tags.
    "0.#{sym}"
  end
  tags.reverse.map do |tag|
    {
      "tag"    => tag,
      "digest" => collector[tag][:checksum],
      "cellar" => collector[tag][:cellar],
    }
  end
end

#compatible_locations?Boolean

Returns:

  • (Boolean)


491
492
493
494
495
496
497
498
499
500
501
# File 'software_spec.rb', line 491

def compatible_locations?
  # this looks like it should check prefix and repository too but to be
  # `cellar :any` actually requires no references to the cellar, prefix or
  # repository.
  return true if [:any, :any_skip_relocation].include?(cellar)

  compatible_cellar = cellar == HOMEBREW_CELLAR.to_s
  compatible_prefix = prefix == HOMEBREW_PREFIX.to_s

  compatible_cellar && compatible_prefix
end

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



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'software_spec.rb', line 459

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

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



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'software_spec.rb', line 521

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

  if digest && tag
    # the cellar hash key only exists on the new format
    cellar = hash[:cellar]
  else
    # otherwise, find old `sha256 "69489ae397e4645..." => :big_sur` format
    digest, tag = hash.find do |key, value|
      key.is_a?(String) && value.is_a?(Symbol) && key.match?(sha256_regex)
    end

    if digest && tag
      odeprecated(
        '`sha256 "digest" => :tag` in a bottle block',
        '`brew style --fix` on the formula to update the style or use `sha256 tag: "digest"`',
      )
    end
  end

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

  cellar ||= all_tags_cellar
  cellar ||= tag.default_cellar

  collector[tag.to_sym] = { checksum: Checksum.new(digest), cellar: cellar }
end

#skip_relocation?Boolean

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

Returns:

  • (Boolean)


7
8
9
# File 'extend/os/linux/software_spec.rb', line 7

def skip_relocation?
  false
end

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

Parameters:

Returns:

  • (Boolean)


510
511
512
# File 'software_spec.rb', line 510

def tag?(tag, no_older_versions: false)
  checksum_for(tag, no_older_versions: no_older_versions) ? true : false
end