|
| 1 | +load("@bazel_skylib//lib:unittest.bzl", "analysistest") |
| 2 | + |
| 3 | +_VisitedRulesInfo = provider() |
| 4 | + |
| 5 | +def _aspect_with_javainfo_required_imp(target, ctx): |
| 6 | + visited = dict([(target.label.name, "")]) |
| 7 | + for dep in ctx.rule.attr.deps: |
| 8 | + visited.update(dep[_VisitedRulesInfo].visited) |
| 9 | + |
| 10 | + return [ |
| 11 | + _VisitedRulesInfo(visited = visited), |
| 12 | + ] |
| 13 | + |
| 14 | +#An aspect that has "required_providers = [JavaInfo]." |
| 15 | +#This is used to test that an aspect that has required_providers can access the JavaInfo provided by the scala_xxx targets |
| 16 | +_aspect_with_javainfo_required = aspect( |
| 17 | + attr_aspects = ["deps"], |
| 18 | + required_providers = [JavaInfo], |
| 19 | + implementation = _aspect_with_javainfo_required_imp, |
| 20 | +) |
| 21 | + |
| 22 | +def _javainfo_from_aspect_test_imp(ctx): |
| 23 | + testenv = analysistest.begin(ctx) |
| 24 | + |
| 25 | + for expected in ctx.attr.expected: |
| 26 | + if (expected not in ctx.attr.target[_VisitedRulesInfo].visited): |
| 27 | + analysistest.fail(testenv, "Aspect did not visit expected target %s" % ctx.attr.expected) |
| 28 | + return analysistest.end(testenv) |
| 29 | + |
| 30 | +javainfo_from_aspect_test = analysistest.make( |
| 31 | + impl = _javainfo_from_aspect_test_imp, |
| 32 | + attrs = { |
| 33 | + "target": attr.label(aspects = [_aspect_with_javainfo_required]), |
| 34 | + "expected": attr.string_list(), #The targets we expect to be visited by the aspect |
| 35 | + }, |
| 36 | +) |
0 commit comments