use of com.google.devtools.build.lib.analysis.ConfiguredTarget 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");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class BuildViewTestCase method checkWarning.
/**
* Check that configuration of the target named 'ruleName' in the
* specified BUILD file reports a warning message ending in
* 'expectedWarningMessage', and that no errors were reported.
*
* @param packageName the package name of the generated BUILD file
* @param ruleName the rule name for the rule in the generated BUILD file
* @param expectedWarningMessage the expected warning message.
* @param lines the text of the rule.
* @return the found error.
*/
protected Event checkWarning(String packageName, String ruleName, String expectedWarningMessage, String... lines) throws Exception {
eventCollector.clear();
ConfiguredTarget target = scratchConfiguredTarget(packageName, ruleName, lines);
assertFalse("Rule '" + "//" + packageName + ":" + ruleName + "' did contain an error", view.hasErrors(target));
return assertContainsEvent(expectedWarningMessage);
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class BuildViewTestCase method getPseudoActionViaExtraAction.
/**
* Retrieves an instance of {@code PseudoAction} that is shadowed by an extra action
* @param targetLabel Label of the target with an extra action
* @param actionListenerLabel Label of the action listener
*/
protected PseudoAction<?> getPseudoActionViaExtraAction(String targetLabel, String actionListenerLabel) throws Exception {
useConfiguration(String.format("--experimental_action_listener=%s", actionListenerLabel));
ConfiguredTarget target = getConfiguredTarget(targetLabel);
List<Action> actions = getExtraActionActions(target);
assertNotNull(actions);
assertThat(actions).hasSize(2);
ExtraAction extraAction = null;
for (Action action : actions) {
if (action instanceof ExtraAction) {
extraAction = (ExtraAction) action;
break;
}
}
assertNotNull(actions.toString(), extraAction);
Action pseudoAction = extraAction.getShadowedAction();
assertThat(pseudoAction).isInstanceOf(PseudoAction.class);
assertEquals(String.format("%s%s.extra_action_dummy", targetConfig.getGenfilesFragment(), convertLabelToPath(targetLabel)), pseudoAction.getPrimaryOutput().getExecPathString());
return (PseudoAction<?>) pseudoAction;
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class BuildConfigurationSkylarkTest method testSkylarkWithTestEnvOptions.
@Test
public void testSkylarkWithTestEnvOptions() throws Exception {
useConfiguration("--test_env=TEST_ENV_VAR=my_value");
scratch.file("examples/rule/BUILD");
scratch.file("examples/rule/config_test.bzl", "def _test_rule_impl(ctx):", " return struct(test_env = ctx.configuration.test_env)", "test_rule = rule(implementation = _test_rule_impl,", " attrs = {},", ")");
scratch.file("examples/config_skylark/BUILD", "package(default_visibility = ['//visibility:public'])", "load('/examples/rule/config_test', 'test_rule')", "test_rule(", " name = 'my_target',", ")");
ConfiguredTarget skylarkTarget = getConfiguredTarget("//examples/config_skylark:my_target");
SkylarkProviders skylarkProviders = skylarkTarget.getProvider(SkylarkProviders.class);
assertThat(skylarkProviders.getValue("test_env", SkylarkDict.class).get("TEST_ENV_VAR")).isEqualTo("my_value");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class BuildViewTestCase method assertSrcsValidity.
protected void assertSrcsValidity(String ruleType, String targetName, boolean expectedError, String... expectedMessages) throws Exception {
ConfiguredTarget target = getConfiguredTarget(targetName);
if (expectedError) {
assertTrue(view.hasErrors(target));
for (String expectedMessage : expectedMessages) {
String message = "in srcs attribute of " + ruleType + " rule " + targetName + ": " + expectedMessage;
assertContainsEvent(message);
}
} else {
assertFalse(view.hasErrors(target));
for (String expectedMessage : expectedMessages) {
String message = "in srcs attribute of " + ruleType + " rule " + target.getLabel() + ": " + expectedMessage;
assertDoesNotContainEvent(message);
}
}
}
Aggregations