Skip to content

Commit 2780393

Browse files
fmeumcopybara-github
authored andcommitted
Make test toolchain requirement mandatory
This ensures that a test for which no compatible exec platform is available results in an analysis error (improved by the test toolchain type's `no_match_error`) instead of being run on the first execution platform, which is likely to fail with an uninformative "exec format" error. RELNOTES[inc]: The toolchain requirement of the default `test` exec group is now mandatory. Work towards #25160 Closes #25871. PiperOrigin-RevId: 753171295 Change-Id: I148a106f7ae3dfbeec121f7724ee60c101ea104b
1 parent ffd06a6 commit 2780393

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/main/java/com/google/devtools/build/lib/packages/RuleClass.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ public class RuleClass implements RuleClassData {
156156
public static final DeclaredExecGroup DEFAULT_TEST_RUNNER_EXEC_GROUP =
157157
DeclaredExecGroup.builder()
158158
.addToolchainType(
159-
ToolchainTypeRequirement.builder(PlatformConstants.DEFAULT_TEST_TOOLCHAIN_TYPE)
160-
.mandatory(false)
161-
.build())
159+
ToolchainTypeRequirement.create(PlatformConstants.DEFAULT_TEST_TOOLCHAIN_TYPE))
162160
.build();
163161

164162
/** Interface for determining whether a rule needs toolchain resolution or not. */

src/test/java/com/google/devtools/build/lib/analysis/test/TestActionBuilderTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.List;
5050
import java.util.Map;
5151
import java.util.Set;
52+
import java.util.regex.Pattern;
5253
import org.junit.Before;
5354
import org.junit.Ignore;
5455
import org.junit.Test;
@@ -736,10 +737,11 @@ def _some_test_impl(ctx):
736737
}
737738

738739
/**
739-
* With the default test toolchain, the first execution platform will be used (matching legacy).
740+
* With the default test toolchain, a failure to find a suitable execution platform will result in
741+
* a toolchain resolution error.
740742
*/
741743
@Test
742-
public void testFirstMatchingExecPlatformWithDefaultTestToolchain() throws Exception {
744+
public void testNoMatchingExecPlatformWithDefaultTestToolchain() throws Exception {
743745
scratch.file(
744746
"some_test.bzl",
745747
"""
@@ -792,11 +794,12 @@ def _some_test_impl(ctx):
792794
"--platforms=//:linux_x86_64_target",
793795
"--host_platform=//:macos_aarch64_exec",
794796
"--extra_execution_platforms=//:macos_aarch64_exec");
795-
ImmutableList<Artifact.DerivedArtifact> testStatusList = getTestStatusArtifacts("//:some_test");
796-
TestRunnerAction testAction = (TestRunnerAction) getGeneratingAction(testStatusList.get(0));
797-
assertThat(testAction.getExecutionPlatform().label())
798-
.isEqualTo(Label.parseCanonicalUnchecked("//:macos_aarch64_exec"));
799-
assertThat(testAction.getExecProperties()).isEmpty();
797+
reporter.removeHandler(failFastHandler);
798+
assertThat(getConfiguredTarget("//:some_test")).isNull();
799+
assertContainsEvent(
800+
Pattern.compile(
801+
"While resolving toolchains for target //:some_test: No matching toolchains found for"
802+
+ " types:.*?//tools/test:default_test_toolchain_type"));
800803
}
801804

802805
/**

0 commit comments

Comments
 (0)