diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 18549c48a0..1a9b2d1bde 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -85,9 +85,9 @@ module Cask # An old name for the cask. sig { returns(T::Array[String]) } def old_tokens - @old_tokens ||= if tap - tap.cask_renames - .flat_map { |old_token, new_token| (new_token == token) ? old_token : [] } + @old_tokens ||= if (tap = self.tap) + Tap.reverse_tap_migrations_renames.fetch("#{tap}/#{token}", []) + + tap.reverse_cask_renames.fetch(token, []) else [] end diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index 76eae2ee52..1a3cd08ec3 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -522,23 +522,23 @@ module Cask type = nil if (new_token = tap.cask_renames[token].presence) - old_token = token + old_token = tap.core_cask_tap? ? token : tapped_token token = new_token new_token = tap.core_cask_tap? ? token : "#{tap}/#{token}" type = :rename elsif (new_tap_name = tap.tap_migrations[token].presence) - new_tap_user, new_tap_repo, = new_tap_name.split("/") - new_tap_name = "#{new_tap_user}/#{new_tap_repo}" - new_tap = Tap.fetch(new_tap_name) + new_tap_user, new_tap_repo, new_token = new_tap_name.split("/", 3) + new_token ||= token + new_tap = Tap.fetch(new_tap_user, new_tap_repo) new_tap.ensure_installed! - new_tapped_token = "#{new_tap_name}/#{token}" + new_tapped_token = "#{new_tap}/#{new_token}" if tapped_token == new_tapped_token opoo "Tap migration for #{tapped_token} points to itself, stopping recursion." else + old_token = tap.core_cask_tap? ? token : tapped_token token, tap, = tap_cask_token_type(new_tapped_token, warn: false) - old_token = tapped_token - new_token = new_tap.core_cask_tap? ? token : new_tapped_token + new_token = new_tap.core_cask_tap? ? token : "#{tap}/#{token}" type = :migration end end diff --git a/Library/Homebrew/cask/caskroom.rb b/Library/Homebrew/cask/caskroom.rb index 272685dc59..43abdfcd1f 100644 --- a/Library/Homebrew/cask/caskroom.rb +++ b/Library/Homebrew/cask/caskroom.rb @@ -53,7 +53,7 @@ module Cask sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) } def self.casks(config: nil) tokens.sort.map do |token| - CaskLoader.load(token, config: config) + CaskLoader.load(token, config: config, warn: false) rescue TapCaskAmbiguityError tap_path = CaskLoader.tap_paths(token).first CaskLoader::FromPathLoader.new(tap_path).load(config: config) diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index dcf8e7a18a..1a7469e8c8 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -129,16 +129,16 @@ class Caveats Bash completion has been installed to: #{root_dir}/etc/bash_completion.d EOS - when :zsh - <<~EOS - zsh #{installed.join(" and ")} have been installed to: - #{root_dir}/share/zsh/site-functions - EOS when :fish fish_caveats = +"fish #{installed.join(" and ")} have been installed to:" fish_caveats << "\n #{root_dir}/share/fish/vendor_completions.d" if completion_installed fish_caveats << "\n #{root_dir}/share/fish/vendor_functions.d" if functions_installed fish_caveats.freeze + when :zsh + <<~EOS + zsh #{installed.join(" and ")} have been installed to: + #{root_dir}/share/zsh/site-functions + EOS end end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 3cce9ccb3f..f5a60ca97f 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -540,7 +540,12 @@ class Formula # Old names for the formula. sig { returns(T::Array[String]) } def oldnames - @oldnames ||= tap&.formula_oldnames&.dig(name) || [] + @oldnames ||= if (tap = self.tap) + Tap.reverse_tap_migrations_renames.fetch("#{tap}/#{name}", []) + + tap.formula_reverse_renames.fetch(name, []) + else + [] + end end # All aliases for the formula. diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 13dccfb851..74ba8e75a4 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -904,7 +904,7 @@ module Formulary def self.tap_formula_name_type(tapped_name, warn:) user, repo, name = tapped_name.split("/", 3).map(&:downcase) - tap = Tap.fetch user, repo + tap = Tap.fetch(user, repo) type = nil alias_name = tap.core_tap? ? name : "#{tap}/#{name}" @@ -912,23 +912,23 @@ module Formulary name = possible_alias.split("/").last type = :alias elsif (new_name = tap.formula_renames[name].presence) - old_name = name + old_name = tap.core_tap? ? name : tapped_name name = new_name new_name = tap.core_tap? ? name : "#{tap}/#{name}" type = :rename elsif (new_tap_name = tap.tap_migrations[name].presence) - new_tap_user, new_tap_repo, = new_tap_name.split("/") - new_tap_name = "#{new_tap_user}/#{new_tap_repo}" - new_tap = Tap.fetch new_tap_name + new_tap_user, new_tap_repo, new_name = new_tap_name.split("/", 3) + new_name ||= name + new_tap = Tap.fetch(new_tap_user, new_tap_repo) new_tap.ensure_installed! - new_tapped_name = "#{new_tap_name}/#{name}" + new_tapped_name = "#{new_tap}/#{new_name}" if tapped_name == new_tapped_name opoo "Tap migration for #{tapped_name} points to itself, stopping recursion." else + old_name = tap.core_tap? ? name : tapped_name name, tap, = tap_formula_name_type(new_tapped_name, warn: false) - old_name = tapped_name - new_name = new_tap.core_tap? ? name : new_tapped_name + new_name = new_tap.core_tap? ? name : "#{tap}/#{name}" type = :migration end end diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 5a5453bac8..5b5d25e8fc 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -335,10 +335,10 @@ class Keg def completion_installed?(shell) dir = case shell when :bash then path/"etc/bash_completion.d" + when :fish then path/"share/fish/vendor_completions.d" when :zsh dir = path/"share/zsh/site-functions" dir if dir.directory? && dir.children.any? { |f| f.basename.to_s.start_with?("_") } - when :fish then path/"share/fish/vendor_completions.d" end dir&.directory? && !dir.children.empty? end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 962b3566ab..f3d86c3649 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -758,6 +758,15 @@ class Tap end end + # Hash with tap formula old names. Reverse of {#formula_renames}. + sig { returns(T::Hash[String, T::Array[String]]) } + def reverse_cask_renames + @reverse_cask_renames ||= cask_renames.each_with_object({}) do |(old_name, new_name), hash| + hash[new_name] ||= [] + hash[new_name] << old_name + end + end + # Hash with tap formula renames. sig { returns(T::Hash[String, String]) } def formula_renames @@ -770,15 +779,30 @@ class Tap # Hash with tap formula old names. Reverse of {#formula_renames}. sig { returns(T::Hash[String, T::Array[String]]) } - def formula_oldnames - @formula_oldnames ||= formula_renames.each_with_object({}) do |(old_name, new_name), hash| + def formula_reverse_renames + @formula_reverse_renames ||= formula_renames.each_with_object({}) do |(old_name, new_name), hash| hash[new_name] ||= [] hash[new_name] << old_name end end + sig { returns(T::Hash[String, T::Array[String]]) } + def self.reverse_tap_migrations_renames + Tap.each_with_object({}) do |tap, hash| + tap.tap_migrations.each do |old_name, new_name| + new_tap_user, new_tap_repo, new_name = new_name.split("/", 3) + next unless new_name + + new_tap = Tap.fetch(new_tap_user, new_tap_repo) + + hash["#{new_tap}/#{new_name}"] ||= [] + hash["#{new_tap}/#{new_name}"] << old_name + end + end + end + # Hash with tap migrations. - sig { returns(Hash) } + sig { returns(T::Hash[String, String]) } def tap_migrations @tap_migrations ||= if (migration_file = path/HOMEBREW_TAP_MIGRATIONS_FILE).file? JSON.parse(migration_file.read) diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index ad493a6c37..3a8ce307db 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -301,28 +301,34 @@ describe Caveats do let(:caveats) { described_class.new(f).caveats } let(:path) { f.prefix.resolved_path } + let(:bash_completion_dir) { path/"etc/bash_completion.d" } + let(:fish_vendor_completions) { path/"share/fish/vendor_completions.d" } + let(:zsh_site_functions) { path/"share/zsh/site-functions" } + before do # don't try to load/fetch gcc/glibc allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false) - allow_any_instance_of(Pathname).to receive(:children).and_return([Pathname.new("child")]) allow_any_instance_of(Object).to receive(:which).with(any_args).and_return(Pathname.new("shell")) allow(Utils::Shell).to receive_messages(preferred: nil, parent: nil) end - it "gives dir where Bash completions have been installed" do - (path/"etc/bash_completion.d").mkpath + it "includes where Bash completions have been installed to" do + bash_completion_dir.mkpath + FileUtils.touch bash_completion_dir/f.name expect(caveats).to include(HOMEBREW_PREFIX/"etc/bash_completion.d") end - it "gives dir where zsh completions have been installed" do - (path/"share/zsh/site-functions").mkpath - expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions") + it "includes where fish completions have been installed to" do + fish_vendor_completions.mkpath + FileUtils.touch fish_vendor_completions/f.name + expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d") end - it "gives dir where fish completions have been installed" do - (path/"share/fish/vendor_completions.d").mkpath - expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d") + it "includes where zsh completions have been installed to" do + zsh_site_functions.mkpath + FileUtils.touch zsh_site_functions/f.name + expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions") end end end diff --git a/Library/Homebrew/test/support/helper/cask.rb b/Library/Homebrew/test/support/helper/cask.rb index 8f14f52649..fa5ee7a65b 100644 --- a/Library/Homebrew/test/support/helper/cask.rb +++ b/Library/Homebrew/test/support/helper/cask.rb @@ -8,8 +8,8 @@ module Test def stub_cask_loader(cask, ref = cask.token, call_original: false) allow(::Cask::CaskLoader).to receive(:for).and_call_original if call_original - loader = ::Cask::CaskLoader::FromInstanceLoader.new cask - allow(::Cask::CaskLoader).to receive(:for).with(ref, warn: true).and_return(loader) + loader = ::Cask::CaskLoader::FromInstanceLoader.new(cask) + allow(::Cask::CaskLoader).to receive(:for).with(ref, any_args).and_return(loader) end end end