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