|
13 | 13 | // limitations under the License.
|
14 | 14 | package com.google.devtools.build.lib.skyframe;
|
15 | 15 |
|
| 16 | +import static com.google.common.collect.ImmutableList.toImmutableList; |
| 17 | +import static com.google.common.truth.Truth.assertThat; |
16 | 18 | import static com.google.devtools.build.lib.analysis.testing.ToolchainCollectionSubject.assertThat;
|
| 19 | +import static com.google.devtools.build.lib.analysis.testing.ToolchainContextSubject.assertThat; |
17 | 20 |
|
18 | 21 | import com.google.auto.value.AutoValue;
|
| 22 | +import com.google.common.collect.ImmutableList; |
19 | 23 | import com.google.common.collect.ImmutableMap;
|
20 | 24 | import com.google.common.collect.Iterables;
|
| 25 | +import com.google.devtools.build.lib.actions.Action; |
21 | 26 | import com.google.devtools.build.lib.analysis.BlazeDirectories;
|
22 | 27 | import com.google.devtools.build.lib.analysis.ConfiguredTarget;
|
23 | 28 | import com.google.devtools.build.lib.analysis.TargetAndConfiguration;
|
24 | 29 | import com.google.devtools.build.lib.analysis.ToolchainCollection;
|
| 30 | +import com.google.devtools.build.lib.analysis.ToolchainContext; |
| 31 | +import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget; |
| 32 | +import com.google.devtools.build.lib.analysis.test.BaselineCoverageAction; |
25 | 33 | import com.google.devtools.build.lib.analysis.util.AnalysisMock;
|
26 | 34 | import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
|
27 | 35 | import com.google.devtools.build.lib.cmdline.Label;
|
|
57 | 65 | * doesn't support direct access to environments.
|
58 | 66 | */
|
59 | 67 | @RunWith(JUnit4.class)
|
60 |
| -public class ToolchainsForTargetsTest extends AnalysisTestCase { |
| 68 | +public final class ToolchainsForTargetsTest extends AnalysisTestCase { |
61 | 69 | /** Returns a {@link SkyKey} for a given <Target, BuildConfiguration> pair. */
|
62 | 70 | private static Key key(
|
63 | 71 | TargetAndConfiguration targetAndConfiguration, ConfiguredTargetKey configuredTargetKey) {
|
@@ -475,4 +483,54 @@ public void keepParentToolchainContext() throws Exception {
|
475 | 483 | .defaultToolchainContext()
|
476 | 484 | .hasExecutionPlatform("//platforms:local_platform_b");
|
477 | 485 | }
|
| 486 | + |
| 487 | + /** Regression test for b/214105142, https://github.com/bazelbuild/bazel/issues/14521 */ |
| 488 | + @Test |
| 489 | + public void toolchainWithDifferentExecutionPlatforms_doesNotGenerateConflictingCoverageAction() |
| 490 | + throws Exception { |
| 491 | + scratch.file( |
| 492 | + "platforms/BUILD", |
| 493 | + "constraint_setting(name = 'local_setting')", |
| 494 | + "constraint_value(name = 'local_value_a', constraint_setting = ':local_setting')", |
| 495 | + "constraint_value(name = 'local_value_b', constraint_setting = ':local_setting')", |
| 496 | + "platform(name = 'local_platform_a', constraint_values = [':local_value_a'])", |
| 497 | + "platform(name = 'local_platform_b', constraint_values = [':local_value_b'])"); |
| 498 | + scratch.file( |
| 499 | + "a/BUILD", |
| 500 | + "load('//toolchain:rule.bzl', 'my_rule')", |
| 501 | + "my_rule(name='a', exec_compatible_with=['//platforms:local_value_a'])", |
| 502 | + "my_rule(name='b', exec_compatible_with=['//platforms:local_value_b'])"); |
| 503 | + useConfiguration( |
| 504 | + "--collect_code_coverage", |
| 505 | + "--extra_execution_platforms=//platforms:local_platform_a,//platforms:local_platform_b"); |
| 506 | + |
| 507 | + update("//a:a", "//a:b"); |
| 508 | + |
| 509 | + // Sanity check that a coverage action was generated for the rule itself. |
| 510 | + assertHasBaselineCoverageAction("//a:a", "Writing file a/a/baseline_coverage.dat"); |
| 511 | + assertHasBaselineCoverageAction("//a:b", "Writing file a/b/baseline_coverage.dat"); |
| 512 | + assertThat(getActions("//toolchains:toolchain_1_impl")).isEmpty(); |
| 513 | + ToolchainContext toolchainAContext = |
| 514 | + getToolchainCollection("//a:a").getDefaultToolchainContext(); |
| 515 | + assertThat(toolchainAContext).hasExecutionPlatform("//platforms:local_platform_a"); |
| 516 | + assertThat(toolchainAContext).hasToolchainType("//toolchain:test_toolchain"); |
| 517 | + assertThat(toolchainAContext).hasResolvedToolchain("//toolchains:toolchain_1_impl"); |
| 518 | + ToolchainContext toolchainBContext = |
| 519 | + getToolchainCollection("//a:b").getDefaultToolchainContext(); |
| 520 | + assertThat(toolchainBContext).hasExecutionPlatform("//platforms:local_platform_b"); |
| 521 | + assertThat(toolchainBContext).hasToolchainType("//toolchain:test_toolchain"); |
| 522 | + assertThat(toolchainBContext).hasResolvedToolchain("//toolchains:toolchain_1_impl"); |
| 523 | + } |
| 524 | + |
| 525 | + private void assertHasBaselineCoverageAction(String label, String progressMessage) |
| 526 | + throws InterruptedException { |
| 527 | + Action coverageAction = Iterables.getOnlyElement(getActions(label)); |
| 528 | + assertThat(coverageAction).isInstanceOf(BaselineCoverageAction.class); |
| 529 | + assertThat(coverageAction.getProgressMessage()).isEqualTo(progressMessage); |
| 530 | + } |
| 531 | + |
| 532 | + private ImmutableList<Action> getActions(String label) throws InterruptedException { |
| 533 | + return ((RuleConfiguredTarget) getConfiguredTarget(label)) |
| 534 | + .getActions().stream().map(Action.class::cast).collect(toImmutableList()); |
| 535 | + } |
478 | 536 | }
|
0 commit comments