Remove FromDefaultNameLoader to avoid warning twice.
				
					
				
			This commit is contained in:
		
							parent
							
								
									76c7245d10
								
							
						
					
					
						commit
						a24da6b072
					
				@ -464,12 +464,19 @@ module Cask
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
      def self.try_new(ref, warn: false)
 | 
					      def self.try_new(ref, warn: false)
 | 
				
			||||||
        return unless ref.is_a?(String)
 | 
					        return unless ref.is_a?(String)
 | 
				
			||||||
        return if ref.include?("/")
 | 
					        return unless ref.match?(/\A#{HOMEBREW_TAP_CASK_TOKEN_REGEX}\Z/o)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        token = ref
 | 
					        token = ref
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        loaders = Tap.filter_map { |tap| super("#{tap}/#{token}", warn: warn) }
 | 
					        # If it exists in the default tap, never treat it as ambiguous with another tap.
 | 
				
			||||||
                     .select { _1.path.exist? }
 | 
					        if (core_cask_tap = CoreCaskTap.instance).installed? &&
 | 
				
			||||||
 | 
					           (loader= super("#{core_cask_tap}/#{token}", warn: warn))&.path&.exist?
 | 
				
			||||||
 | 
					          return loader
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        loaders = Tap.select { |tap| tap.installed? && !tap.core_cask_tap? }
 | 
				
			||||||
 | 
					                     .filter_map { |tap| super("#{tap}/#{token}", warn: warn) }
 | 
				
			||||||
 | 
					                     .select { |tap| tap.path.exist? }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        case loaders.count
 | 
					        case loaders.count
 | 
				
			||||||
        when 1
 | 
					        when 1
 | 
				
			||||||
@ -570,7 +577,6 @@ module Cask
 | 
				
			|||||||
        FromURILoader,
 | 
					        FromURILoader,
 | 
				
			||||||
        FromAPILoader,
 | 
					        FromAPILoader,
 | 
				
			||||||
        FromTapLoader,
 | 
					        FromTapLoader,
 | 
				
			||||||
        FromDefaultNameLoader,
 | 
					 | 
				
			||||||
        FromNameLoader,
 | 
					        FromNameLoader,
 | 
				
			||||||
        FromPathLoader,
 | 
					        FromPathLoader,
 | 
				
			||||||
        FromInstalledPathLoader,
 | 
					        FromInstalledPathLoader,
 | 
				
			||||||
 | 
				
			|||||||
@ -838,7 +838,6 @@ module Homebrew
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
          loadable = [
 | 
					          loadable = [
 | 
				
			||||||
            Formulary::FromAPILoader,
 | 
					            Formulary::FromAPILoader,
 | 
				
			||||||
            Formulary::FromDefaultNameLoader,
 | 
					 | 
				
			||||||
            Formulary::FromNameLoader,
 | 
					            Formulary::FromNameLoader,
 | 
				
			||||||
          ].any? do |loader_class|
 | 
					          ].any? do |loader_class|
 | 
				
			||||||
            loader = begin
 | 
					            loader = begin
 | 
				
			||||||
 | 
				
			|||||||
@ -765,22 +765,6 @@ module Formulary
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  class FromDefaultNameLoader < FromTapLoader
 | 
					 | 
				
			||||||
    sig {
 | 
					 | 
				
			||||||
      params(ref: T.any(String, Pathname, URI::Generic), from: Symbol, warn: T::Boolean)
 | 
					 | 
				
			||||||
        .returns(T.nilable(T.attached_class))
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    def self.try_new(ref, from: T.unsafe(nil), warn: false)
 | 
					 | 
				
			||||||
      return unless ref.is_a?(String)
 | 
					 | 
				
			||||||
      return unless (name = ref[HOMEBREW_DEFAULT_TAP_FORMULA_REGEX, :name])
 | 
					 | 
				
			||||||
      return unless (tap = CoreTap.instance).installed?
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      return unless (loader = super("#{tap}/#{name}", warn: warn))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      loader if loader.path.exist?
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  # Loads a formula from a name, as long as it exists only in a single tap.
 | 
					  # Loads a formula from a name, as long as it exists only in a single tap.
 | 
				
			||||||
  class FromNameLoader < FromTapLoader
 | 
					  class FromNameLoader < FromTapLoader
 | 
				
			||||||
    sig {
 | 
					    sig {
 | 
				
			||||||
@ -789,11 +773,19 @@ module Formulary
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    def self.try_new(ref, from: T.unsafe(nil), warn: false)
 | 
					    def self.try_new(ref, from: T.unsafe(nil), warn: false)
 | 
				
			||||||
      return unless ref.is_a?(String)
 | 
					      return unless ref.is_a?(String)
 | 
				
			||||||
      return if ref.include?("/")
 | 
					      return unless ref.match?(/\A#{HOMEBREW_TAP_FORMULA_NAME_REGEX}\Z/o)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      name = ref
 | 
					      name = ref
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      loaders = Tap.filter_map { |tap| super("#{tap}/#{name}", warn: warn) }.select { _1.path.exist? }
 | 
					      # If it exists in the default tap, never treat it as ambiguous with another tap.
 | 
				
			||||||
 | 
					      if (core_tap = CoreTap.instance).installed? &&
 | 
				
			||||||
 | 
					         (loader = super("#{core_tap}/#{name}", warn: warn))&.path&.exist?
 | 
				
			||||||
 | 
					        return loader
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      loaders = Tap.select { |tap| tap.installed? && !tap.core_tap? }
 | 
				
			||||||
 | 
					                   .filter_map { |tap| super("#{tap}/#{name}", warn: warn) }
 | 
				
			||||||
 | 
					                   .select { |tap| tap.path.exist? }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      case loaders.count
 | 
					      case loaders.count
 | 
				
			||||||
      when 1
 | 
					      when 1
 | 
				
			||||||
@ -1182,7 +1174,6 @@ module Formulary
 | 
				
			|||||||
      FromAPILoader,
 | 
					      FromAPILoader,
 | 
				
			||||||
      FromTapLoader,
 | 
					      FromTapLoader,
 | 
				
			||||||
      FromPathLoader,
 | 
					      FromPathLoader,
 | 
				
			||||||
      FromDefaultNameLoader,
 | 
					 | 
				
			||||||
      FromNameLoader,
 | 
					      FromNameLoader,
 | 
				
			||||||
      FromKegLoader,
 | 
					      FromKegLoader,
 | 
				
			||||||
      FromCacheLoader,
 | 
					      FromCacheLoader,
 | 
				
			||||||
 | 
				
			|||||||
@ -14,3 +14,4 @@ RSpec/ContextWording:
 | 
				
			|||||||
    - unless
 | 
					    - unless
 | 
				
			||||||
    - for
 | 
					    - for
 | 
				
			||||||
    - which
 | 
					    - which
 | 
				
			||||||
 | 
					    - to
 | 
				
			||||||
 | 
				
			|||||||
@ -72,52 +72,88 @@ RSpec.describe Cask::CaskLoader, :cask do
 | 
				
			|||||||
        ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
 | 
					        ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      context "when a cask is migrated to the default tap" do
 | 
					      context "when a cask is migrated" do
 | 
				
			||||||
        let(:token) { "local-caffeine" }
 | 
					        let(:token) { "local-caffeine" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let(:core_tap) { CoreTap.instance }
 | 
				
			||||||
 | 
					        let(:core_cask_tap) { CoreCaskTap.instance }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let(:tap_migrations) do
 | 
					        let(:tap_migrations) do
 | 
				
			||||||
          {
 | 
					          {
 | 
				
			||||||
            token => default_tap.name,
 | 
					            token => new_tap.name,
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
        let(:old_tap) { CoreTap.instance }
 | 
					 | 
				
			||||||
        let(:default_tap) { CoreCaskTap.instance }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        before do
 | 
					        before do
 | 
				
			||||||
 | 
					          old_tap.path.mkpath
 | 
				
			||||||
 | 
					          new_tap.path.mkpath
 | 
				
			||||||
          (old_tap.path/"tap_migrations.json").write tap_migrations.to_json
 | 
					          (old_tap.path/"tap_migrations.json").write tap_migrations.to_json
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it "does not warn when loading the short token" do
 | 
					        context "to a formula in the default tap" do
 | 
				
			||||||
          expect do
 | 
					          let(:old_tap) { core_cask_tap }
 | 
				
			||||||
            described_class.for(token)
 | 
					          let(:new_tap) { core_tap }
 | 
				
			||||||
          end.not_to output.to_stderr
 | 
					
 | 
				
			||||||
 | 
					          let(:formula_file) { new_tap.formula_dir/"#{token}.rb" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          before do
 | 
				
			||||||
 | 
					            new_tap.formula_dir.mkpath
 | 
				
			||||||
 | 
					            FileUtils.touch formula_file
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          it "warn only once" do
 | 
				
			||||||
 | 
					            expect do
 | 
				
			||||||
 | 
					              described_class.for(token)
 | 
				
			||||||
 | 
					            end.to output(
 | 
				
			||||||
 | 
					              a_string_including("Warning: Cask #{token} was renamed to #{new_tap}/#{token}.").once,
 | 
				
			||||||
 | 
					            ).to_stderr
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it "does not warn when loading the full token in the default tap" do
 | 
					        context "to the default tap" do
 | 
				
			||||||
          expect do
 | 
					          let(:old_tap) { core_tap }
 | 
				
			||||||
            described_class.for("#{default_tap}/#{token}")
 | 
					          let(:new_tap) { core_cask_tap }
 | 
				
			||||||
          end.not_to output.to_stderr
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it "warns when loading the full token in the old tap" do
 | 
					          let(:cask_file) { new_tap.cask_dir/"#{token}.rb" }
 | 
				
			||||||
          expect do
 | 
					 | 
				
			||||||
            described_class.for("#{old_tap}/#{token}")
 | 
					 | 
				
			||||||
          end.to output(%r{Cask #{old_tap}/#{token} was renamed to #{token}\.}).to_stderr
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # FIXME
 | 
					          before do
 | 
				
			||||||
        # context "when there is an infinite tap migration loop" do
 | 
					            new_tap.cask_dir.mkpath
 | 
				
			||||||
        #   before do
 | 
					            FileUtils.touch cask_file
 | 
				
			||||||
        #     (default_tap.path/"tap_migrations.json").write({
 | 
					          end
 | 
				
			||||||
        #       token => old_tap.name,
 | 
					
 | 
				
			||||||
        #     }.to_json)
 | 
					          it "does not warn when loading the short token" do
 | 
				
			||||||
        #   end
 | 
					            expect do
 | 
				
			||||||
        #
 | 
					              described_class.for(token)
 | 
				
			||||||
        #   it "stops recursing" do
 | 
					            end.not_to output.to_stderr
 | 
				
			||||||
        #     expect do
 | 
					          end
 | 
				
			||||||
        #       described_class.for("#{default_tap}/#{token}")
 | 
					
 | 
				
			||||||
        #     end.not_to output.to_stderr
 | 
					          it "does not warn when loading the full token in the default tap" do
 | 
				
			||||||
        #   end
 | 
					            expect do
 | 
				
			||||||
        # end
 | 
					              described_class.for("#{new_tap}/#{token}")
 | 
				
			||||||
 | 
					            end.not_to output.to_stderr
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          it "warns when loading the full token in the old tap" do
 | 
				
			||||||
 | 
					            expect do
 | 
				
			||||||
 | 
					              described_class.for("#{old_tap}/#{token}")
 | 
				
			||||||
 | 
					            end.to output(%r{Cask #{old_tap}/#{token} was renamed to #{token}\.}).to_stderr
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          # FIXME
 | 
				
			||||||
 | 
					          # context "when there is an infinite tap migration loop" do
 | 
				
			||||||
 | 
					          #   before do
 | 
				
			||||||
 | 
					          #     (new_tap.path/"tap_migrations.json").write({
 | 
				
			||||||
 | 
					          #       token => old_tap.name,
 | 
				
			||||||
 | 
					          #     }.to_json)
 | 
				
			||||||
 | 
					          #   end
 | 
				
			||||||
 | 
					          #
 | 
				
			||||||
 | 
					          #   it "stops recursing" do
 | 
				
			||||||
 | 
					          #     expect do
 | 
				
			||||||
 | 
					          #       described_class.for("#{new_tap}/#{token}")
 | 
				
			||||||
 | 
					          #     end.not_to output.to_stderr
 | 
				
			||||||
 | 
					          #   end
 | 
				
			||||||
 | 
					          # end
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
				
			|||||||
@ -556,54 +556,90 @@ RSpec.describe Formulary do
 | 
				
			|||||||
        ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
 | 
					        ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      context "when a formula is migrated to the default tap" do
 | 
					      context "when a formula is migrated" do
 | 
				
			||||||
        let(:token) { "foo" }
 | 
					        let(:token) { "foo" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let(:core_tap) { CoreTap.instance }
 | 
				
			||||||
 | 
					        let(:core_cask_tap) { CoreCaskTap.instance }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let(:tap_migrations) do
 | 
					        let(:tap_migrations) do
 | 
				
			||||||
          {
 | 
					          {
 | 
				
			||||||
            token => default_tap.name,
 | 
					            token => new_tap.name,
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
        let(:old_tap) { CoreCaskTap.instance }
 | 
					 | 
				
			||||||
        let(:default_tap) { CoreTap.instance }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        before do
 | 
					        before do
 | 
				
			||||||
          old_tap.path.mkpath
 | 
					          old_tap.path.mkpath
 | 
				
			||||||
 | 
					          new_tap.path.mkpath
 | 
				
			||||||
          (old_tap.path/"tap_migrations.json").write tap_migrations.to_json
 | 
					          (old_tap.path/"tap_migrations.json").write tap_migrations.to_json
 | 
				
			||||||
          FileUtils.touch default_tap.formula_dir/"foo.rb"
 | 
					 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it "does not warn when loading the short token" do
 | 
					        context "to a cask in the default tap" do
 | 
				
			||||||
          expect do
 | 
					          let(:old_tap) { core_tap }
 | 
				
			||||||
            described_class.loader_for(token)
 | 
					          let(:new_tap) { core_cask_tap }
 | 
				
			||||||
          end.not_to output.to_stderr
 | 
					
 | 
				
			||||||
 | 
					          let(:cask_file) { new_tap.cask_dir/"#{token}.rb" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          before do
 | 
				
			||||||
 | 
					            new_tap.cask_dir.mkpath
 | 
				
			||||||
 | 
					            FileUtils.touch cask_file
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          it "warn only once" do
 | 
				
			||||||
 | 
					            expect do
 | 
				
			||||||
 | 
					              described_class.loader_for(token)
 | 
				
			||||||
 | 
					            end.to output(
 | 
				
			||||||
 | 
					              a_string_including("Warning: Formula #{token} was renamed to #{new_tap}/#{token}.").once,
 | 
				
			||||||
 | 
					            ).to_stderr
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it "does not warn when loading the full token in the default tap" do
 | 
					        context "to the default tap" do
 | 
				
			||||||
          expect do
 | 
					          let(:old_tap) { core_cask_tap }
 | 
				
			||||||
            described_class.loader_for("#{default_tap}/#{token}")
 | 
					          let(:new_tap) { core_tap }
 | 
				
			||||||
          end.not_to output.to_stderr
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it "warns when loading the full token in the old tap" do
 | 
					          let(:formula_file) { new_tap.formula_dir/"#{token}.rb" }
 | 
				
			||||||
          expect do
 | 
					 | 
				
			||||||
            described_class.loader_for("#{old_tap}/#{token}")
 | 
					 | 
				
			||||||
          end.to output(%r{Formula #{old_tap}/#{token} was renamed to #{token}\.}).to_stderr
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # FIXME
 | 
					          before do
 | 
				
			||||||
        # context "when there is an infinite tap migration loop" do
 | 
					            new_tap.formula_dir.mkpath
 | 
				
			||||||
        #   before do
 | 
					            FileUtils.touch formula_file
 | 
				
			||||||
        #     (default_tap.path/"tap_migrations.json").write({
 | 
					          end
 | 
				
			||||||
        #       token => old_tap.name,
 | 
					
 | 
				
			||||||
        #     }.to_json)
 | 
					          it "does not warn when loading the short token" do
 | 
				
			||||||
        #   end
 | 
					            expect do
 | 
				
			||||||
        #
 | 
					              described_class.loader_for(token)
 | 
				
			||||||
        #   it "stops recursing" do
 | 
					            end.not_to output.to_stderr
 | 
				
			||||||
        #     expect do
 | 
					          end
 | 
				
			||||||
        #       described_class.loader_for("#{default_tap}/#{token}")
 | 
					
 | 
				
			||||||
        #     end.not_to output.to_stderr
 | 
					          it "does not warn when loading the full token in the default tap" do
 | 
				
			||||||
        #   end
 | 
					            expect do
 | 
				
			||||||
        # end
 | 
					              described_class.loader_for("#{new_tap}/#{token}")
 | 
				
			||||||
 | 
					            end.not_to output.to_stderr
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          it "warns when loading the full token in the old tap" do
 | 
				
			||||||
 | 
					            expect do
 | 
				
			||||||
 | 
					              described_class.loader_for("#{old_tap}/#{token}")
 | 
				
			||||||
 | 
					            end.to output(
 | 
				
			||||||
 | 
					              a_string_including("Formula #{old_tap}/#{token} was renamed to #{token}.").once,
 | 
				
			||||||
 | 
					            ).to_stderr
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          # FIXME
 | 
				
			||||||
 | 
					          # context "when there is an infinite tap migration loop" do
 | 
				
			||||||
 | 
					          #   before do
 | 
				
			||||||
 | 
					          #     (new_tap.path/"tap_migrations.json").write({
 | 
				
			||||||
 | 
					          #       token => old_tap.name,
 | 
				
			||||||
 | 
					          #     }.to_json)
 | 
				
			||||||
 | 
					          #   end
 | 
				
			||||||
 | 
					          #
 | 
				
			||||||
 | 
					          #   it "stops recursing" do
 | 
				
			||||||
 | 
					          #     expect do
 | 
				
			||||||
 | 
					          #       described_class.loader_for("#{new_tap}/#{token}")
 | 
				
			||||||
 | 
					          #     end.not_to output.to_stderr
 | 
				
			||||||
 | 
					          #   end
 | 
				
			||||||
 | 
					          # end
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user