Search in sources :

Example 6 with SkylarkNestedSet

use of com.google.devtools.build.lib.syntax.SkylarkNestedSet in project bazel by bazelbuild.

the class SkylarkIntegrationTest method testOutputGroupsWithList.

@Test
public void testOutputGroupsWithList() throws Exception {
    scratch.file("test/skylark/extension.bzl", "def _impl(ctx):", "  f = ctx.attr.dep.output_group('_hidden_top_level" + INTERNAL_SUFFIX + "')", "  g = list(f)", "  return struct(result = f, ", "               output_groups = { 'my_group' : g, 'my_empty_group' : [] })", "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");
    SkylarkNestedSet result = (SkylarkNestedSet) myTarget.getProvider(SkylarkProviders.class).getValue("result");
    assertThat(result.getSet(Artifact.class)).containsExactlyElementsIn(hiddenTopLevelArtifacts);
    assertThat(myTarget.getProvider(OutputGroupProvider.class).getOutputGroup("my_group")).containsExactlyElementsIn(hiddenTopLevelArtifacts);
    assertThat(myTarget.getProvider(OutputGroupProvider.class).getOutputGroup("my_empty_group")).isEmpty();
}
Also used : 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 7 with SkylarkNestedSet

use of com.google.devtools.build.lib.syntax.SkylarkNestedSet in project bazel by bazelbuild.

the class SkylarkIntegrationTest method testOutputGroupsAsDictionary.

@Test
public void testOutputGroupsAsDictionary() throws Exception {
    scratch.file("test/skylark/extension.bzl", "def _impl(ctx):", "  f = ctx.attr.dep.output_groups['_hidden_top_level" + INTERNAL_SUFFIX + "']", "  has_key1 = '_hidden_top_level" + INTERNAL_SUFFIX + "' in ctx.attr.dep.output_groups", "  has_key2 = 'foobar' in ctx.attr.dep.output_groups", "  all_keys = [k for k in ctx.attr.dep.output_groups]", "  return struct(result = f, ", "                has_key1 = has_key1,", "                has_key2 = has_key2,", "                all_keys = all_keys,", "               output_groups = { 'my_group' : f })", "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);
    assertThat(skylarkProviders.getValue("has_key1")).isEqualTo(Boolean.TRUE);
    assertThat(skylarkProviders.getValue("has_key2")).isEqualTo(Boolean.FALSE);
    assertThat((SkylarkList) skylarkProviders.getValue("all_keys")).containsExactly("_hidden_top_level" + INTERNAL_SUFFIX, "compilation_prerequisites" + INTERNAL_SUFFIX, "files_to_compile" + INTERNAL_SUFFIX, "temp_files" + INTERNAL_SUFFIX);
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) SkylarkList(com.google.devtools.build.lib.syntax.SkylarkList) 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 8 with SkylarkNestedSet

use of com.google.devtools.build.lib.syntax.SkylarkNestedSet 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 9 with SkylarkNestedSet

use of com.google.devtools.build.lib.syntax.SkylarkNestedSet in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testFilesForFileConfiguredTarget.

@Test
public void testFilesForFileConfiguredTarget() throws Exception {
    Object result = evalRuleContextCode(createRuleContext("//foo:bar"), "ruleContext.attr.srcs[0].files");
    assertEquals("libjl.jar", ActionsTestUtil.baseNamesOf(((SkylarkNestedSet) result).getSet(Artifact.class)));
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkNestedSet(com.google.devtools.build.lib.syntax.SkylarkNestedSet) Test(org.junit.Test)

Example 10 with SkylarkNestedSet

use of com.google.devtools.build.lib.syntax.SkylarkNestedSet in project bazel by bazelbuild.

the class SkylarkRuleContextTest method testMiddleMan.

@Test
public void testMiddleMan() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:jl");
    Object result = evalRuleContextCode(ruleContext, "ruleContext.middle_man(':host_jdk')");
    assertThat(Iterables.getOnlyElement(((SkylarkNestedSet) result).getSet(Artifact.class)).getExecPathString()).contains("middlemen");
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) SkylarkNestedSet(com.google.devtools.build.lib.syntax.SkylarkNestedSet) Test(org.junit.Test)

Aggregations

SkylarkNestedSet (com.google.devtools.build.lib.syntax.SkylarkNestedSet)10 Test (org.junit.Test)9 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)6 Artifact (com.google.devtools.build.lib.actions.Artifact)5 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)4 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)4 RuleConfiguredTarget (com.google.devtools.build.lib.analysis.RuleConfiguredTarget)4 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)3 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)3 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)3 Label (com.google.devtools.build.lib.cmdline.Label)1 SkylarkRuleContext (com.google.devtools.build.lib.rules.SkylarkRuleContext)1 AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)1 SkylarkList (com.google.devtools.build.lib.syntax.SkylarkList)1 Nullable (javax.annotation.Nullable)1