Description of the bug:
It looks like aspects run on incompatible targets when they shouldn't.
I think the answer here is that the aspects should not run and instead just provide the IncompatiblePlatformProvider to signify that it's incompatible as well.
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
The absolute minimal example:
example.bzl:
def _custom_rule_impl(ctx):
pass
custom_rule = rule(
implementation = _custom_rule_impl,
)
def _example_aspect_impl(target, ctx):
print("Running aspect on " + str(target))
return []
_example_aspect = aspect(
implementation = _example_aspect_impl,
attr_aspects = ["dep"],
)
def _basic_rule_with_aspect_impl(ctx):
pass
basic_rule_with_aspect = rule(
implementation = _basic_rule_with_aspect_impl,
attrs = {
"dep": attr.label(
aspects = [_example_aspect],
),
},
)
BUILD:
load(":example.bzl", "basic_rule_with_aspect", "custom_rule")
custom_rule(
name = "target1",
target_compatible_with = ["@platforms//:incompatible"],
)
basic_rule_with_aspect(
name = "target2",
dep = ":target1",
)
When you build this target, you'll see that the print() statement in the aspect gets executed:
$ bazel build //:target2
DEBUG: /home/pschrader/work/test_repo/example.bzl:9:10: Running aspect on <target //:target1>
ERROR: Target //:target2 is incompatible and cannot be built, but was explicitly requested.
Dependency chain:
//:target2
//:target1 <-- target platform (@local_config_platform//:host) didn't satisfy constraint @platforms//:incompatible
INFO: Elapsed time: 0.070s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 2 targets configured)
This can lead to undesirable effects. Largely because the aspect evaluation can generate errors before bazel gets a chance to tell the user about the incompatible target being requested.
Which operating system are you running Bazel on?
Ubuntu 18.04
What is the output of bazel info release?
release 5.1.0
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
N/A
What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
Description of the bug:
It looks like aspects run on incompatible targets when they shouldn't.
I think the answer here is that the aspects should not run and instead just provide the
IncompatiblePlatformProviderto signify that it's incompatible as well.What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
The absolute minimal example:
example.bzl:BUILD:When you build this target, you'll see that the
print()statement in the aspect gets executed:This can lead to undesirable effects. Largely because the aspect evaluation can generate errors before bazel gets a chance to tell the user about the incompatible target being requested.
Which operating system are you running Bazel on?
Ubuntu 18.04
What is the output of
bazel info release?release 5.1.0
If
bazel info releasereturnsdevelopment versionor(@non-git), tell us how you built Bazel.N/A
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD?Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response