use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.
the class BuildViewTest method testLoadingErrorReportedCorrectly.
@Test
public void testLoadingErrorReportedCorrectly() throws Exception {
scratch.file("a/BUILD", "cc_library(name='a')");
scratch.file("b/BUILD", "cc_library(name='b', deps = ['//missing:lib'])");
reporter.removeHandler(failFastHandler);
AnalysisResult result = update(defaultFlags().with(Flag.KEEP_GOING), "//a", "//b");
assertThat(result.hasError()).isTrue();
assertThat(result.getError()).contains("command succeeded, but there were loading phase errors");
}
use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.
the class BuildViewTest method testSyntaxErrorInDepPackage.
@Test
public void testSyntaxErrorInDepPackage() throws Exception {
// Check that a loading error in a dependency is properly reported.
scratch.file("a/BUILD", "genrule(name='x',", " srcs = ['file.txt'],", " outs = ['foo'],", " cmd = 'echo')", // syntax error
"@");
scratch.file("b/BUILD", "genrule(name= 'cc',", " tools = ['//a:x'],", " outs = ['bar'],", " cmd = 'echo')");
reporter.removeHandler(failFastHandler);
EventBus eventBus = new EventBus();
AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//b:cc");
assertContainsEvent("invalid character: '@'");
assertThat(result.hasError()).isTrue();
}
use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.
the class BuildViewTest method ruleExtraActionsDontHideAspectExtraActions.
/**
* Here, injecting_rule injects an aspect which acts on a action_rule() and registers an action.
* The action_rule() registers another action of its own.
*
* <p>This test asserts that both actions are reported.
*/
@Test
public void ruleExtraActionsDontHideAspectExtraActions() throws Exception {
useConfiguration("--experimental_action_listener=//pkg:listener");
scratch.file("x/BUILD", "load(':extension.bzl', 'injecting_rule', 'action_rule')", "injecting_rule(name='a', deps=[':b'])", "action_rule(name='b')");
scratch.file("x/extension.bzl", "def _aspect1_impl(target, ctx):", " ctx.empty_action(mnemonic='Mnemonic')", " return struct()", "aspect1 = aspect(_aspect1_impl, attr_aspects=['deps'])", "", "def _injecting_rule_impl(ctx):", " return struct()", "injecting_rule = rule(_injecting_rule_impl, ", " attrs = { 'deps' : attr.label_list(aspects = [aspect1]) })", "", "def _action_rule_impl(ctx):", " out = ctx.new_file(ctx.label.name)", " ctx.action(outputs = [out], command = 'dontcare', mnemonic='Mnemonic')", " return struct()", "action_rule = rule(_action_rule_impl, attrs = { 'deps' : attr.label_list() })");
scratch.file("pkg/BUILD", "extra_action(name='xa', cmd='echo dont-care')", "action_listener(name='listener', mnemonics=['Mnemonic'], extra_actions=[':xa'])");
BuildView.AnalysisResult analysisResult = update("//x:a");
List<String> owners = new ArrayList<>();
for (Artifact artifact : analysisResult.getAdditionalArtifactsToBuild()) {
if ("xa".equals(artifact.getExtension())) {
owners.add(artifact.getOwnerLabel().toString());
}
}
assertThat(owners).containsExactly("//x:b", "//x:b");
}
use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.
the class BuildViewTest method testReportsLoadingRootCauses.
@Test
public void testReportsLoadingRootCauses() throws Exception {
// This test checks that two simultaneous errors are both reported:
// - missing outs attribute,
// - package referenced in tools does not exist
scratch.file("pkg/BUILD", "genrule(name='foo',", " tools=['//nopackage:missing'],", " cmd='')");
reporter.removeHandler(failFastHandler);
EventBus eventBus = new EventBus();
LoadingFailureRecorder recorder = new LoadingFailureRecorder();
eventBus.register(recorder);
// Note: no need to run analysis for a loading failure.
AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//pkg:foo");
assertThat(result.hasError()).isTrue();
assertThat(recorder.events).contains(Pair.of(Label.parseAbsolute("//pkg:foo"), Label.parseAbsolute("//nopackage:missing")));
assertContainsEvent("missing value for mandatory attribute 'outs'");
assertContainsEvent("no such package 'nopackage'");
// Skyframe correctly reports the other root cause as the genrule itself (since it is
// missing attributes).
assertThat(recorder.events).hasSize(2);
assertThat(recorder.events).contains(Pair.of(Label.parseAbsolute("//pkg:foo"), Label.parseAbsolute("//pkg:foo")));
}
use of com.google.devtools.build.lib.analysis.BuildView.AnalysisResult in project bazel by bazelbuild.
the class BuildViewTestBase method runTestForMultiCpuAnalysisFailure.
protected void runTestForMultiCpuAnalysisFailure(String badCpu, String goodCpu) throws Exception {
reporter.removeHandler(failFastHandler);
useConfiguration("--experimental_multi_cpu=" + badCpu + "," + goodCpu);
scratch.file("multi/BUILD", "config_setting(", " name = 'config',", " values = {'cpu': '" + badCpu + "'})", "cc_library(", " name = 'cpu',", " deps = select({", " ':config': [':fail'],", " '//conditions:default': []}))", "genrule(", " name = 'fail',", " outs = ['file1', 'file2'],", " executable = 1,", " cmd = 'touch $@')");
update(defaultFlags().with(Flag.KEEP_GOING), "//multi:cpu");
AnalysisResult result = getAnalysisResult();
assertThat(result.getTargetsToBuild()).hasSize(1);
ConfiguredTarget targetA = Iterables.get(result.getTargetsToBuild(), 0);
assertEquals(goodCpu, targetA.getConfiguration().getCpu());
// Unfortunately, we get the same error twice - we can't distinguish the configurations.
assertContainsEvent("if genrules produce executables, they are allowed only one output");
}
Aggregations