Skip to content

Commit

Permalink
Improve error message for unresolved toolchains
Browse files Browse the repository at this point in the history
Closes bazelbuild#15135.

PiperOrigin-RevId: 447028054
  • Loading branch information
cpsauer authored and copybara-github committed May 6, 2022
1 parent 8950863 commit 45f4628
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Table;
import com.google.devtools.build.lib.analysis.PlatformConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
Expand Down Expand Up @@ -618,20 +617,14 @@ protected Code getDetailedCode() {
}

private static String getMessage(List<Label> missingToolchainTypes) {
if (missingToolchainTypes.size() == 1
&& Iterables.getOnlyElement(missingToolchainTypes)
.toString()
.equals("@bazel_tools//tools/cpp:toolchain_type")) {
return "No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. "
+ "Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there "
+ "is no default C++ toolchain added in the WORKSPACE file? See "
+ "https://github.com/bazelbuild/bazel/issues/10134 for details and migration "
+ "instructions.";
}

ImmutableList<String> labelStrings =
missingToolchainTypes.stream().map(Label::toString).collect(toImmutableList());
return String.format(
"no matching toolchains found for types %s",
missingToolchainTypes.stream().map(Label::toString).collect(joining(", ")));
"No matching toolchains found for types %s."
+ "\nTo debug, rerun with --toolchain_resolution_debug='%s'"
+ "\nIf platforms or toolchains are a new concept for you, we'd encourage reading "
+ "https://bazel.build/concepts/platforms-intro.",
String.join(", ", labelStrings), String.join("|", labelStrings));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void resolve_mandatory_missing() throws Exception {
.hasErrorEntryForKeyThat(key)
.hasExceptionThat()
.hasMessageThat()
.contains("no matching toolchains found for types //toolchain:test_toolchain");
.contains("No matching toolchains found for types //toolchain:test_toolchain");
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions src/test/shell/integration/toolchain_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ use_toolchain(
EOF

bazel build "//${pkg}/demo:use" &> $TEST_log && fail "Build failure expected"
expect_log "While resolving toolchains for target //${pkg}/demo:use: no matching toolchains found for types //${pkg}/toolchain:test_toolchain"
expect_log "While resolving toolchains for target //${pkg}/demo:use: No matching toolchains found for types //${pkg}/toolchain:test_toolchain."
}

function test_multiple_toolchain_use_in_rule {
Expand Down Expand Up @@ -572,7 +572,7 @@ use_toolchains(
EOF

bazel build "//${pkg}/demo:use" &> $TEST_log && fail "Build failure expected"
expect_log "While resolving toolchains for target //${pkg}/demo:use: no matching toolchains found for types //${pkg}/toolchain:test_toolchain_2"
expect_log "While resolving toolchains for target //${pkg}/demo:use: No matching toolchains found for types //${pkg}/toolchain:test_toolchain_2."
}

function test_toolchain_use_in_rule_non_required_toolchain {
Expand Down Expand Up @@ -827,7 +827,7 @@ EOF
--host_platform="//${pkg}:platform1" \
--platforms="//${pkg}:platform1" \
"//${pkg}/demo:use" &> $TEST_log && fail "Build failure expected"
expect_log "While resolving toolchains for target //${pkg}/demo:use: no matching toolchains found for types //${pkg}/toolchain:test_toolchain"
expect_log "While resolving toolchains for target //${pkg}/demo:use: No matching toolchains found for types //${pkg}/toolchain:test_toolchain."
expect_not_log 'Using toolchain: rule message:'
}

Expand Down

0 comments on commit 45f4628

Please sign in to comment.