From f6a45fda097fcdae4704915c530403a90e9d6745 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Wed, 15 Jun 2016 19:32:34 +0000 Subject: Support for platform_type="watchos" on apple_binary. This builds all dependencies linked against watch SDKs instead of iOS SDKs, and builds for the architectures specified in --watchos_multi_cpus RELNOTES: apple_binary supports a new platform_type attribute, which, if set to "watchos", will build dependencies for Apple's watchOS2. -- MOS_MIGRATED_REVID=124980029 --- .../build/lib/rules/apple/AppleConfiguration.java | 51 ++++++++++++++++------ 1 file changed, 37 insertions(+), 14 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java') 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 3b9745f8d5..ebc8c9831f 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 @@ -76,6 +76,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { private final ConfigurationDistinguisher configurationDistinguisher; private final Optional xcodeVersion; private final ImmutableList iosMultiCpus; + private final ImmutableList watchosCpus; private final AppleBitcodeMode bitcodeMode; private final Label xcodeConfigLabel; @Nullable private final Label defaultProvisioningProfileLabel; @@ -102,6 +103,9 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { this.configurationDistinguisher = appleOptions.configurationDistinguisher; this.iosMultiCpus = ImmutableList.copyOf( Preconditions.checkNotNull(appleOptions.iosMultiCpus, "iosMultiCpus")); + this.watchosCpus = (appleOptions.watchosCpus == null || appleOptions.watchosCpus.isEmpty()) + ? ImmutableList.of(AppleCommandLineOptions.DEFAULT_WATCHOS_CPU) + : ImmutableList.copyOf(appleOptions.watchosCpus); this.bitcodeMode = appleOptions.appleBitcodeMode; this.xcodeConfigLabel = Preconditions.checkNotNull(appleOptions.xcodeVersionConfig, "xcodeConfigLabel"); @@ -201,11 +205,13 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { public Map appleTargetPlatformEnv(Platform platform) { ImmutableMap.Builder builder = ImmutableMap.builder(); - // TODO(bazel-team): Handle non-ios platforms. - if (platform == Platform.IOS_DEVICE || platform == Platform.IOS_SIMULATOR) { - String sdkVersion = getSdkVersionForPlatform(platform).toString(); - builder.put(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME, sdkVersion) - .put(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME, platform.getNameInPlist()); + // TODO(cparsons): Avoid setting SDK version for macosx. Until SDK version is + // evaluated for the current configuration xcode version, this would break users who build + // cc_* rules without specifying both xcode_version and macosx_sdk_version build options. + if (platform != Platform.MACOS_X) { + String sdkVersion = getSdkVersionForPlatform(platform).toString(); + builder.put(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME, sdkVersion) + .put(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME, platform.getNameInPlist()); } return builder.build(); } @@ -246,7 +252,9 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { } else { return getIosCpu(); } - // TODO(cparsons): Support platform types other than iOS. + case WATCHOS: + return watchosCpus.get(0); + // TODO(cparsons): Handle all platform types. default: throw new IllegalArgumentException("Unhandled platform type " + applePlatformType); } @@ -286,7 +294,8 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { } else { return getIosMultiCpus(); } - // TODO(cparsons): Support other platform types. + case WATCHOS: + return watchosCpus; default: throw new IllegalArgumentException("Unhandled platform type " + platformType); } @@ -313,12 +322,24 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { // TODO(bazel-team): This should support returning multiple platforms. public Platform getMultiArchPlatform(PlatformType platformType) { List architectures = getMultiArchitectures(platformType); - for (String arch : architectures) { - if (Platform.forTarget(PlatformType.IOS, arch) == Platform.IOS_DEVICE) { - return Platform.IOS_DEVICE; - } + switch (platformType) { + case IOS: + for (String arch : architectures) { + if (Platform.forTarget(PlatformType.IOS, arch) == Platform.IOS_DEVICE) { + return Platform.IOS_DEVICE; + } + } + return Platform.IOS_SIMULATOR; + case WATCHOS: + for (String arch : architectures) { + if (Platform.forTarget(PlatformType.WATCHOS, arch) == Platform.WATCHOS_DEVICE) { + return Platform.WATCHOS_DEVICE; + } + } + return Platform.WATCHOS_SIMULATOR; + default: + throw new IllegalArgumentException("Unsupported platform type " + platformType); } - return Platform.IOS_SIMULATOR; } /** @@ -498,7 +519,9 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { FRAMEWORK, /** Split transition distinguisher for {@code apple_watch1_extension} rule. */ WATCH_OS1_EXTENSION, - /** Split transition distinguisher for {@code apple_binary} rule. */ - APPLEBIN_IOS + /** Distinguisher for {@code apple_binary} rule with "ios" platform_type. */ + APPLEBIN_IOS, + /** Distinguisher for {@code apple_binary} rule with "watchos" platform_type. */ + APPLEBIN_WATCHOS, } } -- cgit v1.2.3