aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/apple
diff options
context:
space:
mode:
authorGravatar Chris Parsons <cparsons@google.com>2016-06-08 18:02:03 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-06-09 08:01:22 +0000
commitfac8383b7ca371e7e604327569aa5b35bb9576f4 (patch)
treebea22851e754e9c1e718d24a4f6119d341a58a69 /src/main/java/com/google/devtools/build/lib/rules/apple
parentbbab724f9c3600952a65a90febf50e1118568a96 (diff)
More refactor work on single-/multi- architecture accessor methods of AppleConfiguration.
Additionally, tweak single-architecture ios-platform logic such that ios_multi_cpus is checked before ios_cpu. There are two contexts to note: 1. Single-architecture logic, (generally post-split), unaware of its own platform type aside from configuration. This retrieves platform type from the --apple_platform_type configuration value. a. getSingleArchPlatform() for Platform retrieval b. getSingleArchitecture() for architecture retrieval 2. Multi-architecture logic, which should be aware of its own platform type, and passes it into configuration accessors. a. getMultiArchPlatform(PlatformType) b. getMultiArchitectures(PlatformType) All callers are migrated to these methods, though some still pass IOS platform type even though they may need to be refactored to support additional platform types later. -- MOS_MIGRATED_REVID=124370652
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/apple')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java97
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/apple/AppleToolchain.java8
2 files changed, 44 insertions, 61 deletions
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 9fc38f0d12..3b9745f8d5 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
@@ -221,45 +221,42 @@ public class AppleConfiguration extends BuildConfiguration.Fragment {
}
/**
- * Gets the single "effective" architecture for the given {@link PlatformType}. Prefer this over
- * {@link #getArchitectures(PlatformType)} only in cases if in the context of a rule which
- * is only concerned with a single architecture (such as {@code objc_library}, which registers
- * single-architecture compile actions.
+ * Gets the single "effective" architecture for this configuration's {@link PlatformType} (for
+ * example, "i386" or "arm64"). Prefer this over {@link #getMultiArchitectures(PlatformType)}
+ * only if in the context of rule logic which is only concerned with a single architecture (such
+ * as in {@code objc_library}, which registers single-architecture compile actions).
*
* <p>Single effective architecture is determined using the following rules:
* <ol>
* <li>If {@code --apple_split_cpu} is set (done via prior configuration transition), then
- * that is the effective architecture.</li>
- * <li>In the case of iOS, use {@code --ios_cpu}.</li>
+ * that is the effective architecture.</li>
+ * <li>If the multi cpus flag (e.g. {@code --ios_multi_cpus}) is set and non-empty, then the first
+ * such architecture is returned.</li>
+ * <li>In the case of iOS, use {@code --ios_cpu} for backwards compatibility.</li>
* <li>Use the default.</li></ol>
- *
- * @throws IllegalArgumentException if {@code --apple_platform_type} is set (via prior
- * configuration transition) yet does not match {@code platformType}
*/
- // TODO(cparsons): Support platform types other than iOS.
- // TODO(b/28958783): Consider changing this behavior to be more consistent between single and
- // multi-arch cases.
- public String getSingleArchitecture(PlatformType platformType) {
+ public String getSingleArchitecture() {
if (!Strings.isNullOrEmpty(appleSplitCpu)) {
- if (applePlatformType != platformType) {
- throw new IllegalArgumentException(
- String.format("Expected post-split-transition platform type %s to match input %s ",
- applePlatformType, platformType));
- }
return appleSplitCpu;
}
- switch (platformType) {
+ switch (applePlatformType) {
case IOS:
- return getIosCpu();
- // TODO(cparsons): Support other platform types.
+ if (!getIosMultiCpus().isEmpty()) {
+ return getIosMultiCpus().get(0);
+ } else {
+ return getIosCpu();
+ }
+ // TODO(cparsons): Support platform types other than iOS.
default:
- throw new IllegalArgumentException("Unhandled platform type " + platformType);
+ throw new IllegalArgumentException("Unhandled platform type " + applePlatformType);
}
}
-
+
/**
* Gets the "effective" architecture(s) for the given {@link PlatformType}. For example,
- * "i386" or "arm64". At least one architecture is always returned.
+ * "i386" or "arm64". At least one architecture is always returned. Prefer this over
+ * {@link #getSingleArchitecture} in rule logic which may support multiple architectures, such
+ * as bundling rules.
*
* <p>Effective architecture(s) is determined using the following rules:
* <ol>
@@ -273,7 +270,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment {
* @throws IllegalArgumentException if {@code --apple_platform_type} is set (via prior
* configuration transition) yet does not match {@code platformType}
*/
- public List<String> getArchitectures(PlatformType platformType) {
+ public List<String> getMultiArchitectures(PlatformType platformType) {
if (!Strings.isNullOrEmpty(appleSplitCpu)) {
if (applePlatformType != platformType) {
throw new IllegalArgumentException(
@@ -296,39 +293,26 @@ public class AppleConfiguration extends BuildConfiguration.Fragment {
}
/**
- * Gets the current configuration {@link Platform} for the given {@link PlatformType}. Platform
- * is determined via a combination between the given platform type and the "effective
- * architecture" of this configuration, as returned by {@link #getArchitectures}. If there
- * are multiple effective architectures, the first in the list will be used. (This handles
- * cases where multiple architectures may be specified, for example via multi-cpu flag, though
- * only one can be consumed for the current rule.) Consider {@link #getBundlingPlatform} as an
- * alternative, when more than one architecture may be expected.
+ * Gets the single "effective" platform for this configuration's {@link PlatformType} and
+ * architecture. Prefer this over {@link #getMultiArchPlatform(PlatformType)}
+ * only in cases if in the context of rule logic which is only concerned with a single
+ * architecture (such as in {@code objc_library}, which registers single-architecture compile
+ * actions).
*/
- public Platform getPlatform(PlatformType platformType) {
- return Platform.forTarget(platformType, getSingleArchitecture(platformType));
+ public Platform getSingleArchPlatform() {
+ return Platform.forTarget(applePlatformType, getSingleArchitecture());
}
/**
- * Returns the platform of the configuration for the current bundle for {@link PlatformType#IOS}
- * platform type, based on configured "effective" architectures (for example, {@code i386} maps
- * to {@link Platform#IOS_SIMULATOR}).
- *
- * <p>Effective architecture(s) are determined via {@link #getArchitectures}. If there are
- * multiple effective architectures, then returns {@link Platform#IOS_DEVICE} if any of the
- * architectures matches it, otherwise returns {@link Platform#IOS_SIMULATOR}.
- *
- * <p>Note that this method is similar to, {@link #getPlatform} but different in how it handles
- * multiple architecture scenarios. This method should be used for obtaining {@link Platform} in
- * contexts where multiple architectures are expected, such as bundling rules.
- *
- * @throws IllegalArgumentException if the current build options specify architecture(s) with
- * no known apple platform
+ * Gets the current configuration {@link Platform} for the given {@link PlatformType}. Platform
+ * is determined via a combination between the given platform type and the "effective"
+ * architectures of this configuration, as returned by {@link #getMultiArchitectures}; if any
+ * of the supported architectures are of device type, this will return a device platform.
+ * Otherwise, this will return a simulator platform.
*/
- // TODO(bazel-team): This method should be enabled to return multiple values once all call sites
- // (in particular actool, bundlemerge, momc) have been upgraded to support multiple values.
- // TODO(cparsons): Take platform type as input, supporting platforms other than IOS.
- public Platform getBundlingPlatform() {
- List<String> architectures = getArchitectures(PlatformType.IOS);
+ // TODO(bazel-team): This should support returning multiple platforms.
+ public Platform getMultiArchPlatform(PlatformType platformType) {
+ List<String> architectures = getMultiArchitectures(platformType);
for (String arch : architectures) {
if (Platform.forTarget(PlatformType.IOS, arch) == Platform.IOS_DEVICE) {
return Platform.IOS_DEVICE;
@@ -336,18 +320,19 @@ public class AppleConfiguration extends BuildConfiguration.Fragment {
}
return Platform.IOS_SIMULATOR;
}
-
+
/**
* Returns the {@link Platform} represented by {@code ios_cpu} (see {@link #getIosCpu}.
* (For example, {@code i386} maps to {@link Platform#IOS_SIMULATOR}.) Note that this is not
* necessarily the effective platform for all ios actions in the current context: This is
* typically the correct platform for implicityly-ios compile and link actions in the current
- * context. For effective platform for bundling actions, see {@link #getBundlingPlatform}.
+ * context. For effective platform for bundling actions, see
+ * {@link #getMultiArchPlatform(PlatformType)}.
*/
// TODO(b/28754442): Deprecate for more general skylark-exposed platform retrieval.
@SkylarkCallable(name = "ios_cpu_platform", doc = "The platform given by the ios_cpu flag.")
public Platform getIosCpuPlatform() {
- return getPlatform(PlatformType.IOS);
+ return Platform.forTarget(PlatformType.IOS, iosCpu);
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleToolchain.java
index a2bbaa1798..097f24f90d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleToolchain.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleToolchain.java
@@ -33,7 +33,6 @@ import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
-import com.google.devtools.build.lib.rules.apple.Platform.PlatformType;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.xcode.xcodegen.proto.XcodeGenProtos.XcodeprojBuildSetting;
@@ -82,12 +81,11 @@ public class AppleToolchain {
.build();
/**
- * Returns the platform plist name (for example, iPhoneSimulator) for the platform corresponding
- * to the value of {@code --ios_cpu} in the given configuration.
+ * Returns the platform plist name (for example, iPhoneSimulator) for the single-arch-context
+ * apple platform specified in the configuration.
*/
- // TODO(bazel-team): Support non-ios platforms.
public static String getPlatformPlistName(AppleConfiguration configuration) {
- return configuration.getPlatform(PlatformType.IOS).getNameInPlist();
+ return configuration.getSingleArchPlatform().getNameInPlist();
}
/**