During toolchain resolution, first filter by toolchain type.
This improves debugging, by making the list of toolchains to check much smaller.
package com.google.devtools.build.lib.skyframe;
+import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.stream.Collectors.joining;
import com.google.common.collect.ImmutableList;
@@ -133,12 +134,14 @@ public class SingleToolchainResolutionFunction implements SkyFunction {
ImmutableMap.Builder<ConfiguredTargetKey, Label> builder = ImmutableMap.builder();
ToolchainTypeInfo toolchainType = null;
- for (DeclaredToolchainInfo toolchain : toolchains) {
- // Make sure the type matches.
- if (!toolchain.toolchainType().typeLabel().equals(toolchainTypeLabel)) {
- continue;
- }
+ // Pre-filter for the correct toolchain type. This simplifies the loop and makes debugging
+ // toolchain resolution much, much easier.
+ ImmutableList<DeclaredToolchainInfo> filteredToolchains =
+ toolchains.stream()
+ .filter(toolchain -> toolchain.toolchainType().typeLabel().equals(toolchainTypeLabel))
+ .collect(toImmutableList());
+ for (DeclaredToolchainInfo toolchain : filteredToolchains) {
// Make sure the target setting matches.
if (!toolchain.targetSettings().stream().allMatch(ConfigMatchingProvider::matches)) {
String mismatchValues =
