-
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 basic incompatible target skipping #10945
Conversation
I'm posting this review to get some feedback from @gregestren (and anyone else interested) regarding implementation, functionality, etc. There is various documentation missing for starters. Also, the code could use some auto-formatting love. |
Ah, also looks like I need to update various unit tests. I'll get around to that also. |
Acknowledged. Please have patience but I'll look through as soon as I can. |
@philsc thanks for your patience. I'm going to look at this Monday. |
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.
First pass. Will do another pass tomorrow.
src/main/java/com/google/devtools/build/lib/analysis/AnalysisResult.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
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.
It's been longer than I'd like since I last looked at this. Looks like I have to look at a lot of the pieces again.
I'll add some comments to keep future me on track.
src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
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'm almost done incorporating your feedback. I also have to resolve a couple of conflicts when rebasing on 3.1.
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
4a6f40d
to
6c26d99
Compare
src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTargetFactory.java
Outdated
Show resolved
Hide resolved
Just as a sanity check, the commit on this PR is still old, right? |
This comment has been minimized.
This comment has been minimized.
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
c88047b
to
dd2e775
Compare
src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTargetFactory.java
Outdated
Show resolved
Hide resolved
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.
All my nitty comments aside, looking fairly good to me. The status reporting logic look also looks really nice.
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/IncompatiblePlatformProvider.java
Show resolved
Hide resolved
...ava/com/google/devtools/build/lib/analysis/configuredtargets/OutputFileConfiguredTarget.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTargetFactory.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTargetFactory.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTargetFactory.java
Outdated
Show resolved
Hide resolved
dd2e775
to
21b8d4d
Compare
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.
A minor update to address some of @gregestren 's feedback.
Added more TODOs to remind myself to add documentation.
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTargetFactory.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTargetFactory.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/IncompatiblePlatformProvider.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTargetFactory.java
Outdated
Show resolved
Hide resolved
...ava/com/google/devtools/build/lib/analysis/configuredtargets/OutputFileConfiguredTarget.java
Outdated
Show resolved
Hide resolved
21b8d4d
to
e4df959
Compare
Woah! I feel like we should frame that message. Nice job Phil on doing the heavy lifting and getting this over the finish line and thanks Greg for all your help and wisdom. |
It needs to be in a separate PR, not just a separate commit in this PR.
Will the change work standalone or does it require the rest of these
changes? Either way we can merge it, I can help with the third_party side
(as well as reviewing the non-third_party side).
…On Thu, Oct 22, 2020 at 4:25 PM Greg ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In WORKSPACE
<#10945 (comment)>:
> @@ -422,6 +422,8 @@ http_archive(
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/releases/download/3.1.0/bazel-toolchains-3.1.0.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/releases/download/3.1.0/bazel-toolchains-3.1.0.tar.gz",
],
+ patches = ["@//third_party:bazel_toolchains/0001-Rename-target_compatible_with-to-internal_target_com.patch"],
Merge update: third_party changes have to be in their own dedicated
commit. Can we move the .patch file to its own commit and get that
submitted first?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10945 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACPW7Y532ULTJ2LPIWTNLDSMCIMXANCNFSM4LFNQWKA>
.
|
The upcoming Incompatible Target Skipping patch (bazelbuild#10945) introduces a new `target_compatible_with` attribute which clashes with one of the custom attributes in the bazel-toolchains repo. This patch fixes the clash so we can merge the Incompatible Target Skipping path. This is essentially a backport of bazelbuild/bazel-toolchains#913.
@katre , @gregestren , here's the separate PR for the third-party portion: #12336 |
The upcoming Incompatible Target Skipping patch (bazelbuild#10945) introduces a new `target_compatible_with` attribute which clashes with one of the custom attributes in the bazel-toolchains repo. This patch fixes the clash so we can merge the Incompatible Target Skipping path. This is essentially a backport of bazelbuild/bazel-toolchains#913.
The upcoming Incompatible Target Skipping patch (#10945) introduces a new `target_compatible_with` attribute which clashes with one of the custom attributes in the bazel-toolchains repo. This patch fixes the clash so we can merge the Incompatible Target Skipping path. This is essentially a backport of bazelbuild/bazel-toolchains#913.
66f85e2
to
9c9905c
Compare
@katre , this is now rebased on top of the separate third-party and WORKSPACE patches. |
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.
Hi @philsc! This is a great change and I'm amazed at the progress you've made.
The large number of comments is my fault: I wasn't keeping up with the status of this PR and so am coming in late with suggestions and comments. Most of them are fairly minor, and are aimed at making the code be more inline with our internal style guide.
The only major change I'd like to propose is in IncompatiblePlatformProvider, and I've left comments there explaining my concerns and suggestions. If these have already been raised during this review, I apologize, and will happily defer to the previous reviewers. If you decide to leave that class as-is, however, could you add comments explaining the rationale for the decision?
Thanks, and sorry for my tardiness.
...ava/com/google/devtools/build/docgen/templates/attributes/common/target_compatible_with.html
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
Outdated
Show resolved
Hide resolved
...ain/java/com/google/devtools/build/lib/analysis/constraints/TopLevelConstraintSemantics.java
Outdated
Show resolved
Hide resolved
9c9905c
to
22818fa
Compare
Since I have the day off, I volunteered to help Phil out addressing comments. The easy ones should be done. Pushed to get some CI feedback. Now time to look at the harder ones. |
2915f50
to
397f3bc
Compare
src/main/java/com/google/devtools/build/lib/analysis/IncompatiblePlatformProvider.java
Outdated
Show resolved
Hide resolved
This patch aims to implement a basic version of incompatible target skipping outlined here: https://docs.google.com/document/d/12n5QNHmFSkuh5yAbdEex64ot4hRgR-moL1zRimU7wHQ/edit?usp=sharing The implementation in this patch supports target skipping based on the target platform. In a `BUILD` file you can now add constraints that the target platform must satisfy in order for the target to be built and/or tested. For example, use the following snippet to declare a target to be compatible with Windows platforms only: cc_binary( name = "bin", srcs = ["bin.cc"], target_compatible_with = [ "@platforms//os:windows", ], ) Builds triggered with `:all` or `...` on a non-Windows platform will simply skip the incompatible target. An appropriate note is shown on the command line if the `--show_result` threshold is high enough. Targets that transitively depend on incompatible targets are themselves considered incompatible and will also be skipped. Explicitly requesting an incompatible target on the command line is an error and will cause the build to fail. Bazel will print out an appropriate error message and inform the user what constraint could not be satisfied. See the new documentation in this patch for more information. In particular, https://docs.bazel.build/versions/master/platforms.html should be a good bit more informative. This implementation does not make any effort to support expressing compatibility with toolchains. It is possible that using `select()` (commented on below) already makes this possible, but it's not validated or explicitly supported in this patch. During implementation we noticed that `select()` can be quite powerful in combination with `target_compatible_with`. A basic summary of this is also documented on the Platforms page. It may be useful to create helper functions in, say, skylib to help make complex `select()` statements more readable. For example, we could replace the following: target_compatible_with = select({ "@platforms//os:linux": [], "@platforms//os:macos": [], "//conditions:default": [":not_compatible"], }) with something like: target_compatible_with = constraints.any_of([ "@platforms//os:linux", "@platforms//os:macos", ]) That, however, is work for follow-up patches. Many thanks to Austin Schuh (@AustinSchuh) and Greg Estren (@gregestren) for working on the proposal and helping a ton on this patch itself. Also thanks to many others who provided feedback on the implementation. RELNOTES: Bazel skips incompatible targets based on target platform and `target_compatible_with` contents. See https://docs.bazel.build/versions/master/platforms.html for more details.
397f3bc
to
c853ee9
Compare
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.
This looks great, thanks so much.
Greg, it's ready to be re-imported. let me know if you want me to help.
Got it. I'll re-import today. Stay tuned all... |
ARM-only target with --cpu=x86. Support work for #10945. PiperOrigin-RevId: 339113675
…rbe_config This essentially the same patch as 9a2fbe2 except that it deals with `target_compatible_with` instead of `exec_properties`. The PR bazelbuild/bazel#10945 adds a new `target_compatible_with` attribute to all rules. That includes repository rules. Currently the patch fails in `//src/test/shell/bazel:bazel_bootstrap_distfile_test`. The error complains about: Error in repository_rule: There is already a built-in attribute 'target_compatible_with' which cannot be overridden Since the repository rule is abstracted by a macro, it should be fairly safe to rename the attribute to `internal_target_compatible_with`.
Does this feature work with general rules? I'm finding that the presence of this rule continues to trigger load of py3_image in WORKSPACE when building on windows, and since io_bazel_rules_docker are not supported on Windows, this causes a build error. py3_image( |
Skipping the target happens after we have analyzed enough to evaluate the rule, so all the workspace loads have to have happened already. If you want py3_image to essentially be a no-op when you are building from windows, then you'll have to do workspace gymnastics to load fake docker rules. |
This patch aims to implement a basic version of incompatible target
skipping outlined here:
https://docs.google.com/document/d/12n5QNHmFSkuh5yAbdEex64ot4hRgR-moL1zRimU7wHQ/edit?usp=sharing
The implementation in this patch supports target skipping based
on the target platform. In a
BUILD
file you can now add constraintsthat the target platform must satisfy in order for the target to be
built and/or tested. For example, use the following snippet to declare
a target to be compatible with Windows platforms only:
Builds triggered with
:all
or...
on a non-Windows platform willsimply skip the incompatible target. An appropriate note is shown on
the command line if the
--show_result
threshold is high enough.Targets that transitively depend on incompatible targets are
themselves considered incompatible and will also be skipped.
Explicitly requesting an incompatible target on the command line is an
error and will cause the build to fail. Bazel will print out an
appropriate error message and inform the user what constraint could
not be satisfied.
See the new documentation in this patch for more information. In
particular, https://docs.bazel.build/versions/master/platforms.html
should be a good bit more informative.
This implementation does not make any effort to support expressing
compatibility with toolchains. It is possible that using
select()
(commented on below) already makes this possible, but it's not
validated or explicitly supported in this patch.
During implementation we noticed that
select()
can be quite powerfulin combination with
target_compatible_with
. A basic summary of thisis also documented on the Platforms page.
It may be useful to create helper functions in, say, skylib to help
make complex
select()
statements more readable. For example, wecould replace the following:
with something like:
That, however, is work for follow-up patches.
Many thanks to Austin Schuh (@AustinSchuh) and Greg Estren
(@gregestren) for working on the proposal and helping a ton on this
patch itself. Also thanks to many others who provided feedback on the
implementation.
RELNOTES: Bazel skips incompatible targets based on target platform
and
target_compatible_with
contents. Seehttps://docs.bazel.build/versions/master/platforms.html for more
details.