-
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
Add --compilation_mode support in transitions #11347
Conversation
I would look at the tests in src/test/j.c.g/devtools/build/lib to find examples of how we test for this. @alandonovan You had comments in #10690 |
I think StarlarkAttrTransitionProviderTest would be a good place to write a test where the set up would be a transition that transitions on //command_line_option:compilation_mode and asserts that the transitioned value is as expected. A thorough test would also read //command_line_option:compilation_mode to make sure that's working as well. Here's a specific test case that is somewhat close to that (no need to make it a split transition) https://cs.opensource.google/bazel/bazel/+/master:src/test/java/com/google/devtools/build/lib/analysis/StarlarkAttrTransitionProviderTest.java;l=120 Could also add a similar e2e test here if you're interested: https://cs.opensource.google/bazel/bazel/+/master:src/test/shell/integration/starlark_configurations_test.sh?q=starlark_configurations_test.sh%20&ss=bazel |
The broader issue here has come up in conversation before where our current Starlark-Java interface for these commandline options in transitions easily allows Java objects without a well-defined Starlark API to leak into the Starlark interpreter context. I'm hesitant to approve piecemeal fixes since they could interfere with future broad fixes. The (rough and currently not being worked on) plan for this is to add another interface that options parsing Converters can inherit, tentatively called StarlarkConvert. It would contain toStarlark (T -> Object) and fromStarlark (Object -> T) methods. The transitions infrastructure would be amended to use these methods when passing values to and from Starlark code (options not inheriting that interface cannot be used in transitions). There are a bunch of commonly used Converters that, if amended, would immediately apply the feature to a majority of options. |
c101423
to
d97af80
Compare
Rebased and added a test. I agree with @sdtwigg that a broader solution would be welcome, but the time plan for it is unfortunately suffering. In this PR, I only address |
@moroten which cache miss scenarios are you trying to address? |
The cache miss scenario is when building the following:
The Annoyingly, the analysis cache is discarded between these commands so checking for cache hits remotely takes some time (see #10875). Running both steps in a single command is not possible due to the |
By enabling |
I see, thanks. @sdtwigg would this PR actually interfere with a broader solution? As ad hoc changes go it's not terribly hackish, and I don't see this opening floodgate exceptions for all the other options. If it's this vs. nothing maybe it's worthwhile. |
After the weekend mental refresh, I am less concerned that this would interfere with the broader solution. That said, can you add a TODO (you can link back to this bug or specifically my comment before) that other places should strongly avoid replicating this fix and look in to implementing the proper fix for other desired flags. |
What's the state of this PR? |
d97af80
to
71d4ed0
Compare
I am sorry I missed @sdtwigg's last comment. I have now added the missing TODO in the code. |
@@ -514,6 +514,92 @@ public void testOptionConversionCpu() throws Exception { | |||
assertThat(getConfiguration(Iterables.getOnlyElement(dep)).getCpu()).isEqualTo("armeabi-v7a"); | |||
} | |||
|
|||
private void writeReadAndPassthroughOptionsTestFiles() throws Exception { | |||
setStarlarkSemanticsOptions("--experimental_starlark_config_transitions=true"); | |||
writeWhitelistFile(); |
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 think this line specifically out of date. Need to amend this so the tests still pass and I can import this into Bazel.
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've rebased and letting Buildkite run the tests.
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.
Thanks for rebasing, Fredrik. @sdtwigg ready to merge?
71d4ed0
to
3d13709
Compare
Add support for converting //command_line_option:compilation_mode from Java value to Starlark value so that it can be read in a transition. Implementing StarlarkValue is a workaround until a well-defined Java-Starlark conversion interface has been created. See also bazelbuild#11347 (comment) Avoid replicating this workaround. Fixes --compilation_mode in bazelbuild#10690, but not the general case.
Add support for converting //command_line_option:compilation_mode from Java value to Starlark value so that it can be read in a transition. Implementing StarlarkValue is a workaround until a well-defined Java-Starlark conversion interface has been created. See also bazelbuild#11347 (comment) Avoid replicating this workaround. Fixes --compilation_mode in bazelbuild#10690, but not the general case.
3d13709
to
9b4675b
Compare
Add support for converting //command_line_option:compilation_mode from Java value to Starlark value so that it can be read in a transition. Fixes --compilation_mode in bazelbuild#10690, but not the general case. This patch does not contain any tests. What kind of test is expected and where should it be implemented? Closes bazelbuild#11347. PiperOrigin-RevId: 333249729
Add support for converting //command_line_option:compilation_mode from
Java value to Starlark value so that it can be read in a transition.
Fixes --compilation_mode in #10690, but not the general case.
This patch does not contain any tests. What kind of test is expected and where should it be implemented?