Skip to content

Commit 8482db4

Browse files
committed
Update test aspect to fix last_green build
Updates `_aspect_impl()` in `test/aspect/aspect.bzl` to return a new `VisitedInfo` provider instead of a `struct`. This fixes `//test/aspect:aspect_test` when building with the `last_green` bazel: - bazel-a91a6a77171c008598bdee53d144792c95211890-darwin-arm64 ```txt $ USE_BAZEL_VERSION=last_green \ bazel test --test_output=errors //test/aspect:aspect_test ERROR: testing/toolchain/BUILD:10:27: in //test/aspect:aspect.bzl%test_aspect aspect on testing_toolchain_deps rule //testing/toolchain:junit_classpath: Returning a struct from an aspect implementation function is deprecated. ERROR: Analysis of target '//testing/toolchain:junit_classpath' failed ERROR: Analysis of target '//test/aspect:aspect_test' failed; build aborted: Analysis failed ``` This `last_green` Bazel build contains the following commit, summarized as "Remove support for returning struct providers from aspects": - bazelbuild/bazel@07cddaf That commit is related to: - bazelbuild/bazel#25836 - bazelbuild/bazel#25819 - bazelbuild/intellij#7606
1 parent dc41be2 commit 8482db4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

test/aspect/aspect.bzl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ sure the targets we expect are there.
55
"""
66
attr_aspects = ["_scala_toolchain", "deps"]
77

8+
VisitedInfo = provider("Collection of visited targets", fields = ["visited"])
9+
810
def _stringify_label(label):
911
s = str(label)
1012
if s.startswith("@@//"):
@@ -15,12 +17,12 @@ def _stringify_label(label):
1517

1618
def _aspect_impl(target, ctx):
1719
visited = [_stringify_label(target.label)]
20+
1821
for attr_name in attr_aspects:
19-
if hasattr(ctx.rule.attr, attr_name):
20-
for dep in getattr(ctx.rule.attr, attr_name):
21-
if hasattr(dep, "visited"):
22-
visited += dep.visited
23-
return struct(visited = visited)
22+
for dep in getattr(ctx.rule.attr, attr_name, []):
23+
visited += dep[VisitedInfo].visited
24+
25+
return VisitedInfo(visited = visited)
2426

2527
test_aspect = aspect(
2628
attr_aspects = attr_aspects,
@@ -56,7 +58,7 @@ def _aspect_testscript_impl(ctx):
5658
}
5759
content = ""
5860
for target in ctx.attr.targets:
59-
visited = depset(sorted(target.visited)).to_list()
61+
visited = depset(sorted(target[VisitedInfo].visited)).to_list()
6062
expected = depset(sorted(expected_deps[target.label.name])).to_list()
6163
if visited != expected:
6264
content += """
@@ -71,12 +73,12 @@ def _aspect_testscript_impl(ctx):
7173
visited = ", ".join(visited),
7274
)
7375

74-
scriptFile = ctx.actions.declare_file("aspect_test.sh")
76+
script_file = ctx.actions.declare_file("aspect_test.sh")
7577
ctx.actions.write(
76-
output = scriptFile,
78+
output = script_file,
7779
content = content,
7880
)
79-
return [DefaultInfo(files = depset([scriptFile]))]
81+
return [DefaultInfo(files = depset([script_file]))]
8082

8183
aspect_testscript = rule(
8284
implementation = _aspect_testscript_impl,

0 commit comments

Comments
 (0)