If --experimental_prefer_mutual_xcode=false, match the local default Xcode version to remote versions by its version number only, not by the entire Xcode version rule data.

Without this, dynamic execution gets turned off in the default case if the xcode_config has different data remotely and locally. We actually only care that the version be the same, not that the aliases, for example, are the same.

RELNOTES: None
PiperOrigin-RevId: 294735526
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java
index 5052261..06396be 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java
@@ -353,7 +353,8 @@
               localVersions.getDefaultVersion().getVersion(),
               printableXcodeVersions(remoteVersions.getAvailableVersions())));
       availability = Availability.LOCAL;
-    } else if (mutuallyAvailableVersions.contains(localVersions.getDefaultVersion())) {
+    } else if (remoteAliasesToVersionMap.containsKey(
+        localVersions.getDefaultVersion().getVersion().toString())) {
       availability = Availability.BOTH;
     } else {
       ruleContext.ruleWarning(
diff --git a/src/test/java/com/google/devtools/build/lib/rules/apple/XcodeConfigTest.java b/src/test/java/com/google/devtools/build/lib/rules/apple/XcodeConfigTest.java
index d169430..7cea95d 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/apple/XcodeConfigTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/apple/XcodeConfigTest.java
@@ -460,6 +460,66 @@
   }
 
   @Test
+  public void testLocalDefaultCanBeMutuallyAvailable() throws Exception {
+    // Passing "--experimental_prefer_mutual_xcode=false" allows toggling between Xcode versions
+    // using xcode-select. This test ensures that if the version from xcode-select is available
+    // remotely, both local and remote execution are enabled.
+    scratch.file(
+        "xcode/BUILD",
+        "xcode_config(",
+        "    name = 'foo',",
+        "    remote_versions = ':remote',",
+        "    local_versions = ':local',",
+        ")",
+        "",
+        "xcode_version(",
+        "    name = 'version512',",
+        "    version = '5.1.2',",
+        "    aliases = ['5', '5.1'],",
+        ")",
+        "xcode_version(",
+        "    name = 'version84',",
+        "    version = '8.4',",
+        ")",
+        "xcode_version(",
+        "    name = 'version92',",
+        "    version = '9.2',",
+        ")",
+        "xcode_version(",
+        "    name = 'version9',",
+        "    version = '9',",
+        ")",
+        "xcode_version(",
+        "    name = 'version10',",
+        "    version = '10',",
+        "    aliases = ['10.0'],",
+        ")",
+        "xcode_version(",
+        "    name = 'other_version10',",
+        "    version = '10.0',",
+        ")",
+        "available_xcodes(",
+        "    name = 'remote',",
+        "    versions = [':version512', ':version92', ':version9', ':version10'],",
+        "    default = ':version512',",
+        ")",
+        "available_xcodes(",
+        "    name = 'local',",
+        "    versions = [':version84', ':other_version10', ':version92', ':version9'],",
+        "    default = ':other_version10',",
+        ")");
+    useConfiguration(
+        "--xcode_version_config=//xcode:foo", "--experimental_prefer_mutual_xcode=false");
+    assertXcodeVersion("10");
+    assertAvailability(XcodeConfigInfo.Availability.BOTH);
+    assertHasRequirements(
+        ImmutableList.of(
+            ExecutionRequirements.REQUIRES_DARWIN, ExecutionRequirements.REQUIREMENTS_SET));
+
+    assertNoEvents();
+  }
+
+  @Test
   public void testInvalidXcodeFromMutualThrows() throws Exception {
     scratch.file(
         "xcode/BUILD",