Obsolete and begin removing the toolchain_resolution_override flag.

It is not compatible with multiple execution platforms.

Part of #4442.

Change-Id: I683beaae1624130352a6f02bae3f4dfff263ea00
PiperOrigin-RevId: 183855561
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfiguration.java
index 021c673..97c7f4f 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfiguration.java
@@ -15,7 +15,6 @@
 package com.google.devtools.build.lib.analysis;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.concurrent.ThreadSafety;
@@ -42,7 +41,6 @@
   private final ImmutableList<Label> extraExecutionPlatforms;
   private final ImmutableList<Label> targetPlatforms;
   private final ImmutableList<Label> extraToolchains;
-  private final ImmutableMap<Label, Label> toolchainResolutionOverrides;
   private final ImmutableList<Label> enabledToolchainTypes;
 
   @AutoCodec.Instantiator
@@ -51,13 +49,11 @@
       ImmutableList<Label> extraExecutionPlatforms,
       ImmutableList<Label> targetPlatforms,
       ImmutableList<Label> extraToolchains,
-      ImmutableMap<Label, Label> toolchainResolutionOverrides,
       ImmutableList<Label> enabledToolchainTypes) {
     this.executionPlatform = executionPlatform;
     this.extraExecutionPlatforms = extraExecutionPlatforms;
     this.targetPlatforms = targetPlatforms;
     this.extraToolchains = extraToolchains;
-    this.toolchainResolutionOverrides = toolchainResolutionOverrides;
     this.enabledToolchainTypes = enabledToolchainTypes;
   }
 
@@ -85,16 +81,6 @@
     return extraToolchains;
   }
 
-  /** Returns {@code true} if the given toolchain type has a manual override set. */
-  public boolean hasToolchainOverride(Label toolchainType) {
-    return toolchainResolutionOverrides.containsKey(toolchainType);
-  }
-
-  /** Returns the {@link Label} of the toolchain to use for the given toolchain type. */
-  public Label getToolchainOverride(Label toolchainType) {
-    return toolchainResolutionOverrides.get(toolchainType);
-  }
-
   @SkylarkCallable(
     name = "enabled_toolchain_types",
     structField = true,
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfigurationLoader.java
index c4f9c8b..cdc4893 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformConfigurationLoader.java
@@ -15,9 +15,7 @@
 package com.google.devtools.build.lib.analysis;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
-import com.google.devtools.build.lib.analysis.PlatformOptions.ToolchainResolutionOverride;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.analysis.config.BuildOptions;
 import com.google.devtools.build.lib.analysis.config.ConfigurationEnvironment;
@@ -25,7 +23,6 @@
 import com.google.devtools.build.lib.analysis.config.FragmentOptions;
 import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
 import com.google.devtools.build.lib.cmdline.Label;
-import java.util.List;
 
 /** A loader that creates {@link PlatformConfiguration} instances based on command-line options. */
 public class PlatformConfigurationLoader implements ConfigurationFragmentFactory {
@@ -55,16 +52,6 @@
         ImmutableList.copyOf(options.extraExecutionPlatforms),
         ImmutableList.copyOf(options.platforms),
         ImmutableList.copyOf(options.extraToolchains),
-        convertOverrides(options.toolchainResolutionOverrides),
         ImmutableList.copyOf(options.enabledToolchainTypes));
   }
-
-  private static ImmutableMap<Label, Label> convertOverrides(
-      List<ToolchainResolutionOverride> overrides) {
-    ImmutableMap.Builder<Label, Label> builder = new ImmutableMap.Builder<>();
-    for (ToolchainResolutionOverride override : overrides) {
-      builder.put(override.toolchainType(), override.toolchainLabel());
-    }
-    return builder.build();
-  }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java
index bfd84ee..51bfd8a 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java
@@ -14,25 +14,16 @@
 
 package com.google.devtools.build.lib.analysis;
 
-import static com.google.devtools.build.lib.analysis.config.BuildConfiguration.convertOptionsLabel;
-
-import com.google.auto.value.AutoValue;
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration.LabelListConverter;
 import com.google.devtools.build.lib.analysis.config.FragmentOptions;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
-import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-import com.google.devtools.common.options.Converter;
 import com.google.devtools.common.options.Option;
 import com.google.devtools.common.options.OptionDocumentationCategory;
 import com.google.devtools.common.options.OptionEffectTag;
-import com.google.devtools.common.options.OptionsParsingException;
-import com.google.protobuf.CodedInputStream;
-import com.google.protobuf.CodedOutputStream;
-import java.io.IOException;
 import java.util.List;
 
 /** Command-line options for platform-related configuration. */
