use of com.google.devtools.build.lib.syntax.SkylarkNestedSet in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectOutputsToBinDirectory.
@Test
public void aspectOutputsToBinDirectory() throws Exception {
scratch.file("foo/extension.bzl", "def _aspect_impl(target, ctx):", " file = ctx.new_file('aspect-output-' + target.label.name)", " ctx.file_action(file, 'data')", " return struct(aspect_file = file)", "my_aspect = aspect(_aspect_impl)", "def _rule_impl(ctx):", " pass", "rule_bin_out = rule(_rule_impl, output_to_genfiles=False)", "rule_gen_out = rule(_rule_impl, output_to_genfiles=True)", "def _main_rule_impl(ctx):", " s = depset()", " for d in ctx.attr.deps:", " s = s | depset([d.aspect_file])", " return struct(aspect_files = s)", "main_rule = rule(_main_rule_impl,", " attrs = { 'deps' : attr.label_list(aspects = [my_aspect]) },", ")");
scratch.file("foo/BUILD", "load('extension', 'rule_bin_out', 'rule_gen_out', 'main_rule')", "rule_bin_out(name = 'rbin')", "rule_gen_out(name = 'rgen')", "main_rule(name = 'main', deps = [':rbin', ':rgen'])");
AnalysisResult analysisResult = update(ImmutableList.<String>of(), "//foo:main");
ConfiguredTarget target = analysisResult.getTargetsToBuild().iterator().next();
NestedSet<Artifact> aspectFiles = ((SkylarkNestedSet) target.getProvider(SkylarkProviders.class).getValue("aspect_files")).getSet(Artifact.class);
assertThat(transform(aspectFiles, new Function<Artifact, String>() {
@Override
public String apply(Artifact artifact) {
return artifact.getFilename();
}
})).containsExactly("aspect-output-rbin", "aspect-output-rgen");
for (Artifact aspectFile : aspectFiles) {
String rootPath = aspectFile.getRoot().getExecPath().toString();
assertWithMessage("Artifact %s should not be in genfiles", aspectFile).that(rootPath).doesNotContain("genfiles");
assertWithMessage("Artifact %s should be in bin", aspectFile).that(rootPath).endsWith("bin");
}
}
use of com.google.devtools.build.lib.syntax.SkylarkNestedSet in project bazel by bazelbuild.
the class SkylarkIntegrationTest method testOutputGroups.
@Test
public void testOutputGroups() throws Exception {
scratch.file("test/skylark/extension.bzl", "def _impl(ctx):", " f = ctx.attr.dep.output_group('_hidden_top_level" + INTERNAL_SUFFIX + "')", " return struct(result = f, ", " 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");
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);
}
use of com.google.devtools.build.lib.syntax.SkylarkNestedSet in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testFilesForRuleConfiguredTarget.
@Test
public void testFilesForRuleConfiguredTarget() throws Exception {
Object result = evalRuleContextCode(createRuleContext("//foo:foo"), "ruleContext.attr.srcs[0].files");
assertEquals("a.txt", ActionsTestUtil.baseNamesOf(((SkylarkNestedSet) result).getSet(Artifact.class)));
}
use of com.google.devtools.build.lib.syntax.SkylarkNestedSet in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectPropagating.
@Test
public void aspectPropagating() throws Exception {
scratch.file("test/aspect.bzl", "def _impl(target, ctx):", " s = depset([target.label])", " c = depset([ctx.rule.kind])", " for i in ctx.rule.attr.deps:", " s += i.target_labels", " c += i.rule_kinds", " return struct(target_labels = s, rule_kinds = c)", "", "MyAspect = aspect(", " implementation=_impl,", " attr_aspects=['deps'],", ")");
scratch.file("test/BUILD", "java_library(", " name = 'yyy',", ")", "java_library(", " name = 'xxx',", " srcs = ['A.java'],", " deps = [':yyy'],", ")");
AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
assertThat(getLabelsToBuild(analysisResult)).containsExactly("//test:xxx");
AspectValue aspectValue = analysisResult.getAspects().iterator().next();
SkylarkProviders skylarkProviders = aspectValue.getConfiguredAspect().getProvider(SkylarkProviders.class);
assertThat(skylarkProviders).isNotNull();
Object names = skylarkProviders.getValue("target_labels");
assertThat(names).isInstanceOf(SkylarkNestedSet.class);
assertThat(transform(((SkylarkNestedSet) names).toCollection(), new Function<Object, String>() {
@Nullable
@Override
public String apply(Object o) {
assertThat(o).isInstanceOf(Label.class);
return o.toString();
}
})).containsExactly("//test:xxx", "//test:yyy");
Object ruleKinds = skylarkProviders.getValue("rule_kinds");
assertThat(ruleKinds).isInstanceOf(SkylarkNestedSet.class);
assertThat(((SkylarkNestedSet) ruleKinds).toCollection()).containsExactly("java_library");
}
use of com.google.devtools.build.lib.syntax.SkylarkNestedSet in project bazel by bazelbuild.
the class SkylarkAspectsTest method buildTargetAndCheckRuleInfo.
private void buildTargetAndCheckRuleInfo(String... expectedLabels) throws Exception {
AnalysisResult result = update(ImmutableList.<String>of(), "//test:r2");
ConfiguredTarget configuredTarget = result.getTargetsToBuild().iterator().next();
SkylarkNestedSet ruleInfoValue = (SkylarkNestedSet) configuredTarget.getProvider(SkylarkProviders.class).getValue("rule_info");
assertThat(ruleInfoValue.getSet(String.class)).containsExactlyElementsIn(Arrays.asList(expectedLabels));
}
Aggregations