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);
}
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");
}
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();
}
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");
}
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());
}
Aggregations