-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Use a dummy toolchain context for rules that don't have one. #13162
Conversation
@@ -2034,6 +2034,35 @@ EOF | |||
expect_not_log "does not provide ToolchainTypeInfo" | |||
} | |||
|
|||
function test_toolchain_from_no_toolchain_rule() { | |||
# Create a build_setting that tries to load a toolchain. | |||
# build_settings cnanot actually have toolchains because they |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed entirely.
cat >> demo/rule.bzl <<EOF | ||
def _sample_impl(ctx): | ||
info = ctx.toolchains["//:toolchain_type"] | ||
if info: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if info != None:
? To distinguish from other false-y values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the unit test.
@@ -2034,6 +2034,35 @@ EOF | |||
expect_not_log "does not provide ToolchainTypeInfo" | |||
} | |||
|
|||
function test_toolchain_from_no_toolchain_rule() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of testing this at both the unit test and shell test levels?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I wrote this first then added the other to debug, but we only need one. Removed the shell test.
// Starlark rules are easier if this cannot be null, so return a no-op value instead. | ||
return new ToolchainContextApi() { | ||
@Override | ||
public Object getIndex(StarlarkSemantics semantics, Object key) throws EvalException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: You can omit the throws declaration since this override doesn't throw. Same below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
ResolvedToolchainContext toolchainContext = ruleContext.getToolchainContext(); | ||
if (toolchainContext == null) { | ||
// Starlark rules are easier if this cannot be null, so return a no-op value instead. | ||
return new ToolchainContextApi() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optionally make this a singleton, but I doubt it'll matter much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's enough benefit, this is fairly clear.
Fixes bazelbuild#12610. Closes bazelbuild#13162. PiperOrigin-RevId: 361545255
Fixes #12610.