Fix --experimental_prefer_mutual_xcode=false to recognize the correct developer directory for local xcode version tools when a mutually available Xcode is selected. The change in https://github.com/bazelbuild/bazel/commit/2572bba43133692b249eb840d5262cb32bc020db started using the version number of the default local version to find the local xcode, but this results in looking for developer tools at a path that doesn't exist. Instead, use the remote version associated with that local version, and match on that one, as we do with --experimental_prefer_mutual_xcode=true. RELNOTES: None. PiperOrigin-RevId: 295961075
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 06396be..5814866 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
@@ -343,6 +343,7 @@ } // Select the local default. Availability availability = null; + XcodeVersionRuleData localVersion = null; if (mutuallyAvailableVersions.isEmpty()) { ruleContext.ruleWarning( String.format( @@ -352,18 +353,22 @@ + " performance.", localVersions.getDefaultVersion().getVersion(), printableXcodeVersions(remoteVersions.getAvailableVersions()))); + localVersion = localVersions.getDefaultVersion(); availability = Availability.LOCAL; } else if (remoteAliasesToVersionMap.containsKey( localVersions.getDefaultVersion().getVersion().toString())) { availability = Availability.BOTH; + localVersion = + remoteAliasesToVersionMap.get(localVersions.getDefaultVersion().getVersion().toString()); } else { ruleContext.ruleWarning( "You passed --experimental_prefer_mutual_xcode=false, which prevents Bazel from" + " selecting an Xcode version that optimizes your performance. Please consider" + " using --experimental_prefer_mutual_xcode=true."); availability = Availability.LOCAL; + localVersion = localVersions.getDefaultVersion(); } - return Maps.immutableEntry(localVersions.getDefaultVersion(), availability); + return Maps.immutableEntry(localVersion, availability); } private static String printableXcodeVersions(Iterable<XcodeVersionRuleData> xcodeVersions) {