diff options
author | 2018-02-28 12:16:38 -0800 | |
---|---|---|
committer | 2018-02-28 12:18:44 -0800 | |
commit | e70aafe68eebfd4f7dedf3cccd19deae72d29db6 (patch) | |
tree | 7dd211075236b3c06b34b0517852bdd624d8a87d /src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java | |
parent | 77c4f30b333106ff15de5b5dd42076db01fd22b4 (diff) |
Deprecate and remove several uses of the 'values' map in NativeInfo subclasses.
These subclasses should be using @SkylarkCallable(structField = true) instead
This is a bit of a memory win, as there is now no need to store field information twice.
There are still a couple of stragglers that are more difficult, namely ToolchainInfo and DefaultInfo. Their APIs will likely need some more extensive revamping before proceeding.
RELNOTES: None.
PiperOrigin-RevId: 187364392
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/IosDeviceProvider.java | 48 |
1 files changed, 34 insertions, 14 deletions
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 1ce7085140..bbd98f7943 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 @@ -16,17 +16,23 @@ package com.google.devtools.build.lib.rules.objc; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction.Substitution; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.packages.NativeInfo; import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.rules.apple.DottedVersion; -import java.util.Map; +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; import javax.annotation.Nullable; /** Provider that describes a simulator device. */ @Immutable +@SkylarkModule( + name = "IosDevice", + category = SkylarkModuleCategory.PROVIDER, + doc = "<b>Deprecated. Use the new Skylark testing rules instead.</b>" +) public final class IosDeviceProvider extends NativeInfo { /** A builder of {@link IosDeviceProvider}s. */ public static final class Builder { @@ -85,13 +91,38 @@ public final class IosDeviceProvider extends NativeInfo { private final String locale; private IosDeviceProvider(Builder builder) { - super(SKYLARK_CONSTRUCTOR, getSkylarkFields(builder)); + super(SKYLARK_CONSTRUCTOR); this.type = Preconditions.checkNotNull(builder.type); this.iosVersion = Preconditions.checkNotNull(builder.iosVersion); this.locale = Preconditions.checkNotNull(builder.locale); this.xcodeVersion = builder.xcodeVersion; } + @SkylarkCallable( + name = "ios_version", + doc = "The iOS version of the simulator to use.", + structField = true + ) + public String getIosVersionString() { + return iosVersion.toString(); + } + + @SkylarkCallable( + name = "xcode_version", + doc = "The xcode version to obtain the iOS simulator from, or <code>None</code> if unknown.", + structField = true, + allowReturnNones = true + ) + @Nullable + public String getXcodeVersionString() { + return xcodeVersion != null ? xcodeVersion.toString() : null; + } + + @SkylarkCallable( + name = "type", + doc = "The hardware type of the device, corresponding to the simctl device type.", + structField = true + ) public String getType() { return type; } @@ -120,15 +151,4 @@ public final class IosDeviceProvider extends NativeInfo { Substitution.of("%(simulator_sdk)s", getIosVersion().toString()), Substitution.of("%(locale)s", getLocale()))); } - - private static Map<String, Object> getSkylarkFields(Builder builder) { - ImmutableMap.Builder<String, Object> skylarkFields = - new ImmutableMap.Builder<String, Object>() - .put("type", builder.type) - .put("ios_version", builder.iosVersion.toString()); - if (builder.xcodeVersion != null) { - skylarkFields.put("xcode_version", builder.xcodeVersion.toString()); - } - return skylarkFields.build(); - } } |