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

Finalize methods that do not support overrides #16640

Merged
merged 2 commits into from
Feb 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions Library/Homebrew/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ def message
s
end

# Overriding {#satisfied?} is unsupported.
# Pass a block or boolean to the satisfy DSL method instead.
# Pass a block or boolean to the satisfy DSL method instead of overriding.
sig(:final) {
params(
env: T.nilable(String),
cc: T.nilable(String),
build_bottle: T::Boolean,
bottle_arch: T.nilable(String),
).returns(T::Boolean)
}
def satisfied?(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
satisfy = self.class.satisfy
return true unless satisfy
Expand All @@ -76,8 +83,8 @@ def satisfied?(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
true
end

# Overriding {#fatal?} is unsupported.
# Pass a boolean to the fatal DSL method instead.
# Pass a boolean to the fatal DSL method instead of overriding.
sig(:final) { returns(T::Boolean) }
def fatal?
self.class.fatal || false
end
Expand All @@ -92,8 +99,15 @@ def satisfied_result_parent
parent
end

# Overriding {#modify_build_environment} is unsupported.
# Pass a block to the env DSL method instead.
# Pass a block to the env DSL method instead of overriding.
sig(:final) {
params(
env: T.nilable(String),
cc: T.nilable(String),
build_bottle: T::Boolean,
bottle_arch: T.nilable(String),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params are based on https://github.com/Homebrew/brew/blob/master/Library/Homebrew/extend/ENV.rb#L36-L39 (though I noticed that build_bottle is T.nilable(T::Boolean) in some places)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think T::Boolean is preferable in most cases. We should adjust the call sites to avoid T.nilable(T::Boolean) being passed where this is still the case.

).void
}
def modify_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
satisfied?(env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
instance_eval(&env_proc) if env_proc
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/requirement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
let(:klass) { Class.new(described_class) }

it "returns nil" do
expect(requirement.modify_build_environment).to be_nil
expect { requirement.modify_build_environment }.not_to raise_error
end
end
end
Expand Down
Loading