diff options
Diffstat (limited to 'src/main/java/com/google')
7 files changed, 97 insertions, 15 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 41fe05d8df..562a82229e 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 @@ -41,6 +41,11 @@ import javax.annotation.Nullable; @SkylarkModule(name = "apple", doc = "A configuration fragment for Apple platforms") @Immutable public class AppleConfiguration extends BuildConfiguration.Fragment { + /** + * Environment variable name for the xcode version. The value of this environment variable should + * be set to the version (for example, "7.2") of xcode to use when invoking part of the apple + * toolkit in action execution. + **/ public static final String XCODE_VERSION_ENV_NAME = "XCODE_VERSION_OVERRIDE"; /** * Environment variable name for the apple SDK version. If unset, uses the system default of the @@ -158,11 +163,20 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { ) public Map<String, String> getAppleHostSystemEnv() { Optional<DottedVersion> xcodeVersion = getXcodeVersion(); - ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); if (xcodeVersion.isPresent()) { - builder.put(AppleConfiguration.XCODE_VERSION_ENV_NAME, xcodeVersion.get().toString()); + return getXcodeVersionEnv(xcodeVersion.get()); + } else { + return ImmutableMap.of(); } - return builder.build(); + } + + /** + * Returns a map of environment variables that should be propagated for actions that require + * a version of xcode to be explicitly declared. Keys are variable names and values are their + * corresponding values. + */ + public Map<String, String> getXcodeVersionEnv(DottedVersion xcodeVersion) { + return ImmutableMap.of(AppleConfiguration.XCODE_VERSION_ENV_NAME, xcodeVersion.toString()); } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersion.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersion.java index f7e321f285..b630f5de40 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersion.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersion.java @@ -27,8 +27,12 @@ public class XcodeVersion implements RuleConfiguredTargetFactory { @Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException { + XcodeVersionRuleData ruleData = + new XcodeVersionRuleData(ruleContext.getLabel(), ruleContext.getRule()); + return new RuleConfiguredTargetBuilder(ruleContext) .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) + .addProvider(XcodeVersionProperties.class, ruleData.getXcodeVersionProperties()) .build(); } }
\ No newline at end of file diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java index 5da51a5b41..572574db1d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java @@ -17,13 +17,14 @@ package com.google.devtools.build.lib.rules.apple; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import com.google.common.base.Strings; +import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import javax.annotation.Nullable; /** * A tuple containing information about a version of xcode and its properties. */ -public class XcodeVersionProperties { +public class XcodeVersionProperties implements TransitiveInfoProvider { @VisibleForTesting public static final String DEFAULT_IOS_SDK_VERSION = "8.4"; @VisibleForTesting public static final String DEFAULT_WATCHOS_SDK_VERSION = "2.0"; @VisibleForTesting public static final String DEFAULT_MACOSX_SDK_VERSION = "10.10"; diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java index 8d3bd78221..97bfa97960 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDevice.java @@ -18,6 +18,7 @@ import static com.google.devtools.build.lib.syntax.Type.STRING; import com.google.common.base.Strings; import com.google.devtools.build.lib.analysis.ConfiguredTarget; +import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesProvider; @@ -25,6 +26,7 @@ import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.DottedVersion; import com.google.devtools.build.lib.rules.apple.Platform; +import com.google.devtools.build.lib.rules.apple.XcodeVersionProperties; /** * Implementation for the "ios_device" rule. @@ -32,20 +34,34 @@ import com.google.devtools.build.lib.rules.apple.Platform; public final class IosDevice implements RuleConfiguredTargetFactory { @Override public ConfiguredTarget create(RuleContext context) throws InterruptedException { - String iosVersionAttribute = context.attributes().get("ios_version", STRING); + AppleConfiguration appleConfiguration = context.getFragment(AppleConfiguration.class); + String iosVersionAttribute = + context.attributes().get(IosDeviceRule.IOS_VERSION_ATTR_NAME, STRING); + XcodeVersionProperties xcodeVersionProperties = context.getPrerequisite( + IosDeviceRule.XCODE_ATTR_NAME, Mode.TARGET, XcodeVersionProperties.class); + + DottedVersion xcodeVersion = null; + if (xcodeVersionProperties != null && xcodeVersionProperties.getXcodeVersion().isPresent()) { + xcodeVersion = xcodeVersionProperties.getXcodeVersion().get(); + } else if (appleConfiguration.getXcodeVersion().isPresent()) { + xcodeVersion = appleConfiguration.getXcodeVersion().get(); + } + DottedVersion iosVersion; if (!Strings.isNullOrEmpty(iosVersionAttribute)) { iosVersion = DottedVersion.fromString(iosVersionAttribute); + } else if (xcodeVersionProperties != null) { + iosVersion = xcodeVersionProperties.getDefaultIosSdkVersion(); } else { - iosVersion = context.getFragment(AppleConfiguration.class) - .getSdkVersionForPlatform(Platform.IOS_SIMULATOR); + iosVersion = appleConfiguration.getSdkVersionForPlatform(Platform.IOS_SIMULATOR); } IosDeviceProvider provider = new IosDeviceProvider.Builder() - .setType(context.attributes().get("type", STRING)) + .setType(context.attributes().get(IosDeviceRule.TYPE_ATTR_NAME, STRING)) .setIosVersion(iosVersion) - .setLocale(context.attributes().get("locale", STRING)) + .setLocale(context.attributes().get(IosDeviceRule.LOCALE_ATTR_NAME, STRING)) + .setXcodeVersion(xcodeVersion) .build(); return new RuleConfiguredTargetBuilder(context) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java index 26f736091e..2f62c5dea3 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java @@ -21,6 +21,8 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.rules.apple.DottedVersion; import com.google.devtools.build.lib.util.Preconditions; +import javax.annotation.Nullable; + /** * Provider that describes a simulator device. */ @@ -31,17 +33,35 @@ public final class IosDeviceProvider implements TransitiveInfoProvider { private String type; private DottedVersion iosVersion; private String locale; + @Nullable + private DottedVersion xcodeVersion; + /** + * Sets the hardware type of the device, corresponding to the {@code simctl} device type. + */ public Builder setType(String type) { this.type = type; return this; } + /** + * Sets the iOS version of the simulator to use. This may be different than the iOS sdk version + * used to build the application. + */ public Builder setIosVersion(DottedVersion iosVersion) { this.iosVersion = iosVersion; return this; } + /** + * Sets the xcode version to obtain the iOS simulator from. This may be different than the + * xcode version with which the application was built. + */ + public Builder setXcodeVersion(@Nullable DottedVersion xcodeVersion) { + this.xcodeVersion = xcodeVersion; + return this; + } + public Builder setLocale(String locale) { this.locale = locale; return this; @@ -54,12 +74,14 @@ public final class IosDeviceProvider implements TransitiveInfoProvider { private final String type; private final DottedVersion iosVersion; + private final DottedVersion xcodeVersion; private final String locale; private IosDeviceProvider(Builder builder) { this.type = Preconditions.checkNotNull(builder.type); this.iosVersion = Preconditions.checkNotNull(builder.iosVersion); this.locale = Preconditions.checkNotNull(builder.locale); + this.xcodeVersion = builder.xcodeVersion; } public String getType() { @@ -70,6 +92,11 @@ public final class IosDeviceProvider implements TransitiveInfoProvider { return iosVersion; } + @Nullable + public DottedVersion getXcodeVersion() { + return xcodeVersion; + } + public String getLocale() { return locale; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java index 87a11bad50..0ee0d04a69 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceRule.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.rules.objc; import static com.google.devtools.build.lib.packages.Attribute.attr; +import static com.google.devtools.build.lib.packages.BuildType.LABEL; import static com.google.devtools.build.lib.syntax.Type.STRING; import com.google.devtools.build.lib.analysis.BaseRuleClasses; @@ -28,22 +29,36 @@ import com.google.devtools.build.lib.rules.apple.AppleConfiguration; * Rule definition for ios_device. */ public final class IosDeviceRule implements RuleDefinition { + static final String IOS_VERSION_ATTR_NAME = "ios_version"; + static final String XCODE_ATTR_NAME = "xcode"; + static final String TYPE_ATTR_NAME = "type"; + static final String LOCALE_ATTR_NAME = "locale"; + @Override public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { return builder .requiresConfigurationFragments(AppleConfiguration.class) /* <!-- #BLAZE_RULE(ios_device).ATTRIBUTE(ios_version) --> The operating system version of the device. This corresponds to the - <code>simctl</code> runtime. Defaults to the ios sdk version configuration value. + <code>simctl</code> runtime. Defaults to the default ios sdk version for the xcode + version defined in the <code>xcode</code> attribute, or uses the ios sdk version + configuration value, if <code>xcode</code> is unspecified. + <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ + .add(attr(IOS_VERSION_ATTR_NAME, STRING)) + /* <!-- #BLAZE_RULE(ios_device).ATTRIBUTE(xcode) --> + The version of xcode to use to run the simulator. Defaults to the xcode version build + configuration value. <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr("ios_version", STRING)) + .add(attr(XCODE_ATTR_NAME, LABEL) + .allowedRuleClasses("xcode_version") + .allowedFileTypes()) /* <!-- #BLAZE_RULE(ios_device).ATTRIBUTE(type) --> The hardware type. This corresponds to the <code>simctl</code> device type. <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/ - .add(attr("type", STRING) + .add(attr(TYPE_ATTR_NAME, STRING) .mandatory()) - .add(attr("locale", STRING) + .add(attr(LOCALE_ATTR_NAME, STRING) .undocumented("this is not yet supported by any test runner") .value("en")) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java index ba0c5a14c9..fd94eab868 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/TestSupport.java @@ -34,6 +34,7 @@ import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction.Su import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; +import com.google.devtools.build.lib.rules.apple.DottedVersion; import com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider; import com.google.devtools.build.lib.rules.test.TestEnvironmentProvider; import com.google.devtools.build.lib.syntax.Type; @@ -251,12 +252,16 @@ public class TestSupport { * builder. */ public Map<Class<? extends TransitiveInfoProvider>, TransitiveInfoProvider> getExtraProviders() { + IosDeviceProvider deviceProvider = + ruleContext.getPrerequisite(IosTest.TARGET_DEVICE, Mode.TARGET, IosDeviceProvider.class); + DottedVersion xcodeVersion = deviceProvider.getXcodeVersion(); AppleConfiguration configuration = ruleContext.getFragment(AppleConfiguration.class); ImmutableMap.Builder<String, String> envBuilder = ImmutableMap.builder(); - envBuilder.putAll(configuration.getTargetAppleEnvironment(configuration.getIosCpuPlatform())); - envBuilder.putAll(configuration.getAppleHostSystemEnv()); + if (xcodeVersion != null) { + envBuilder.putAll(configuration.getXcodeVersionEnv(xcodeVersion)); + } if (ruleContext.getConfiguration().isCodeCoverageEnabled()) { envBuilder.put("COVERAGE_GCOV_PATH", |