@@ -116,21 +107,23 @@
 
   @Option(
     name = "toolchain_resolution_override",
-    converter = ToolchainResolutionOverrideConverter.class,
     allowMultiple = true,
     defaultValue = "",
-    documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
+    documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
     effectTags = {
       OptionEffectTag.AFFECTS_OUTPUTS,
       OptionEffectTag.CHANGES_INPUTS,
       OptionEffectTag.LOADING_AND_ANALYSIS
     },
+    deprecationWarning =
+        "toolchain_resolution_override is now a no-op and will be removed in"
+            + " an upcoming release",
     help =
         "Override toolchain resolution for a toolchain type with a specific toolchain. "
             + "Example: --toolchain_resolution_override=@io_bazel_rules_go//:toolchain="
             + "@io_bazel_rules_go//:linux-arm64-toolchain"
   )
-  public List<ToolchainResolutionOverride> toolchainResolutionOverrides;
+  public List<String> toolchainResolutionOverrides;
 
   @Option(
     name = "toolchain_resolution_debug",
@@ -168,69 +161,4 @@
     host.toolchainResolutionOverrides = this.toolchainResolutionOverrides;
     return host;
   }
-
-  /** Data about which toolchain instance should be used for a given toolchain type. */
-  @AutoValue
-  public abstract static class ToolchainResolutionOverride {
-    public static final ObjectCodec<ToolchainResolutionOverride> CODEC =
-        new ToolchainResolutionOverrideCodec();
-
-    public abstract Label toolchainType();
-
-    public abstract Label toolchainLabel();
-
-    private static ToolchainResolutionOverride create(Label toolchainType, Label toolchainLabel) {
-      return new AutoValue_PlatformOptions_ToolchainResolutionOverride(
-          toolchainType, toolchainLabel);
-    }
-
-    private static class ToolchainResolutionOverrideCodec
-        implements ObjectCodec<ToolchainResolutionOverride> {
-      @Override
-      public Class<ToolchainResolutionOverride> getEncodedClass() {
-        return ToolchainResolutionOverride.class;
-      }
-
-      @Override
-      public void serialize(ToolchainResolutionOverride obj, CodedOutputStream codedOut)
-          throws SerializationException, IOException {
-        Label.CODEC.serialize(obj.toolchainType(), codedOut);
-        Label.CODEC.serialize(obj.toolchainLabel(), codedOut);
-      }
-
-      @Override
-      public ToolchainResolutionOverride deserialize(CodedInputStream codedIn)
-          throws SerializationException, IOException {
-        return ToolchainResolutionOverride.create(
-            Label.CODEC.deserialize(codedIn), Label.CODEC.deserialize(codedIn));
-      }
-    }
-  }
-
-  /**
-   * {@link Converter} implementation to create {@link ToolchainResolutionOverride} instances from
-   * the value set in the flag.
-   */
-  public static class ToolchainResolutionOverrideConverter
-      implements Converter<ToolchainResolutionOverride> {
-
-    @Override
-    public ToolchainResolutionOverride convert(String input) throws OptionsParsingException {
-      int index = input.indexOf('=');
-      if (index == -1) {
-        throw new OptionsParsingException(
-            "Toolchain resolution override not in the type=toolchain format");
-      }
-      Label toolchainType = convertOptionsLabel(input.substring(0, index));
-      Label toolchain = convertOptionsLabel(input.substring(index + 1));
-
-      return ToolchainResolutionOverride.create(toolchainType, toolchain);
-    }
-
-    @Override
-    public String getTypeDescription() {
-      return "a hard-coded override for toolchain resolution, "
-          + "in the format toolchainTypeLabel=toolchainLabel";
-    }
-  }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
index f222b38..0711230 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
@@ -49,12 +49,6 @@
     PlatformConfiguration platformConfiguration =
         configuration.getFragment(PlatformConfiguration.class);
 
-    if (platformConfiguration.hasToolchainOverride(key.toolchainType())) {
-      // Short circuit everything and just return the override.
-      return ToolchainResolutionValue.create(
-          platformConfiguration.getToolchainOverride(key.toolchainType()));
-    }
-
     // Get all toolchains.
     RegisteredToolchainsValue toolchains;
     try {
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java
index 128c59a..9d44e05 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java
@@ -64,30 +64,6 @@
   }
 
   @Test
-  public void testResolution_flagOverride() throws Exception {
-    // Add extra toolchain.
-    scratch.file(
-        "extra/BUILD",
-        "load('//toolchain:toolchain_def.bzl', 'test_toolchain')",
-        "test_toolchain(",
-        "  name='extra_toolchain_impl',",
-        "  data = 'extra')");
-
-    useConfiguration(
-        "--toolchain_resolution_override=" + testToolchainType + "=//extra:extra_toolchain_impl");
-
-    SkyKey key =
-        ToolchainResolutionValue.key(targetConfig, testToolchainType, linuxPlatform, macPlatform);
-    EvaluationResult<ToolchainResolutionValue> result = invokeToolchainResolution(key);
-
-    assertThatEvaluationResult(result).hasNoError();
-
-    ToolchainResolutionValue toolchainResolutionValue = result.get(key);
-    assertThat(toolchainResolutionValue.toolchainLabel())
-        .isEqualTo(makeLabel("//extra:extra_toolchain_impl"));
-  }
-
-  @Test
   public void testResolution_noneFound() throws Exception {
     // Clear the toolchains.
     rewriteWorkspace();