use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectsPropagatingForDefaultAndImplicit.
@Test
public void aspectsPropagatingForDefaultAndImplicit() throws Exception {
scratch.file("test/aspect.bzl", "def _impl(target, ctx):", " s = depset([target.label])", " c = depset([ctx.rule.kind])", " a = ctx.rule.attr", " if hasattr(a, '_stl') and a._stl:", " s += a._stl.target_labels", " c += a._stl.rule_kinds", " if hasattr(a, '_stl_default') and a._stl_default:", " s += a._stl_default.target_labels", " c += a._stl_default.rule_kinds", " return struct(target_labels = s, rule_kinds = c)", "", "def _rule_impl(ctx):", " pass", "", "my_rule = rule(implementation = _rule_impl,", " attrs = { '_stl' : attr.label(default = Label('//test:xxx')) },", ")", "MyAspect = aspect(", " implementation=_impl,", " attr_aspects=['_stl', '_stl_default'],", ")");
scratch.file("test/BUILD", "load('/test/aspect', 'my_rule')", "cc_library(", " name = 'xxx',", ")", "my_rule(", " name = 'yyy',", ")");
AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:yyy");
AspectValue aspectValue = analysisResult.getAspects().iterator().next();
SkylarkProviders skylarkProviders = aspectValue.getConfiguredAspect().getProvider(SkylarkProviders.class);
assertThat(skylarkProviders).isNotNull();
Object names = skylarkProviders.getValue("target_labels");
assertThat(names).isInstanceOf(SkylarkNestedSet.class);
assertThat(transform(((SkylarkNestedSet) names).toCollection(), new Function<Object, String>() {
@Nullable
@Override
public String apply(Object o) {
assertThat(o).isInstanceOf(Label.class);
return ((Label) o).getName();
}
})).containsExactly("stl", "xxx", "yyy");
}
use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectsPropagatingToAllAttributes.
@Test
public void aspectsPropagatingToAllAttributes() throws Exception {
scratch.file("test/aspect.bzl", "def _impl(target, ctx):", " s = depset([target.label])", " if hasattr(ctx.rule.attr, 'runtime_deps'):", " for i in ctx.rule.attr.runtime_deps:", " s += i.target_labels", " return struct(target_labels = s)", "", "MyAspect = aspect(", " implementation=_impl,", " attrs = { '_tool' : attr.label(default = Label('//test:tool')) },", " attr_aspects=['*'],", ")");
scratch.file("test/BUILD", "java_library(", " name = 'tool',", ")", "java_library(", " name = 'bar',", " runtime_deps = [':tool'],", ")", "java_library(", " name = 'foo',", " runtime_deps = [':bar'],", ")");
AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:foo");
AspectValue aspectValue = analysisResult.getAspects().iterator().next();
SkylarkProviders skylarkProviders = aspectValue.getConfiguredAspect().getProvider(SkylarkProviders.class);
assertThat(skylarkProviders).isNotNull();
Object names = skylarkProviders.getValue("target_labels");
assertThat(names).isInstanceOf(SkylarkNestedSet.class);
assertThat(transform(((SkylarkNestedSet) names).toCollection(), new Function<Object, String>() {
@Nullable
@Override
public String apply(Object o) {
assertThat(o).isInstanceOf(Label.class);
return ((Label) o).getName();
}
})).containsExactly("foo", "bar", "tool");
}
use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.
the class AndroidStudioInfoAspectTestBase method buildTarget.
private void buildTarget(String target) throws Exception {
AnalysisResult analysisResult = update(ImmutableList.of(target), ImmutableList.of(AndroidStudioInfoAspect.NAME), false, LOADING_PHASE_THREADS, true, new EventBus());
Collection<AspectValue> aspects = analysisResult.getAspects();
assertThat(aspects.size()).isEqualTo(1);
AspectValue value = aspects.iterator().next();
this.configuredAspect = value.getConfiguredAspect();
assertThat(configuredAspect.getName()).isEqualTo(AndroidStudioInfoAspect.NAME);
}
Aggregations