Skip to content

Commit

Permalink
Improve error message for unresolved toolchains
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsauer committed Mar 29, 2022
1 parent 33de02a commit 348c85d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,20 +570,12 @@ 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.";
}

List<String> labelStrings =
missingToolchainTypes.stream().map(Label::toString).collect(Collectors.toList());
return String.format(
"no matching toolchains found for types %s",
missingToolchainTypes.stream().map(Label::toString).collect(joining(", ")));
"No matching toolchains found for types %s. "
+ "To debug, rerun with --toolchain_resolution_debug='%s'",
String.join(", ", labelStrings), String.join("|", labelStrings));
}
}

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 @@ -436,7 +436,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. To debug, rerun with --toolchain_resolution_debug='//${pkg}/toolchain:test_toolchain'"
}

function test_multiple_toolchain_use_in_rule {
Expand Down Expand Up @@ -526,7 +526,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. To debug, rerun with --toolchain_resolution_debug='//${pkg}/toolchain:test_toolchain_2'"
}

function test_toolchain_use_in_rule_non_required_toolchain {
Expand Down Expand Up @@ -781,7 +781,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. To debug, rerun with --toolchain_resolution_debug='//${pkg}/toolchain:test_toolchain'"
expect_not_log 'Using toolchain: rule message:'
}

Expand Down

0 comments on commit 348c85d

Please sign in to comment.