Search in sources :

Example 21 with ConfiguredTarget

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");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)

Example 22 with ConfiguredTarget

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);
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) RuleConfiguredTarget(com.google.devtools.build.lib.analysis.RuleConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget)

Example 23 with ConfiguredTarget

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;
}
Also used : Action(com.google.devtools.build.lib.actions.Action) SourceManifestAction(com.google.devtools.build.lib.analysis.SourceManifestAction) ExtraAction(com.google.devtools.build.lib.rules.extra.ExtraAction) PseudoAction(com.google.devtools.build.lib.analysis.PseudoAction) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) SymlinkTreeAction(com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction) WorkspaceStatusAction(com.google.devtools.build.lib.analysis.WorkspaceStatusAction) BaselineCoverageAction(com.google.devtools.build.lib.rules.test.BaselineCoverageAction) PseudoAction(com.google.devtools.build.lib.analysis.PseudoAction) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) RuleConfiguredTarget(com.google.devtools.build.lib.analysis.RuleConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) ExtraAction(com.google.devtools.build.lib.rules.extra.ExtraAction)

Example 24 with ConfiguredTarget

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");
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) SkylarkDict(com.google.devtools.build.lib.syntax.SkylarkDict) Test(org.junit.Test)

Example 25 with ConfiguredTarget

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);
        }
    }
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) RuleConfiguredTarget(com.google.devtools.build.lib.analysis.RuleConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget)

Aggregations

ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)222 Test (org.junit.Test)178 Artifact (com.google.devtools.build.lib.actions.Artifact)51 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)41 RuleConfiguredTarget (com.google.devtools.build.lib.analysis.RuleConfiguredTarget)25 Label (com.google.devtools.build.lib.cmdline.Label)17 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)15 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)13 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)12 Nullable (javax.annotation.Nullable)10 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)9 Variables (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables)9 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)7 Map (java.util.Map)7 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)6 TestAspects (com.google.devtools.build.lib.analysis.util.TestAspects)6 Attribute (com.google.devtools.build.lib.packages.Attribute)6 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)5 ConfigMatchingProvider (com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider)5 TestFilteringCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent)5