aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2017-06-02 02:54:37 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-06-02 15:27:18 +0200
commit96180fa5de610990f7ab6df5906b6deb5636df9c (patch)
tree13a5f64ec68db73453d650ed33c03347a23a0b17 /src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java
parentd028d7854d3e95d97143945a1ec32944e5e4594b (diff)
Move helper methods for accessing platform providers to a utility class.
Change-Id: I45d0cf8e5096ad4ab516af5ddaa98eea8d516c04 PiperOrigin-RevId: 157788771
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java34
1 files changed, 4 insertions, 30 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java b/src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java
index 184f7a8a07..87d4b6be7a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java
@@ -14,8 +14,6 @@
package com.google.devtools.build.lib.rules.platform;
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.FileProvider;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
@@ -23,14 +21,13 @@ 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;
-import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
+import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.CPU;
import com.google.devtools.build.lib.util.OS;
-import com.google.devtools.build.lib.util.Preconditions;
import java.util.Map;
/** Defines a platform for execution contexts. */
@@ -46,7 +43,7 @@ public class Platform implements RuleConfiguredTargetFactory {
autodetectHostConstraints(ruleContext, platformBuilder);
} else {
platformBuilder.addConstraints(
- ConstraintValue.constraintValues(
+ PlatformProviderUtils.constraintValues(
ruleContext.getPrerequisites(PlatformRule.CONSTRAINT_VALUES_ATTR, Mode.DONT_CHECK)));
}
@@ -77,7 +74,7 @@ public class Platform implements RuleConfiguredTargetFactory {
// Add the CPU.
CPU cpu = CPU.getCurrent();
Iterable<ConstraintValueInfo> cpuConstraintValues =
- ConstraintValue.constraintValues(
+ PlatformProviderUtils.constraintValues(
ruleContext.getPrerequisites(PlatformRule.HOST_CPU_CONSTRAINTS_ATTR, Mode.DONT_CHECK));
for (ConstraintValueInfo constraint : cpuConstraintValues) {
if (cpu.getCanonicalName().equals(constraint.label().getName())) {
@@ -89,7 +86,7 @@ public class Platform implements RuleConfiguredTargetFactory {
// Add the OS.
OS os = OS.getCurrent();
Iterable<ConstraintValueInfo> osConstraintValues =
- ConstraintValue.constraintValues(
+ PlatformProviderUtils.constraintValues(
ruleContext.getPrerequisites(PlatformRule.HOST_OS_CONSTRAINTS_ATTR, Mode.DONT_CHECK));
for (ConstraintValueInfo constraint : osConstraintValues) {
if (os.getCanonicalName().equals(constraint.label().getName())) {
@@ -98,27 +95,4 @@ public class Platform implements RuleConfiguredTargetFactory {
}
}
}
-
- /** Retrieves and casts the provider from the given target. */
- public static PlatformInfo platform(TransitiveInfoCollection target) {
- Object provider = target.get(PlatformInfo.SKYLARK_IDENTIFIER);
- if (provider == null) {
- return null;
- }
- Preconditions.checkState(provider instanceof PlatformInfo);
- return (PlatformInfo) provider;
- }
-
- /** Retrieves and casts the providers from the given targets. */
- public static Iterable<PlatformInfo> platforms(
- Iterable<? extends TransitiveInfoCollection> targets) {
- return Iterables.transform(
- targets,
- new Function<TransitiveInfoCollection, PlatformInfo>() {
- @Override
- public PlatformInfo apply(TransitiveInfoCollection target) {
- return platform(target);
- }
- });
- }
}