aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/apple
diff options
context:
space:
mode:
authorGravatar cparsons <cparsons@google.com>2018-02-28 12:16:38 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-28 12:18:44 -0800
commite70aafe68eebfd4f7dedf3cccd19deae72d29db6 (patch)
tree7dd211075236b3c06b34b0517852bdd624d8a87d /src/main/java/com/google/devtools/build/lib/rules/apple
parent77c4f30b333106ff15de5b5dd42076db01fd22b4 (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/apple')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigProvider.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java124
2 files changed, 81 insertions, 46 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigProvider.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigProvider.java
index 913e367cd3..50db482da5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfigProvider.java
@@ -14,7 +14,6 @@
package com.google.devtools.build.lib.rules.apple;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
@@ -55,7 +54,7 @@ public class XcodeConfigProvider extends NativeInfo {
DottedVersion tvosSdkVersion, DottedVersion tvosMinimumOsVersion,
DottedVersion macosSdkVersion, DottedVersion macosMinimumOsVersion,
DottedVersion xcodeVersion) {
- super(PROVIDER, ImmutableMap.of());
+ super(PROVIDER);
this.iosSdkVersion = Preconditions.checkNotNull(iosSdkVersion);
this.iosMinimumOsVersion = Preconditions.checkNotNull(iosMinimumOsVersion);
this.watchosSdkVersion = Preconditions.checkNotNull(watchosSdkVersion);
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 073a9f7a9f..c106f45425 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,15 +17,21 @@ 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.common.collect.ImmutableMap;
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 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;
/** A tuple containing information about a version of xcode and its properties. */
@Immutable
+@SkylarkModule(
+ name = "XcodeProperties",
+ category = SkylarkModuleCategory.PROVIDER,
+ doc = "A provider containing information about a version of Xcode and its properties."
+)
public class XcodeVersionProperties extends NativeInfo {
/** Skylark name for the XcodeVersionProperties provider. */
@@ -76,14 +82,7 @@ public class XcodeVersionProperties extends NativeInfo {
@Nullable String defaultWatchosSdkVersion,
@Nullable String defaultTvosSdkVersion,
@Nullable String defaultMacosSdkVersion) {
- super(
- SKYLARK_CONSTRUCTOR,
- getSkylarkFields(
- xcodeVersion,
- defaultIosSdkVersion,
- defaultWatchosSdkVersion,
- defaultTvosSdkVersion,
- defaultMacosSdkVersion));
+ super(SKYLARK_CONSTRUCTOR);
this.xcodeVersion = Optional.fromNullable(xcodeVersion);
this.defaultIosSdkVersion =
(Strings.isNullOrEmpty(defaultIosSdkVersion))
@@ -103,58 +102,95 @@ public class XcodeVersionProperties extends NativeInfo {
: DottedVersion.fromString(defaultMacosSdkVersion);
}
+ /** Returns the xcode version, or null if the xcode version is unknown. */
+ @SkylarkCallable(
+ name = "xcode_version",
+ doc = "The xcode version, or <code>None</code> if the xcode version is unknown.",
+ structField = true,
+ allowReturnNones = true
+ )
+ @Nullable
+ public String getXcodeVersionString() {
+ if (xcodeVersion.isPresent()) {
+ return xcodeVersion.get().toString();
+ }
+ return null;
+ }
+
+ /** Returns the default ios sdk version to use if this xcode version is in use. */
+ @SkylarkCallable(
+ name = "default_ios_sdk_version",
+ doc = "The default iOS sdk version for this version of xcode, or <code>None</code> if "
+ + "unknown.",
+ structField = true,
+ allowReturnNones = true
+ )
+ @Nullable
+ public String getDefaultIosSdkVersionString() {
+ return defaultIosSdkVersion != null ? defaultIosSdkVersion.toString() : null;
+ }
+
+ /** Returns the default watchos sdk version to use if this xcode version is in use. */
+ @SkylarkCallable(
+ name = "default_watchos_sdk_version",
+ doc = "The default watchOS sdk version for this version of xcode, or <code>None</code> if "
+ + "unknown.",
+ structField = true,
+ allowReturnNones = true
+ )
+ @Nullable
+ public String getDefaultWatchosSdkVersionString() {
+ return defaultWatchosSdkVersion != null ? defaultWatchosSdkVersion.toString() : null;
+ }
+
+ /** Returns the default tvos sdk version to use if this xcode version is in use. */
+ @SkylarkCallable(
+ name = "default_tvos_sdk_version",
+ doc = "The default tvOS sdk version for this version of xcode, or <code>None</code> if "
+ + "unknown.",
+ structField = true,
+ allowReturnNones = true
+ )
+ @Nullable
+ public String getDefaultTvosSdkVersionString() {
+ return defaultTvosSdkVersion != null ? defaultTvosSdkVersion.toString() : null;
+ }
+
+ /** Returns the default macosx sdk version to use if this xcode version is in use. */
+ @SkylarkCallable(
+ name = "default_macos_sdk_version",
+ doc = "The default macOS sdk version for this version of xcode, or <code>None</code> if "
+ + "unknown.",
+ structField = true,
+ allowReturnNones = true
+ )
+ @Nullable
+ public String getDefaultMacosSdkVersionString() {
+ return defaultMacosSdkVersion != null ? defaultMacosSdkVersion.toString() : null;
+ }
+
/** Returns the xcode version, or {@link Optional#absent} if the xcode version is unknown. */
public Optional<DottedVersion> getXcodeVersion() {
return xcodeVersion;
}
- /** Returns the default ios sdk version to use if this xcode version is in use. */
+ @Nullable
public DottedVersion getDefaultIosSdkVersion() {
return defaultIosSdkVersion;
}
- /** Returns the default watchos sdk version to use if this xcode version is in use. */
+ @Nullable
public DottedVersion getDefaultWatchosSdkVersion() {
return defaultWatchosSdkVersion;
}
- /** Returns the default tvos sdk version to use if this xcode version is in use. */
+ @Nullable
public DottedVersion getDefaultTvosSdkVersion() {
return defaultTvosSdkVersion;
}
- /** Returns the default macosx sdk version to use if this xcode version is in use. */
+ @Nullable
public DottedVersion getDefaultMacosSdkVersion() {
return defaultMacosSdkVersion;
}
-
- private static Map<String, Object> getSkylarkFields(
- @Nullable DottedVersion xcodeVersion,
- @Nullable String defaultIosSdkVersion,
- @Nullable String defaultWatchosSdkVersion,
- @Nullable String defaultTvosSdkVersion,
- @Nullable String defaultMacosSdkVersion) {
- ImmutableMap.Builder<String, Object> skylarkFields = new ImmutableMap.Builder<>();
- if (xcodeVersion != null) {
- skylarkFields.put("xcode_version", xcodeVersion.toString());
- }
-
- if (defaultIosSdkVersion != null) {
- skylarkFields.put("default_ios_sdk_version", defaultIosSdkVersion);
- }
-
- if (defaultWatchosSdkVersion != null) {
- skylarkFields.put("default_watchos_sdk_version", defaultWatchosSdkVersion);
- }
-
- if (defaultTvosSdkVersion != null) {
- skylarkFields.put("default_tvos_sdk_version", defaultTvosSdkVersion);
- }
-
- if (defaultMacosSdkVersion != null) {
- skylarkFields.put("default_macos_sdk_version", defaultMacosSdkVersion);
- }
-
- return skylarkFields.build();
- }
}