use of com.google.devtools.build.lib.analysis.SkylarkProviders in project bazel by bazelbuild.
the class SkylarkIntegrationTest method testOutputGroupsAsDictionaryPipe.
@Test
public void testOutputGroupsAsDictionaryPipe() throws Exception {
scratch.file("test/skylark/extension.bzl", "def _impl(ctx):", " f = ctx.attr.dep.output_groups['_hidden_top_level" + INTERNAL_SUFFIX + "']", " g = ctx.attr.dep.output_groups['_hidden_top_level" + INTERNAL_SUFFIX + "'] | depset([])", " return struct(result = g, ", " output_groups = { 'my_group' : g })", "my_rule = rule(implementation = _impl,", " attrs = { 'dep' : attr.label() })");
scratch.file("test/skylark/BUILD", "load('/test/skylark/extension', 'my_rule')", "cc_binary(name = 'lib', data = ['a.txt'])", "my_rule(name='my', dep = ':lib')");
NestedSet<Artifact> hiddenTopLevelArtifacts = getConfiguredTarget("//test/skylark:lib").getProvider(OutputGroupProvider.class).getOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL);
ConfiguredTarget myTarget = getConfiguredTarget("//test/skylark:my");
SkylarkProviders skylarkProviders = myTarget.getProvider(SkylarkProviders.class);
SkylarkNestedSet result = (SkylarkNestedSet) skylarkProviders.getValue("result");
assertThat(result.getSet(Artifact.class)).containsExactlyElementsIn(hiddenTopLevelArtifacts);
assertThat(myTarget.getProvider(OutputGroupProvider.class).getOutputGroup("my_group")).containsExactlyElementsIn(hiddenTopLevelArtifacts);
}
use of com.google.devtools.build.lib.analysis.SkylarkProviders in project bazel by bazelbuild.
the class SkylarkIntegrationTest method rulesReturningDeclaredProvidersCompatMode.
@Test
public void rulesReturningDeclaredProvidersCompatMode() throws Exception {
scratch.file("test/extension.bzl", "my_provider = provider()", "def _impl(ctx):", " return struct(providers = [my_provider(x = 1)])", "my_rule = rule(_impl)");
scratch.file("test/BUILD", "load(':extension.bzl', 'my_rule')", "my_rule(name = 'r')");
ConfiguredTarget configuredTarget = getConfiguredTarget("//test:r");
ClassObjectConstructor.Key key = new SkylarkClassObjectConstructor.SkylarkKey(Label.create(configuredTarget.getLabel().getPackageIdentifier(), "extension.bzl"), "my_provider");
SkylarkProviders skylarkProviders = configuredTarget.getProvider(SkylarkProviders.class);
assertThat(skylarkProviders).isNotNull();
SkylarkClassObject declaredProvider = skylarkProviders.getDeclaredProvider(key);
assertThat(declaredProvider).isNotNull();
assertThat(declaredProvider.getConstructor().getKey()).isEqualTo(key);
assertThat(declaredProvider.getValue("x")).isEqualTo(1);
}
Aggregations