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");
}
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"));
}
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();
}
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"));
}
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();
}
Aggregations