From b9fc4e36f037faa1b088b696d16c26aa4627a6cb Mon Sep 17 00:00:00 2001 From: FnControlOption <70830482+FnControlOption@users.noreply.github.com> Date: Thu, 26 Aug 2021 14:36:49 -0700 Subject: [PATCH 1/2] fetch: fix --bottle-tag when unbottled on host system --- Library/Homebrew/cli/args.rbi | 3 +++ Library/Homebrew/extend/os/mac/utils/bottles.rb | 4 +++- Library/Homebrew/fetch.rb | 1 + Library/Homebrew/formula.rb | 2 +- Library/Homebrew/formula.rbi | 4 ++-- Library/Homebrew/software_spec.rb | 17 ++++++----------- Library/Homebrew/utils/bottles.rb | 4 +++- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/cli/args.rbi b/Library/Homebrew/cli/args.rbi index 11e2138733..80e172e8d8 100644 --- a/Library/Homebrew/cli/args.rbi +++ b/Library/Homebrew/cli/args.rbi @@ -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 diff --git a/Library/Homebrew/extend/os/mac/utils/bottles.rb b/Library/Homebrew/extend/os/mac/utils/bottles.rb index ce0415dfbe..6701e886e4 100644 --- a/Library/Homebrew/extend/os/mac/utils/bottles.rb +++ b/Library/Homebrew/extend/os/mac/utils/bottles.rb @@ -6,7 +6,9 @@ module Utils 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 diff --git a/Library/Homebrew/fetch.rb b/Library/Homebrew/fetch.rb index 70648d528a..ea44555561 100644 --- a/Library/Homebrew/fetch.rb +++ b/Library/Homebrew/fetch.rb @@ -11,6 +11,7 @@ module Homebrew 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? && diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index f55ca41444..9d3d3182aa 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -373,7 +373,7 @@ class Formula # @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. diff --git a/Library/Homebrew/formula.rbi b/Library/Homebrew/formula.rbi index 360ab51722..4df0cd60b5 100644 --- a/Library/Homebrew/formula.rbi +++ b/Library/Homebrew/formula.rbi @@ -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 diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 0147c2e0d7..7312097d3a 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -93,13 +93,13 @@ class SoftwareSpec !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) @@ -306,12 +306,7 @@ class Bottle @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 diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 0ee920ea32..ad121c6151 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -11,7 +11,9 @@ module Utils 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 From 794510f4e0e45f3504fdbda70ca989d8579968be Mon Sep 17 00:00:00 2001 From: FnControlOption <70830482+FnControlOption@users.noreply.github.com> Date: Thu, 26 Aug 2021 14:37:27 -0700 Subject: [PATCH 2/2] cmd/cache: add --bottle-tag flag --- Library/Homebrew/cmd/--cache.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/--cache.rb b/Library/Homebrew/cmd/--cache.rb index 2e945cf877..0620411636 100644 --- a/Library/Homebrew/cmd/--cache.rb +++ b/Library/Homebrew/cmd/--cache.rb @@ -24,6 +24,8 @@ module Homebrew 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", @@ -31,7 +33,7 @@ module Homebrew 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] @@ -61,7 +63,7 @@ module Homebrew 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