Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: fix --bottle-tag when unbottled on host system #11927

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Library/Homebrew/cli/args.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ module Homebrew
sig { returns(T::Boolean) }
def minor?; end

sig { returns(T.nilable(String)) }
def bottle_tag; end

sig { returns(T.nilable(String)) }
def tag; end

Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/cmd/--cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ def __cache_args
description: "Show the cache file used when building from source."
switch "--force-bottle",
description: "Show the cache file used when pouring a bottle."
flag "--bottle-tag",
description: "Show the cache file used when pouring a bottle for the given tag."
switch "--HEAD",
description: "Show the cache file used when building from HEAD."
switch "--formula",
description: "Only show cache files for formulae."
switch "--cask",
description: "Only show cache files for casks."

conflicts "--build-from-source", "--force-bottle", "--HEAD", "--cask"
conflicts "--build-from-source", "--force-bottle", "--bottle-tag", "--HEAD", "--cask"
conflicts "--formula", "--cask"

named_args [:formula, :cask]
Expand Down Expand Up @@ -61,7 +63,7 @@ def __cache
sig { params(formula: Formula, args: CLI::Args).void }
def print_formula_cache(formula, args:)
if fetch_bottle?(formula, args: args)
puts formula.bottle.cached_download
puts formula.bottle_for_tag(args.bottle_tag).cached_download
elsif args.HEAD?
puts formula.head.cached_download
else
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/extend/os/mac/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module Bottles
class << self
undef tag

def tag
def tag(symbol = nil)
return Utils::Bottles::Tag.from_symbol(symbol) if symbol.present?

Utils::Bottles::Tag.new(system: MacOS.version.to_sym, arch: Hardware::CPU.arch)
end
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def fetch_bottle?(f, args:)
bottle = f.bottle

return true if args.force_bottle? && bottle.present?
return true if args.bottle_tag.present? && f.bottled?(args.bottle_tag)

bottle.present? &&
f.pour_bottle? &&
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def bottle
# @private
sig { params(tag: T.nilable(String)).returns(T.nilable(Bottle)) }
def bottle_for_tag(tag = nil)
Bottle.new(self, bottle_specification, tag) if bottled?
Bottle.new(self, bottle_specification, tag) if bottled?(tag)
end

# The description of the software.
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/formula.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Formula
def bottle_disabled?; end
def bottle_disable_reason; end
def bottle_defined?; end
def bottle_tag?; end
def bottled?; end
def bottle_tag?(tag = nil); end
def bottled?(tag = nil); end
def bottle_specification; end
def downloader; end

Expand Down
17 changes: 6 additions & 11 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ def bottle_defined?
!bottle_specification.collector.keys.empty?
end

def bottle_tag?
bottle_specification.tag?(Utils::Bottles.tag)
def bottle_tag?(tag = nil)
bottle_specification.tag?(Utils::Bottles.tag(tag))
end

def bottled?
bottle_tag? && \
(bottle_specification.compatible_locations? || owner.force_bottle)
def bottled?(tag = nil)
bottle_tag?(tag) && \
(tag.present? || bottle_specification.compatible_locations? || owner.force_bottle)
end

def bottle(disable_type = nil, disable_reason = nil, &block)
Expand Down Expand Up @@ -306,12 +306,7 @@ def initialize(formula, spec, tag = nil)
@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)
checksum, tag, cellar = spec.checksum_for(Utils::Bottles.tag(tag))

@prefix = spec.prefix
@tag = tag
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module Bottles
class << self
extend T::Sig

def tag
def tag(symbol = nil)
return Tag.from_symbol(symbol) if symbol.present?

@tag ||= Tag.new(system: T.must(ENV["HOMEBREW_SYSTEM"]).downcase.to_sym,
arch: T.must(ENV["HOMEBREW_PROCESSOR"]).downcase.to_sym)
end
Expand Down