Search in sources :

Example 16 with ViewCreationFailedException

use of com.google.devtools.build.lib.analysis.ViewCreationFailedException 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");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 17 with ViewCreationFailedException

use of com.google.devtools.build.lib.analysis.ViewCreationFailedException in project bazel by bazelbuild.

the class SkylarkAspectsTest method multipleAspects.

@Test
public void multipleAspects() throws Exception {
    scratch.file("test/aspect.bzl", "def _aspect_impl(target,ctx):", "  return struct()", "my_aspect = aspect(implementation = _aspect_impl)", "def _dummy_impl(ctx):", "  pass", "r1 = rule(_dummy_impl, ", "          attrs = { 'deps' : attr.label_list(aspects = [my_aspect, my_aspect]) })");
    scratch.file("test/BUILD", "load(':aspect.bzl', 'r1')", "r1(name = 't1')");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult result = update("//test:r1");
        assertThat(keepGoing()).isTrue();
        assertThat(result.hasError()).isTrue();
    } catch (TargetParsingException | ViewCreationFailedException expected) {
    // expected.
    }
    assertContainsEvent("aspect //test:aspect.bzl%my_aspect added more than once");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 18 with ViewCreationFailedException

use of com.google.devtools.build.lib.analysis.ViewCreationFailedException in project bazel by bazelbuild.

the class SkylarkAspectsTest method topLevelAspectDoesNotExistNoBuildFile.

@Test
public void topLevelAspectDoesNotExistNoBuildFile() throws Exception {
    scratch.file("test/BUILD", "java_library(name = 'xxx')");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult result = update(ImmutableList.of("foo/aspect.bzl%MyAspect"), "//test:xxx");
        assertThat(keepGoing()).isTrue();
        assertThat(result.hasError()).isTrue();
    } catch (ViewCreationFailedException e) {
    // expect to fail.
    }
    assertContainsEvent("Every .bzl file must have a corresponding package, but 'foo' does not have one. " + "Please create a BUILD file in the same or any parent directory. " + "Note that this BUILD file does not need to do anything except exist.");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 19 with ViewCreationFailedException

use of com.google.devtools.build.lib.analysis.ViewCreationFailedException in project bazel by bazelbuild.

the class SkylarkAspectsTest method duplicateSkylarkProviders.

@Test
public void duplicateSkylarkProviders() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "  return struct(duplicate = 'x')", "", "MyAspect = aspect(implementation=_impl)", "def _rule_impl(ctx):", "  return struct(duplicate = 'y')", "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: Provider duplicate provided twice");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 20 with ViewCreationFailedException

use of com.google.devtools.build.lib.analysis.ViewCreationFailedException in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectOnAspectInconsistentVisibilityIndirect.

@Test
public void aspectOnAspectInconsistentVisibilityIndirect() 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])})", "def _r0_impl(ctx):", "  pass", "r0 = rule(_r0_impl, attrs = { 'dep' : attr.label()})");
    scratch.file("test/BUILD", "load(':aspect.bzl', 'r0', 'r1', 'r2')", "r0(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')", "r0(name = 'r0_2', dep = ':r2_1')");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult analysisResult = update("//test:r0_2");
        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)");
}
Also used : ViewCreationFailedException(com.google.devtools.build.lib.analysis.ViewCreationFailedException) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Aggregations

ViewCreationFailedException (com.google.devtools.build.lib.analysis.ViewCreationFailedException)21 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)17 Test (org.junit.Test)16 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)3 Label (com.google.devtools.build.lib.cmdline.Label)2 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)2 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)2 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)2 Target (com.google.devtools.build.lib.packages.Target)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)1 ArtifactPrefixConflictException (com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)1 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 MutableActionGraph (com.google.devtools.build.lib.actions.MutableActionGraph)1 ActionConflictException (com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException)1 TestExecException (com.google.devtools.build.lib.actions.TestExecException)1 AnalysisFailureEvent (com.google.devtools.build.lib.analysis.AnalysisFailureEvent)1 LicensesProvider (com.google.devtools.build.lib.analysis.LicensesProvider)1 TargetLicense (com.google.devtools.build.lib.analysis.LicensesProvider.TargetLicense)1 StaticallyLinkedMarkerProvider (com.google.devtools.build.lib.analysis.StaticallyLinkedMarkerProvider)1