diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 1a6214b47aae8..f82e9b4b2f18f 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -553,7 +553,17 @@ def synced_with_other_formulae? # ```ruby # resource("additional_files").stage { bin.install "my/extra/tool" } # ``` - delegate resource: :active_spec + # + # FIXME: This should not actually take a block. All resources should be defined + # at the top-level using {Formula.resource} instead + # (see https://github.com/Homebrew/brew/issues/17203#issuecomment-2093654431). + # + # @api public + sig { + params(name: String, klass: T.class_of(Resource), block: T.nilable(T.proc.bind(Resource).void)) + .returns(T.nilable(Resource)) + } + def resource(name, klass = Resource, &block) = active_spec.resource(name, klass, &block) # An old name for the formula. sig { returns(T.nilable(String)) } @@ -3710,6 +3720,7 @@ def head(val = nil, specs = {}, &block) # ``` # # @api public + sig { params(name: String, klass: T.class_of(Resource), block: T.nilable(T.proc.bind(Resource).void)).void } def resource(name, klass = Resource, &block) specs.each do |spec| spec.resource(name, klass, &block) unless spec.resource_defined?(name) diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index cc1d0a65d6add..400540d0565d1 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -123,6 +123,10 @@ def resource_defined?(name) resources.key?(name) end + sig { + params(name: String, klass: T.class_of(Resource), block: T.nilable(T.proc.bind(Resource).void)) + .returns(T.nilable(Resource)) + } def resource(name, klass = Resource, &block) if block raise DuplicateResourceError, name if resource_defined?(name) @@ -132,6 +136,7 @@ def resource(name, klass = Resource, &block) resources[name] = res dependency_collector.add(res) + res else resources.fetch(name) { raise ResourceMissingError.new(owner, name) } end diff --git a/Library/Homebrew/sorbet/rbi/parlour.rbi b/Library/Homebrew/sorbet/rbi/parlour.rbi index 57ef1b863ebc6..aee33eadc2d47 100644 --- a/Library/Homebrew/sorbet/rbi/parlour.rbi +++ b/Library/Homebrew/sorbet/rbi/parlour.rbi @@ -80,9 +80,6 @@ class Formula sig { params(args: T.untyped, options: T.untyped, block: T.untyped).returns(T::Boolean) } def loaded_from_api?(*args, **options, &block); end - sig { params(args: T.untyped, options: T.untyped, block: T.untyped).returns(T.untyped) } - def resource(*args, **options, &block); end - sig { params(args: T.untyped, options: T.untyped, block: T.untyped).returns(T.untyped) } def deps(*args, **options, &block); end