Search in sources :

Example 21 with ViewCreationFailedException

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

the class SkylarkAspectsTest method duplicateOutputGroupsFromTwoAspects.

@Test
public void duplicateOutputGroupsFromTwoAspects() throws Exception {
    scratch.file("test/aspect.bzl", "def _a1_impl(target, ctx):", "  f = ctx.new_file(target.label.name + '_a1.txt')", "  ctx.file_action(f, 'f')", "  return struct(output_groups = { 'a1_group' : depset([f]) })", "", "a1 = aspect(implementation=_a1_impl, attr_aspects = ['dep'])", "def _rule_impl(ctx):", "  if not ctx.attr.dep:", "     return struct()", "  og = {k:ctx.attr.dep.output_groups[k] for k in ctx.attr.dep.output_groups}", "  return struct(output_groups = og)", "my_rule1 = rule(_rule_impl, attrs = { 'dep' : attr.label(aspects = [a1]) })", "def _a2_impl(target, ctx):", "  g = ctx.new_file(target.label.name + '_a2.txt')", "  ctx.file_action(g, 'f')", "  return struct(output_groups = { 'a1_group' : depset([g]) })", "", "a2 = aspect(implementation=_a2_impl, attr_aspects = ['dep'])", "my_rule2 = rule(_rule_impl, attrs = { 'dep' : attr.label(aspects = [a2]) })");
    scratch.file("test/BUILD", "load(':aspect.bzl', 'my_rule1', 'my_rule2')", "my_rule1(name = 'base')", "my_rule1(name = 'xxx', dep = ':base')", "my_rule2(name = 'yyy', dep = ':xxx')");
    reporter.removeHandler(failFastHandler);
    try {
        AnalysisResult analysisResult = update("//test:yyy");
        assertThat(analysisResult.hasError()).isTrue();
        assertThat(keepGoing()).isTrue();
    } catch (ViewCreationFailedException e) {
    // expected.
    }
    assertContainsEvent("ERROR /workspace/test/BUILD:3:1: Output group a1_group 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)

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