Search in sources :

Example 16 with SkylarkProviders

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);
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) RuleConfiguredTarget(com.google.devtools.build.lib.analysis.RuleConfiguredTarget) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) SkylarkNestedSet(com.google.devtools.build.lib.syntax.SkylarkNestedSet) Test(org.junit.Test)

Example 17 with SkylarkProviders

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);
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) SkylarkClassObjectConstructor(com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor) ClassObjectConstructor(com.google.devtools.build.lib.packages.ClassObjectConstructor) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) RuleConfiguredTarget(com.google.devtools.build.lib.analysis.RuleConfiguredTarget) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) Test(org.junit.Test)

Aggregations

SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)17 Test (org.junit.Test)12 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)9 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)6 Nullable (javax.annotation.Nullable)6 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)5 Artifact (com.google.devtools.build.lib.actions.Artifact)4 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)4 RuleConfiguredTarget (com.google.devtools.build.lib.analysis.RuleConfiguredTarget)4 Label (com.google.devtools.build.lib.cmdline.Label)4 SkylarkNestedSet (com.google.devtools.build.lib.syntax.SkylarkNestedSet)4 AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)3 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)2 ClassObjectConstructor (com.google.devtools.build.lib.packages.ClassObjectConstructor)2 SkylarkClassObjectConstructor (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor)2 FileProvider (com.google.devtools.build.lib.analysis.FileProvider)1 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)1 SkylarkKey (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.SkylarkKey)1 JavaProvider (com.google.devtools.build.lib.rules.java.JavaProvider)1 EvalException (com.google.devtools.build.lib.syntax.EvalException)1