Search in sources :

Example 11 with AspectValue

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");
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) Label(com.google.devtools.build.lib.cmdline.Label) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 12 with AspectValue

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");
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) Label(com.google.devtools.build.lib.cmdline.Label) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 13 with AspectValue

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);
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)

Aggregations

AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)13 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)7 Artifact (com.google.devtools.build.lib.actions.Artifact)6 Test (org.junit.Test)6 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 Label (com.google.devtools.build.lib.cmdline.Label)4 Nullable (javax.annotation.Nullable)4 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)3 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)3 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)2 InputFileConfiguredTarget (com.google.devtools.build.lib.analysis.InputFileConfiguredTarget)2 OutputFileConfiguredTarget (com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget)2 TopLevelArtifactContext (com.google.devtools.build.lib.analysis.TopLevelArtifactContext)2 OutErr (com.google.devtools.build.lib.util.io.OutErr)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Stopwatch (com.google.common.base.Stopwatch)1 EventBus (com.google.common.eventbus.EventBus)1 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)1 ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)1