Search in sources :

Example 11 with SkylarkAspect

use of com.google.devtools.build.lib.packages.SkylarkAspect in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testAspectParameterAndExtraDeps.

@Test
public void testAspectParameterAndExtraDeps() throws Exception {
    evalAndExport("def _impl(target, ctx):", "   pass", "my_aspect = aspect(_impl,", "   attrs = { 'param' : attr.string(values=['a', 'b']),", "             '_extra' : attr.label(default = Label('//foo/bar:baz')) }", ")");
    SkylarkAspect aspect = (SkylarkAspect) ev.lookup("my_aspect");
    assertThat(aspect.getAttributes()).hasSize(2);
    assertThat(aspect.getParamAttributes()).containsExactly("param");
}
Also used : SkylarkAspect(com.google.devtools.build.lib.packages.SkylarkAspect) Test(org.junit.Test)

Example 12 with SkylarkAspect

use of com.google.devtools.build.lib.packages.SkylarkAspect in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method fancyExports.

@Test
public void fancyExports() throws Exception {
    evalAndExport("def _impla(target, ctx): pass", "p, (a, p1) = [", "   provider(),", "   [ aspect(_impla),", "     provider() ]", "]");
    SkylarkClassObjectConstructor p = (SkylarkClassObjectConstructor) lookup("p");
    SkylarkAspect a = (SkylarkAspect) lookup("a");
    SkylarkClassObjectConstructor p1 = (SkylarkClassObjectConstructor) lookup("p1");
    assertThat(p.getPrintableName()).isEqualTo("p");
    assertThat(p.getKey()).isEqualTo(new SkylarkClassObjectConstructor.SkylarkKey(FAKE_LABEL, "p"));
    assertThat(p1.getPrintableName()).isEqualTo("p1");
    assertThat(p1.getKey()).isEqualTo(new SkylarkClassObjectConstructor.SkylarkKey(FAKE_LABEL, "p1"));
    assertThat(a.getAspectClass()).isEqualTo(new SkylarkAspectClass(FAKE_LABEL, "a"));
}
Also used : SkylarkAspectClass(com.google.devtools.build.lib.packages.SkylarkAspectClass) SkylarkAspect(com.google.devtools.build.lib.packages.SkylarkAspect) SkylarkClassObjectConstructor(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor) Test(org.junit.Test)

Example 13 with SkylarkAspect

use of com.google.devtools.build.lib.packages.SkylarkAspect in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method aspectRequiredAspectProvidersDefault.

@Test
public void aspectRequiredAspectProvidersDefault() throws Exception {
    evalAndExport("def _impl(target, ctx):", "   pass", "my_aspect = aspect(_impl)");
    SkylarkAspect myAspect = (SkylarkAspect) lookup("my_aspect");
    RequiredProviders requiredProviders = myAspect.getDefinition(AspectParameters.EMPTY).getRequiredProvidersForAspects();
    assertThat(requiredProviders.isSatisfiedBy(AdvertisedProviderSet.ANY)).isFalse();
    assertThat(requiredProviders.isSatisfiedBy(AdvertisedProviderSet.EMPTY)).isFalse();
}
Also used : SkylarkAspect(com.google.devtools.build.lib.packages.SkylarkAspect) RequiredProviders(com.google.devtools.build.lib.packages.RequiredProviders) Test(org.junit.Test)

Example 14 with SkylarkAspect

use of com.google.devtools.build.lib.packages.SkylarkAspect in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method aspectProvides.

@Test
public void aspectProvides() throws Exception {
    evalAndExport("def _impl(target, ctx):", "   pass", "y = provider()", "my_aspect = aspect(_impl, provides = ['x', y])");
    SkylarkAspect myAspect = (SkylarkAspect) lookup("my_aspect");
    AdvertisedProviderSet advertisedProviders = myAspect.getDefinition(AspectParameters.EMPTY).getAdvertisedProviders();
    assertThat(advertisedProviders.canHaveAnyProvider()).isFalse();
    assertThat(advertisedProviders.getSkylarkProviders()).containsExactly(legacy("x"), declared("y"));
}
Also used : SkylarkAspect(com.google.devtools.build.lib.packages.SkylarkAspect) AdvertisedProviderSet(com.google.devtools.build.lib.packages.AdvertisedProviderSet) Test(org.junit.Test)

Example 15 with SkylarkAspect

use of com.google.devtools.build.lib.packages.SkylarkAspect in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method aspectRequiredAspectProvidersSingle.

@Test
public void aspectRequiredAspectProvidersSingle() throws Exception {
    evalAndExport("def _impl(target, ctx):", "   pass", "cc = provider()", "my_aspect = aspect(_impl, required_aspect_providers=['java', cc])");
    SkylarkAspect myAspect = (SkylarkAspect) lookup("my_aspect");
    RequiredProviders requiredProviders = myAspect.getDefinition(AspectParameters.EMPTY).getRequiredProvidersForAspects();
    assertThat(requiredProviders.isSatisfiedBy(AdvertisedProviderSet.ANY)).isTrue();
    assertThat(requiredProviders.isSatisfiedBy(AdvertisedProviderSet.EMPTY)).isFalse();
    assertThat(requiredProviders.isSatisfiedBy(AdvertisedProviderSet.builder().addSkylark(declared("cc")).addSkylark("java").build())).isTrue();
    assertThat(requiredProviders.isSatisfiedBy(AdvertisedProviderSet.builder().addSkylark("cc").build())).isFalse();
}
Also used : SkylarkAspect(com.google.devtools.build.lib.packages.SkylarkAspect) RequiredProviders(com.google.devtools.build.lib.packages.RequiredProviders) Test(org.junit.Test)

Aggregations

SkylarkAspect (com.google.devtools.build.lib.packages.SkylarkAspect)16 Test (org.junit.Test)12 Attribute (com.google.devtools.build.lib.packages.Attribute)4 RequiredProviders (com.google.devtools.build.lib.packages.RequiredProviders)4 SkyKey (com.google.devtools.build.skyframe.SkyKey)3 Nullable (javax.annotation.Nullable)3 Label (com.google.devtools.build.lib.cmdline.Label)2 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)2 SkylarkAspectClass (com.google.devtools.build.lib.packages.SkylarkAspectClass)2 SkylarkAttr (com.google.devtools.build.lib.rules.SkylarkAttr)2 Descriptor (com.google.devtools.build.lib.rules.SkylarkAttr.Descriptor)2 SkylarkImportFailedException (com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.SkylarkImportFailedException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ConfiguredAspect (com.google.devtools.build.lib.analysis.ConfiguredAspect)1 ConfiguredAspectFactory (com.google.devtools.build.lib.analysis.ConfiguredAspectFactory)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 InconsistentAspectOrderException (com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException)1 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)1 DuplicateException (com.google.devtools.build.lib.analysis.MergedConfiguredTarget.DuplicateException)1