aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/apple
diff options
context:
space:
mode:
authorGravatar Chris Parsons <cparsons@google.com>2015-11-18 22:39:48 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-11-19 10:04:30 +0000
commit181010eeb9535003cc934050a89fa76700f7e60e (patch)
tree4d48f490f5cdd4977bca7bf7be106d3415707ff9 /src/main/java/com/google/devtools/build/lib/rules/apple
parent6f09a5d5e4b9b7b508542a5d62d961e3a077868e (diff)
Propagate apple platform environment variables for CppCompileAction
-- MOS_MIGRATED_REVID=108182745
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.java38
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/apple/Platform.java48
2 files changed, 80 insertions, 6 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 783adddebc..b751a13f6f 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
@@ -83,17 +83,45 @@ public class AppleConfiguration extends BuildConfiguration.Fragment {
* for actions pertaining to building ios applications. Keys are variable names and values are
* their corresponding values.
*/
- // TODO(bazel-team): Repurpose for non-ios platforms.
+ // TODO(bazel-team): Separate host system and target platform environment
public Map<String, String> getEnvironmentForIosAction() {
+ ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder();
+ mapBuilder.putAll(appleTargetPlatformEnv(Platform.forIosArch(getIosCpu())));
+ mapBuilder.putAll(appleHostSystemEnv());
+ return mapBuilder.build();
+ }
+
+ /**
+ * Returns a map of environment variables (derived from configuration) that should be propagated
+ * for actions that build on an apple host system. These environment variables are needed to
+ * by apple toolchain. Keys are variable names and values are their corresponding values.
+ */
+ public Map<String, String> appleHostSystemEnv() {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
- if (xcodeVersionOverride.isPresent()) {
- builder.put(XCODE_VERSION_ENV_NAME, xcodeVersionOverride.get().toString());
+ if (getXcodeVersionOverride().isPresent()) {
+ builder.put(AppleConfiguration.XCODE_VERSION_ENV_NAME,
+ getXcodeVersionOverride().get().toString());
}
- builder.put(APPLE_SDK_VERSION_ENV_NAME, iosSdkVersion.toString());
- builder.put(APPLE_SDK_PLATFORM_ENV_NAME, Platform.forIosArch(getIosCpu()).getNameInPlist());
return builder.build();
}
+ /**
+ * Returns a map of environment variables (derived from configuration) that should be propagated
+ * for actions pertaining to building applications for apple platforms. These environment
+ * variables are needed to use apple toolkits. Keys are variable names and values are their
+ * corresponding values.
+ */
+ public Map<String, String> appleTargetPlatformEnv(Platform platform) {
+ ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+
+ // TODO(bazel-team): Handle non-ios platforms.
+ if (platform == Platform.IOS_DEVICE || platform == Platform.IOS_SIMULATOR) {
+ builder.put(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME, getIosSdkVersion().toString())
+ .put(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME, platform.getNameInPlist());
+ }
+ return builder.build();
+ }
+
public String getIosCpu() {
return iosCpu;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/Platform.java b/src/main/java/com/google/devtools/build/lib/rules/apple/Platform.java
index e5b447e327..ad75b11856 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/apple/Platform.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/apple/Platform.java
@@ -20,15 +20,26 @@ import com.google.common.collect.ImmutableSet;
import java.util.Locale;
import java.util.Set;
+import javax.annotation.Nullable;
+
/**
* An enum that can be used to distinguish between various apple platforms.
*/
public enum Platform {
- IOS_DEVICE("iPhoneOS"), IOS_SIMULATOR("iPhoneSimulator");
+ IOS_DEVICE("iPhoneOS"),
+ IOS_SIMULATOR("iPhoneSimulator"),
+ MACOSX("MacOSX");
private static final Set<String> IOS_SIMULATOR_ARCHS = ImmutableSet.of("i386", "x86_64");
private static final Set<String> IOS_DEVICE_ARCHS =
ImmutableSet.of("armv6", "armv7", "armv7s", "arm64");
+
+ private static final Set<String> IOS_SIMULATOR_TARGET_CPUS =
+ ImmutableSet.of("ios_x86_64", "ios_i386");
+ private static final Set<String> IOS_DEVICE_TARGET_CPUS =
+ ImmutableSet.of("ios_armv7", "ios_arm64");
+ private static final Set<String> MACOSX_TARGET_CPUS =
+ ImmutableSet.of("darwin_x86_64");
private final String nameInPlist;
@@ -70,4 +81,39 @@ public enum Platform {
"No supported ios platform registered for architecture " + arch);
}
}
+
+ @Nullable
+ private static Platform forTargetCpuNullable(String targetCpu) {
+ if (IOS_SIMULATOR_TARGET_CPUS.contains(targetCpu)) {
+ return IOS_SIMULATOR;
+ } else if (IOS_DEVICE_TARGET_CPUS.contains(targetCpu)) {
+ return IOS_DEVICE;
+ } else if (MACOSX_TARGET_CPUS.contains(targetCpu)) {
+ return MACOSX;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the platform for the given target cpu.
+ *
+ * @throws IllegalArgumentException if there is no valid apple platform for the given target cpu
+ */
+ public static Platform forTargetCpu(String targetCpu) {
+ Platform platform = forTargetCpuNullable(targetCpu);
+ if (platform != null) {
+ return platform;
+ } else {
+ throw new IllegalArgumentException(
+ "No supported apple platform registered for target cpu " + targetCpu);
+ }
+ }
+
+ /**
+ * Returns true if the given target cpu is an apple platform.
+ */
+ public static boolean isApplePlatform(String targetCpu) {
+ return forTargetCpuNullable(targetCpu) != null;
+ }
}