use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectFailingExecution.
@Test
public void aspectFailingExecution() throws Exception {
scratch.file("test/aspect.bzl", "def _impl(target, ctx):", " return 1/0", "", "MyAspect = aspect(implementation=_impl)");
scratch.file("test/BUILD", "java_library(name = 'xxx',)");
reporter.removeHandler(failFastHandler);
try {
AnalysisResult result = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
assertThat(keepGoing()).isTrue();
assertThat(result.hasError()).isTrue();
} catch (ViewCreationFailedException e) {
// expect to fail.
}
assertContainsEvent("ERROR /workspace/test/BUILD:1:1: in " + "//test:aspect.bzl%MyAspect aspect on java_library rule //test:xxx: \n" + "Traceback (most recent call last):" + LINE_SEPARATOR + "\tFile \"/workspace/test/BUILD\", line 1" + LINE_SEPARATOR + "\t\t//test:aspect.bzl%MyAspect(...)" + LINE_SEPARATOR + "\tFile \"/workspace/test/aspect.bzl\", line 2, in _impl" + LINE_SEPARATOR + "\t\t1 / 0" + LINE_SEPARATOR + "integer division by zero");
}
use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult 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));
}
use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectParametersOptional.
@Test
public void aspectParametersOptional() throws Exception {
scratch.file("test/aspect.bzl", "def _impl(target, ctx):", " return struct()", "def _rule_impl(ctx):", " return struct()", "MyAspectOptParam = aspect(", " implementation=_impl,", " attrs = { 'my_attr' : attr.string(values=['aaa'], default='aaa') },", ")", "my_rule = rule(", " implementation=_rule_impl,", " attrs = { 'deps' : attr.label_list(aspects=[MyAspectOptParam]) },", ")");
scratch.file("test/BUILD", "load('//test:aspect.bzl', 'my_rule')", "my_rule(name = 'xxx')");
AnalysisResult result = update(ImmutableList.<String>of(), "//test:xxx");
assertThat(result.hasError()).isFalse();
}
use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.
the class SkylarkAspectsTest method duplicateOutputGroups.
@Test
public void duplicateOutputGroups() throws Exception {
scratch.file("test/aspect.bzl", "def _impl(target, ctx):", " f = ctx.new_file('f.txt')", " ctx.file_action(f, 'f')", " return struct(output_groups = { 'duplicate' : depset([f]) })", "", "MyAspect = aspect(implementation=_impl)", "def _rule_impl(ctx):", " g = ctx.new_file('g.txt')", " ctx.file_action(g, 'g')", " return struct(output_groups = { 'duplicate' : depset([g]) })", "my_rule = rule(_rule_impl)", "def _noop(ctx):", " pass", "rbase = rule(_noop, attrs = { 'dep' : attr.label(aspects = [MyAspect]) })");
scratch.file("test/BUILD", "load(':aspect.bzl', 'my_rule', 'rbase')", "my_rule(name = 'xxx')", "rbase(name = 'yyy', dep = ':xxx')");
reporter.removeHandler(failFastHandler);
try {
AnalysisResult result = update("//test:yyy");
assertThat(keepGoing()).isTrue();
assertThat(result.hasError()).isTrue();
} catch (ViewCreationFailedException e) {
// expect to fail.
}
assertContainsEvent("ERROR /workspace/test/BUILD:3:1: Output group duplicate provided twice");
}
use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectOnAspectLinearAlias.
/**
* Linear aspects-on-aspects with alias rule.
*/
@Test
public void aspectOnAspectLinearAlias() throws Exception {
scratch.file("test/aspect.bzl", "a1p = provider()", "def _a1_impl(target,ctx):", " return struct(a1p = a1p(text = 'random'))", "a1 = aspect(_a1_impl, attr_aspects = ['dep'], provides = ['a1p'])", "a2p = provider()", "def _a2_impl(target,ctx):", " value = []", " if hasattr(ctx.rule.attr.dep, 'a2p'):", " value += ctx.rule.attr.dep.a2p.value", " if hasattr(target, 'a1p'):", " value.append(str(target.label) + str(ctx.aspect_ids) + '=yes')", " else:", " value.append(str(target.label) + str(ctx.aspect_ids) + '=no')", " return struct(a2p = a2p(value = value))", "a2 = aspect(_a2_impl, attr_aspects = ['dep'], required_aspect_providers = ['a1p'])", "def _r1_impl(ctx):", " pass", "def _r2_impl(ctx):", " return struct(result = ctx.attr.dep.a2p.value)", "r1 = rule(_r1_impl, attrs = { 'dep' : attr.label(aspects = [a1])})", "r2 = rule(_r2_impl, attrs = { 'dep' : attr.label(aspects = [a2])})");
scratch.file("test/BUILD", "load(':aspect.bzl', 'r1', 'r2')", "r1(name = 'r0')", "alias(name = 'a0', actual = ':r0')", "r1(name = 'r1', dep = ':a0')", "r2(name = 'r2', dep = ':r1')");
AnalysisResult analysisResult = update("//test:r2");
ConfiguredTarget target = Iterables.getOnlyElement(analysisResult.getTargetsToBuild());
SkylarkList<?> result = (SkylarkList<?>) target.get("result");
// "yes" means that aspect a2 sees a1's providers.
assertThat(result).containsExactly("//test:r0[\"//test:aspect.bzl%a1\", \"//test:aspect.bzl%a2\"]=yes", "//test:r1[\"//test:aspect.bzl%a2\"]=no");
}
Aggregations