diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java index 2de9906a79ef3b..1faccff61100c0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java @@ -77,8 +77,8 @@ public class AppleConfiguration extends Fragment implements AppleConfigurationAp private static final String MACOS_CPU_PREFIX = "darwin_"; // TODO(b/180572694): Remove after platforms based toolchain resolution supported. - /** Prefix for forced iOS simulator cpu values */ - public static final String IOS_FORCED_SIMULATOR_CPU_PREFIX = "sim_"; + /** Prefix for forced iOS and tvOS simulator cpu values */ + public static final String FORCED_SIMULATOR_CPU_PREFIX = "sim_"; /** Default cpu for iOS builds. */ @VisibleForTesting @@ -229,25 +229,24 @@ private static String getSingleArchitecture( // The removeSimPrefix argument is necessary due to a simulator and device both using arm64 // architecture. In the case of Starlark asking for the architecture, we should return the // actual architecture (arm64) but in other cases in this class what we actually want is the - // CPU without the ios prefix (e.g. sim_arm64). This parameter is provided in the private method - // so that internal to this class we are able to use both without duplicating retrieval logic. + // CPU without the ios/tvos prefix (e.g. sim_arm64). This parameter is provided in the private + // method so that internal to this class we are able to use both without duplicating retrieval + // logic. // TODO(b/180572694): Remove removeSimPrefix parameter once platforms are used instead of CPU + String cpu = getPrefixedAppleCpu(applePlatformType, appleCpus); + if (removeSimPrefix && cpu.startsWith(FORCED_SIMULATOR_CPU_PREFIX)) { + cpu = cpu.substring(FORCED_SIMULATOR_CPU_PREFIX.length()); + } + return cpu; + } + + private static String getPrefixedAppleCpu(PlatformType applePlatformType, AppleCpus appleCpus) { if (!Strings.isNullOrEmpty(appleCpus.appleSplitCpu())) { - String cpu = appleCpus.appleSplitCpu(); - if (removeSimPrefix && cpu.startsWith(IOS_FORCED_SIMULATOR_CPU_PREFIX)) { - cpu = cpu.substring(IOS_FORCED_SIMULATOR_CPU_PREFIX.length()); - } - return cpu; + return appleCpus.appleSplitCpu(); } switch (applePlatformType) { case IOS: - { - String cpu = Iterables.getFirst(appleCpus.iosMultiCpus(), appleCpus.iosCpu()); - if (removeSimPrefix && cpu.startsWith(IOS_FORCED_SIMULATOR_CPU_PREFIX)) { - cpu = cpu.substring(IOS_FORCED_SIMULATOR_CPU_PREFIX.length()); - } - return cpu; - } + return Iterables.getFirst(appleCpus.iosMultiCpus(), appleCpus.iosCpu()); case WATCHOS: return appleCpus.watchosCpus().get(0); case TVOS: