Search in sources :

Example 26 with AnalysisResult

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

the class SkylarkAspectsTest method aspectWithOutputGroups.

@Test
public void aspectWithOutputGroups() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   f = target.output_group('_hidden_top_level" + INTERNAL_SUFFIX + "')", "   return struct(output_groups = { 'my_result' : f })", "", "MyAspect = aspect(", "   implementation=_impl,", ")");
    scratch.file("test/BUILD", "java_library(", "     name = 'xxx',", "     srcs = ['A.java'],", ")");
    AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
    assertThat(getLabelsToBuild(analysisResult)).containsExactly("//test:xxx");
    AspectValue aspectValue = analysisResult.getAspects().iterator().next();
    OutputGroupProvider outputGroupProvider = aspectValue.getConfiguredAspect().getProvider(OutputGroupProvider.class);
    assertThat(outputGroupProvider).isNotNull();
    NestedSet<Artifact> names = outputGroupProvider.getOutputGroup("my_result");
    assertThat(names).isNotEmpty();
    NestedSet<Artifact> expectedSet = getConfiguredTarget("//test:xxx").getProvider(OutputGroupProvider.class).getOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL);
    assertThat(names).containsExactlyElementsIn(expectedSet);
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 27 with AnalysisResult

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

the class BuildViewTest method testPostProcessedConfigurableAttributes.

/**
   * Tests that rules with configurable attributes can be accessed through {@link
   * com.google.devtools.build.lib.skyframe.PostConfiguredTargetFunction}.
   * This is a regression test for a Bazel crash.
   */
@Test
public void testPostProcessedConfigurableAttributes() throws Exception {
    useConfiguration("--cpu=k8");
    // Expect errors from action conflicts.
    reporter.removeHandler(failFastHandler);
    scratch.file("conflict/BUILD", "config_setting(name = 'a', values = {'test_arg': 'a'})", "cc_library(name='x', srcs=select({':a': ['a.cc'], '//conditions:default': ['foo.cc']}))", "cc_binary(name='_objs/x/conflict/foo.pic.o', srcs=['bar.cc'])");
    AnalysisResult result = update(defaultFlags().with(Flag.KEEP_GOING), "//conflict:_objs/x/conflict/foo.pic.o", "//conflict:x");
    assertThat(result.hasError()).isTrue();
    // Expect to reach this line without a Precondition-triggered NullPointerException.
    assertContainsEvent("file 'conflict/_objs/x/conflict/foo.pic.o' is generated by these conflicting actions");
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 28 with AnalysisResult

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

the class BuildViewTest method testCircularDependencyWithLateBoundLabel.

@Test
public void testCircularDependencyWithLateBoundLabel() throws Exception {
    scratch.file("cycle/BUILD", "cc_library(name = 'foo', deps = [':bar'])", "cc_library(name = 'bar')");
    useConfiguration("--experimental_stl=//cycle:foo");
    reporter.removeHandler(failFastHandler);
    EventBus eventBus = new EventBus();
    LoadingFailureRecorder loadingFailureRecorder = new LoadingFailureRecorder();
    AnalysisFailureRecorder analysisFailureRecorder = new AnalysisFailureRecorder();
    eventBus.register(loadingFailureRecorder);
    eventBus.register(analysisFailureRecorder);
    AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//cycle:foo");
    assertThat(result.hasError()).isTrue();
    assertContainsEvent("in cc_library rule //cycle:foo: cycle in dependency graph:");
    // This needs to be reported as an anlysis-phase cycle; the cycle only occurs due to the stl
    // command-line option, which is part of the configuration, and which is used due to the
    // late-bound label.
    assertThat(Iterables.transform(analysisFailureRecorder.events, ANALYSIS_EVENT_TO_STRING_PAIR)).containsExactly(Pair.of("//cycle:foo", "//cycle:foo"));
    assertThat(loadingFailureRecorder.events).isEmpty();
}
Also used : EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 29 with AnalysisResult

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

the class BuildViewTest method testCircularDependencyBelowTwoTargets.

/**
   * Regression test: Exception in ConfiguredTargetGraph.checkForCycles()
   * when multiple top-level targets depend on the same cycle.
   */
@Test
public void testCircularDependencyBelowTwoTargets() throws Exception {
    scratch.file("foo/BUILD", "sh_library(name = 'top1', srcs = ['top1.sh'], deps = [':rec1'])", "sh_library(name = 'top2', srcs = ['top2.sh'], deps = [':rec1'])", "sh_library(name = 'rec1', srcs = ['rec1.sh'], deps = [':rec2'])", "sh_library(name = 'rec2', srcs = ['rec2.sh'], deps = [':rec1'])");
    reporter.removeHandler(failFastHandler);
    AnalysisResult result = update(defaultFlags().with(Flag.KEEP_GOING), "//foo:top1", "//foo:top2");
    assertThat(result.hasError()).isTrue();
    assertContainsEvent("in sh_library rule //foo:rec1: cycle in dependency graph:\n");
    assertContainsEvent("in sh_library rule //foo:top");
}
Also used : AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 30 with AnalysisResult

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

the class BuildViewTest method testReportsAnalysisRootCauses.

@Test
public void testReportsAnalysisRootCauses() throws Exception {
    scratch.file("private/BUILD", "genrule(", "    name='private',", "    outs=['private.out'],", "    cmd='',", "    visibility=['//visibility:private'])");
    scratch.file("foo/BUILD", "genrule(", "    name='foo',", "    tools=[':bar'],", "    outs=['foo.out'],", "    cmd='')", "genrule(", "    name='bar',", "    tools=['//private'],", "    outs=['bar.out'],", "    cmd='')");
    reporter.removeHandler(failFastHandler);
    EventBus eventBus = new EventBus();
    AnalysisFailureRecorder recorder = new AnalysisFailureRecorder();
    eventBus.register(recorder);
    AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//foo");
    assertThat(result.hasError()).isTrue();
    assertThat(recorder.events).hasSize(1);
    AnalysisFailureEvent event = recorder.events.get(0);
    assertEquals("//foo:bar", event.getFailureReason().toString());
    assertEquals("//foo:foo", event.getFailedTarget().getLabel().toString());
}
Also used : EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Aggregations

AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)69 Test (org.junit.Test)63 ViewCreationFailedException (com.google.devtools.build.lib.analysis.ViewCreationFailedException)21 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)12 EventBus (com.google.common.eventbus.EventBus)8 AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)7 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)6 Artifact (com.google.devtools.build.lib.actions.Artifact)5 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)5 SkylarkList (com.google.devtools.build.lib.syntax.SkylarkList)5 Nullable (javax.annotation.Nullable)5 Label (com.google.devtools.build.lib.cmdline.Label)4 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)3 SkylarkNestedSet (com.google.devtools.build.lib.syntax.SkylarkNestedSet)3 Key (com.google.devtools.build.lib.packages.ClassObjectConstructor.Key)2 SkylarkKey (com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.SkylarkKey)2 Stopwatch (com.google.common.base.Stopwatch)1 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 AnalysisPhaseCompleteEvent (com.google.devtools.build.lib.analysis.AnalysisPhaseCompleteEvent)1 BuildInfoEvent (com.google.devtools.build.lib.analysis.BuildInfoEvent)1