use of com.google.devtools.build.lib.analysis.ViewCreationFailedException in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectFailingReturnsNotAStruct.
@Test
public void aspectFailingReturnsNotAStruct() throws Exception {
scratch.file("test/aspect.bzl", "def _impl(target, ctx):", " return 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("Aspect implementation should return a struct or a list, but got int");
}
use of com.google.devtools.build.lib.analysis.ViewCreationFailedException in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectFailingReturnsUnsafeObject.
@Test
public void aspectFailingReturnsUnsafeObject() throws Exception {
scratch.file("test/aspect.bzl", "def foo():", " return 0", "def _impl(target, ctx):", " return struct(x = foo)", "", "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" + "\n" + "\n" + "/workspace/test/aspect.bzl:4:11: Value of provider 'x' is of an illegal type: function");
}
use of com.google.devtools.build.lib.analysis.ViewCreationFailedException in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectOnAspectInconsistentVisibility.
@Test
public void aspectOnAspectInconsistentVisibility() 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):", " return struct(a2p = a2p(value = 'random'))", "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')", "r1(name = 'r1', dep = ':r0')", "r2(name = 'r2', dep = ':r1')", "r1(name = 'r1_1', dep = ':r2')", "r2(name = 'r2_1', dep = ':r1_1')");
reporter.removeHandler(failFastHandler);
try {
AnalysisResult analysisResult = update("//test:r2_1");
assertThat(analysisResult.hasError()).isTrue();
assertThat(keepGoing()).isTrue();
} catch (ViewCreationFailedException e) {
// expected
}
assertContainsEvent("ERROR /workspace/test/BUILD:4:1: Aspect //test:aspect.bzl%a2 is" + " applied twice, both before and after aspect //test:aspect.bzl%a1 " + "(when propagating from //test:r2 to //test:r1 via attribute dep)");
}
use of com.google.devtools.build.lib.analysis.ViewCreationFailedException in project bazel by bazelbuild.
the class SkylarkAspectsTest method aspectFailingOrphanArtifacts.
@Test
public void aspectFailingOrphanArtifacts() throws Exception {
scratch.file("test/aspect.bzl", "def _impl(target, ctx):", " ctx.new_file('missing_in_action.txt')", " return struct()", "", "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" + "\n" + "\n" + "The following files have no generating action:\n" + "test/missing_in_action.txt\n");
}
use of com.google.devtools.build.lib.analysis.ViewCreationFailedException in project bazel by bazelbuild.
the class SkylarkAspectsTest method getConfiguredTargetForAspectFragment.
private ConfiguredTarget getConfiguredTargetForAspectFragment(String fullFieldName, String fragments, String hostFragments, String ruleFragments, String ruleHostFragments) throws Exception {
scratch.file("test/aspect.bzl", "def _aspect_impl(target, ctx):", " return struct(result = str(" + fullFieldName + "))", "", "def _rule_impl(ctx):", " return struct(stuff = '...')", "", "MyAspect = aspect(", " implementation=_aspect_impl,", " attr_aspects=['deps'],", " fragments=[" + fragments + "],", " host_fragments=[" + hostFragments + "],", ")", "my_rule = rule(", " implementation=_rule_impl,", " attrs = { 'attr' : ", " attr.label_list(mandatory=True, allow_files=True, aspects = [MyAspect]) },", " fragments=[" + ruleFragments + "],", " host_fragments=[" + ruleHostFragments + "],", ")");
scratch.file("test/BUILD", "load('/test/aspect', 'my_rule')", "exports_files(['zzz'])", "my_rule(", " name = 'yyy',", " attr = ['zzz'],", ")", "my_rule(", " name = 'xxx',", " attr = ['yyy'],", ")");
AnalysisResult result = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
if (result.hasError()) {
assertThat(keepGoing()).isTrue();
throw new ViewCreationFailedException("Analysis failed");
}
return getConfiguredTarget("//test:xxx");
}
Aggregations