You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is not "a breaking change in theory" for us; it is an actual breaking change that may require significant work to fix. This should not be included in a point release, but rolled out with an --incompatible flag flipped in a major version. What's the motivation for slipping this incompatibility into 3.5.0?
For context: The motivation behind this change is to make prelude evaluation more consistent with regular bzl loading. Before this change, the (parsed) prelude contents were syntactically prepended to every BUILD file, sort of like a C-style #include directive. This meant that the prelude's AST was shared by all BUILD files, and therefore couldn't be statically processed in the usual way by the Starlark interpreter (specifically, to record variable scoping information for faster runtime evaluation). It also made BUILD file evaluation even more complex, compared to treating the prelude as just another (virtual) load dependency.
We need to assess the use cases and how difficult they are to migrate. So if you're broken, please chime in.
I also opened #11946 to discuss possibly eliminating the prelude file altogether.
To create universal targets in every package. In particular, we create syntax-checking test targets and some linters that we want in every package. These are macros that are loaded and called from the prelude, e.g.
def _test_impl(name, srcs):
if srcs:
native.sh_test(...)
def py_formatting_test():
_test_impl(name="py_formatting_test", srcs=native.glob(["*.py"])
This doesn't work if the prelude is handled as a regular bzl file, as the macros can't be called during load() ("The native module can be accessed only from a BUILD thread. Wrap the function in a macro and call it from a BUILD file"). So this would break with this change. Is there another way of supporting this kind of target creation?
Ah ha. Thanks Kevin. That is an interesting use case. We cope with that at Google by doing it metadata hooks at the source code repository level. Essentially, we set up the SCM so that we do the format test at PR pre-merge time, through non-bazel mechanisms. One obvious trade-off is that we have to maintain a more complex SCM than git, but we don't have to run (literally) millions of style checks in addition to the behavioral tests that our continuous testing pipeline is looking at.
@kevingessner Would it be acceptable for you to update the BUILD files and make them explicit?
i.e. add this line everywhere:
py_formatting_test()
With a presubmit check, you can enforce that the call is present. The load statement isn't required if you put the load in the prelude file.
I uderstand it's not ideal for you, but supporting your use-case causes some problems. Right now, this bug is blocking the next Bazel release. Anyone has an opinion on what's the way forward?
We could design a solution to support your use-case, but that would take time (and we need releases in the meantime).
Ah, I didn't realize. I was hoping this would be reverted and put behind a flag. I guess if you want to put this breaking change in 3.6, go ahead. I'll work around it when we upgrade.
Activity
aiuto commentedon Aug 13, 2020
@alandonovan Need to discuss backpatching a rollback to the release branch vs. hiding change behind a flag.
brandjon commentedon Aug 13, 2020
For context: The motivation behind this change is to make prelude evaluation more consistent with regular bzl loading. Before this change, the (parsed) prelude contents were syntactically prepended to every BUILD file, sort of like a C-style #include directive. This meant that the prelude's AST was shared by all BUILD files, and therefore couldn't be statically processed in the usual way by the Starlark interpreter (specifically, to record variable scoping information for faster runtime evaluation). It also made BUILD file evaluation even more complex, compared to treating the prelude as just another (virtual) load dependency.
We need to assess the use cases and how difficult they are to migrate. So if you're broken, please chime in.
I also opened #11946 to discuss possibly eliminating the prelude file altogether.
kevingessner commentedon Aug 17, 2020
Thanks for making this ticket! We use the prelude for two things:
To load commonly-used rules that should be available in every package. This includes some that shadow bazel-provided rules (see Feature request: Setting default javacopts for all java_library rules in workspace #3427). It sounds like this usage will be supported going forward.
To create universal targets in every package. In particular, we create syntax-checking test targets and some linters that we want in every package. These are macros that are loaded and called from the prelude, e.g.
with that macro defined roughly as:
This doesn't work if the prelude is handled as a regular bzl file, as the macros can't be called during load() ("The native module can be accessed only from a BUILD thread. Wrap the function in a macro and call it from a BUILD file"). So this would break with this change. Is there another way of supporting this kind of target creation?
aiuto commentedon Aug 18, 2020
Ah ha. Thanks Kevin. That is an interesting use case. We cope with that at Google by doing it metadata hooks at the source code repository level. Essentially, we set up the SCM so that we do the format test at PR pre-merge time, through non-bazel mechanisms. One obvious trade-off is that we have to maintain a more complex SCM than git, but we don't have to run (literally) millions of style checks in addition to the behavioral tests that our continuous testing pipeline is looking at.
aiuto commentedon Aug 18, 2020
No longer a release blocker for 3.5. I moved the baseline to before this change.
laurentlb commentedon Sep 2, 2020
@kevingessner Would it be acceptable for you to update the BUILD files and make them explicit?
i.e. add this line everywhere:
py_formatting_test()With a presubmit check, you can enforce that the call is present. The load statement isn't required if you put the load in the prelude file.
I uderstand it's not ideal for you, but supporting your use-case causes some problems. Right now, this bug is blocking the next Bazel release. Anyone has an opinion on what's the way forward?
We could design a solution to support your use-case, but that would take time (and we need releases in the meantime).
cc @alandonovan
kevingessner commentedon Sep 2, 2020
@laurentlb I thought the change was reverted, so releases could continue?
#11940 (comment)
We can do something like that, but I definitely liked having it automatic. I'd love to see a feature like that for the future.
laurentlb commentedon Sep 2, 2020
It was not reverted. Bazel 3.5 used a baseline just before the change, but the change is still at head and is blocking 3.6.
kevingessner commentedon Sep 2, 2020
Ah, I didn't realize. I was hoping this would be reverted and put behind a flag. I guess if you want to put this breaking change in 3.6, go ahead. I'll work around it when we upgrade.
aiuto commentedon Sep 2, 2020
I see you added release blocker again.
Just clarifying that you meant a 3.6 release blocker. And now that is less clear.