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



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

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.



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

def all_tags_cellar
  @all_tags_cellar
end

#collectorObject (readonly)

Returns the value of attribute collector.



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

def collector
  @collector
end

#prefixObject (readonly)

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

#repositoryObject (readonly)

Returns the value of attribute repository.



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

def repository
  @repository
end

#root_url_specsObject (readonly)

Returns the value of attribute root_url_specs.



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

def root_url_specs
  @root_url_specs
end

#tapObject

Returns the value of attribute tap.



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

def tap
  @tap
end

Instance Method Details

#cellar(val = nil) ⇒ Object



471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'software_spec.rb', line 471

def cellar(val = nil)
  if val.present?
    odisabled(
      "`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:



557
558
559
# File 'software_spec.rb', line 557

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

#checksumsObject



561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'software_spec.rb', line 561

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)


486
487
488
489
490
491
492
493
494
495
496
# File 'software_spec.rb', line 486

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



458
459
460
461
462
463
464
465
466
467
468
469
# File 'software_spec.rb', line 458

def root_url(var = nil, specs = {})
  if var.nil?
    @root_url ||= HOMEBREW_BOTTLE_DEFAULT_DOMAIN
  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



516
517
518
519
520
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
# File 'software_spec.rb', line 516

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
      odisabled(
        '`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)


505
506
507
# File 'software_spec.rb', line 505

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