aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/platform
diff options
context:
space:
mode:
authorGravatar John Cater <jcater@google.com>2017-04-05 14:54:40 +0000
committerGravatar Marcel Hlopko <hlopko@google.com>2017-04-06 10:59:46 +0200
commit96580a4f0536dd9fd73f016939e977e76571194f (patch)
tree37375b06cfe5581311266579edbb05435d800abe /src/main/java/com/google/devtools/build/lib/rules/platform
parent2fcd79a76b675ec9ef7c875496a35b529b0e19e1 (diff)
Expose platform-related providers to Skylark.
Change-Id: I7615d3e6e33e0c48f18b2506a135f45ce3705a38 PiperOrigin-RevId: 152256914
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/platform')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/BUILD1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSetting.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingInfo.java92
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingProvider.java31
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValue.java13
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueInfo.java99
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueProvider.java33
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueRule.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/Platform.java37
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java54
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/PlatformInfo.java110
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/PlatformProvider.java45
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java5
13 files changed, 382 insertions, 148 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/BUILD b/src/main/java/com/google/devtools/build/lib/rules/platform/BUILD
index d8c6ca9b79..5808889ba9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/BUILD
@@ -13,6 +13,7 @@ java_library(
deps = [
"//src/main/java/com/google/devtools/build/lib:build-base",
"//src/main/java/com/google/devtools/build/lib:packages",
+ "//src/main/java/com/google/devtools/build/lib:skylarkinterface",
"//third_party:auto_value",
"//third_party:guava",
],
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSetting.java b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSetting.java
index 03e924f1db..653ea2fe4f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSetting.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSetting.java
@@ -20,7 +20,6 @@ import com.google.devtools.build.lib.analysis.FilesToRunProvider;
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.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
/**
@@ -37,9 +36,7 @@ public class ConstraintSetting implements RuleConfiguredTargetFactory {
.addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY)
.addProvider(FileProvider.class, FileProvider.EMPTY)
.addProvider(FilesToRunProvider.class, FilesToRunProvider.EMPTY)
- .addProvider(
- ConstraintSettingProvider.class,
- ConstraintSettingProvider.create(ruleContext.getLabel()))
+ .addNativeDeclaredProvider(ConstraintSettingInfo.create(ruleContext.getLabel()))
.build();
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingInfo.java b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingInfo.java
new file mode 100644
index 0000000000..e921050eba
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingInfo.java
@@ -0,0 +1,92 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.rules.platform;
+
+import com.google.auto.value.AutoValue;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
+import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.ClassObjectConstructor;
+import com.google.devtools.build.lib.packages.NativeClassObjectConstructor;
+import com.google.devtools.build.lib.packages.SkylarkClassObject;
+import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier;
+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 com.google.devtools.build.lib.util.Preconditions;
+
+/** Provider for a platform constraint setting that is available to be fulfilled. */
+@SkylarkModule(
+ name = "ConstraintSettingInfo",
+ doc = "A specific constraint setting that may be used to define a platform.",
+ category = SkylarkModuleCategory.PROVIDER
+)
+@AutoValue
+@Immutable
+public abstract class ConstraintSettingInfo extends SkylarkClassObject {
+
+ /** Name used in Skylark for accessing this provider. */
+ static final String SKYLARK_NAME = "ConstraintSettingInfo";
+
+ /** Skylark constructor and identifier for this provider. */
+ static final ClassObjectConstructor SKYLARK_CONSTRUCTOR =
+ new NativeClassObjectConstructor(SKYLARK_NAME) {};
+
+ /** Identifier used to retrieve this provider from rules which export it. */
+ public static final SkylarkProviderIdentifier SKYLARK_IDENTIFIER =
+ SkylarkProviderIdentifier.forKey(SKYLARK_CONSTRUCTOR.getKey());
+
+ ConstraintSettingInfo() {
+ super(SKYLARK_CONSTRUCTOR, ImmutableMap.<String, Object>of());
+ }
+
+ @SkylarkCallable(
+ name = "label",
+ doc = "The label used to identify this constraint setting.",
+ structField = true
+ )
+ public abstract Label label();
+
+ /** Retrieves and casts the provider from the given target. */
+ public static ConstraintSettingInfo fromTarget(TransitiveInfoCollection target) {
+ Object provider = target.get(SKYLARK_IDENTIFIER);
+ if (provider == null) {
+ return null;
+ }
+ Preconditions.checkState(provider instanceof ConstraintSettingInfo);
+ return (ConstraintSettingInfo) provider;
+ }
+
+ /** Retrieves and casts the providers from the given targets. */
+ public static Iterable<ConstraintSettingInfo> fromTargets(
+ Iterable<? extends TransitiveInfoCollection> targets) {
+ return Iterables.transform(
+ targets,
+ new Function<TransitiveInfoCollection, ConstraintSettingInfo>() {
+ @Override
+ public ConstraintSettingInfo apply(TransitiveInfoCollection target) {
+ return fromTarget(target);
+ }
+ });
+ }
+
+ /** Returns a new {@link ConstraintSettingInfo} with the given data. */
+ public static ConstraintSettingInfo create(Label constraintSetting) {
+ return new AutoValue_ConstraintSettingInfo(constraintSetting);
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingProvider.java b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingProvider.java
deleted file mode 100644
index 9459a07e91..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingProvider.java
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.rules.platform;
-
-import com.google.auto.value.AutoValue;
-import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-
-/** Provider for a platform constraint setting that is available to be fulfilled. */
-@AutoValue
-@Immutable
-public abstract class ConstraintSettingProvider implements TransitiveInfoProvider {
- public abstract Label constraintSetting();
-
- public static ConstraintSettingProvider create(Label constraintSetting) {
- return new AutoValue_ConstraintSettingProvider(constraintSetting);
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValue.java b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValue.java
index c232c92212..e1aa6d933b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValue.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValue.java
@@ -30,19 +30,16 @@ public class ConstraintValue implements RuleConfiguredTargetFactory {
public ConfiguredTarget create(RuleContext ruleContext)
throws InterruptedException, RuleErrorException {
- ConstraintSettingProvider constraint =
- ruleContext.getPrerequisite(
- ConstraintValueRule.CONSTRAINT_SETTING_ATTR,
- Mode.DONT_CHECK,
- ConstraintSettingProvider.class);
+ ConstraintSettingInfo constraint =
+ ConstraintSettingInfo.fromTarget(
+ ruleContext.getPrerequisite(
+ ConstraintValueRule.CONSTRAINT_SETTING_ATTR, Mode.DONT_CHECK));
return new RuleConfiguredTargetBuilder(ruleContext)
.addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY)
.addProvider(FileProvider.class, FileProvider.EMPTY)
.addProvider(FilesToRunProvider.class, FilesToRunProvider.EMPTY)
- .addProvider(
- ConstraintValueProvider.class,
- ConstraintValueProvider.create(constraint, ruleContext.getLabel()))
+ .addNativeDeclaredProvider(ConstraintValueInfo.create(constraint, ruleContext.getLabel()))
.build();
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueInfo.java b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueInfo.java
new file mode 100644
index 0000000000..f2cecb277e
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueInfo.java
@@ -0,0 +1,99 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.rules.platform;
+
+import com.google.auto.value.AutoValue;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
+import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.ClassObjectConstructor;
+import com.google.devtools.build.lib.packages.NativeClassObjectConstructor;
+import com.google.devtools.build.lib.packages.SkylarkClassObject;
+import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier;
+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 com.google.devtools.build.lib.util.Preconditions;
+
+/** Provider for a platform constraint value that fulfills a {@link ConstraintSettingInfo}. */
+@SkylarkModule(
+ name = "ConstraintValueProvider",
+ doc = "A value for a constraint setting that can be used to define a platform.",
+ category = SkylarkModuleCategory.PROVIDER
+)
+@AutoValue
+@Immutable
+public abstract class ConstraintValueInfo extends SkylarkClassObject {
+
+ /** Name used in Skylark for accessing this provider. */
+ static final String SKYLARK_NAME = "ConstraintValueInfo";
+
+ /** Skylark constructor and identifier for this provider. */
+ static final ClassObjectConstructor SKYLARK_CONSTRUCTOR =
+ new NativeClassObjectConstructor(SKYLARK_NAME) {};
+
+ /** Identifier used to retrieve this provider from rules which export it. */
+ public static final SkylarkProviderIdentifier SKYLARK_IDENTIFIER =
+ SkylarkProviderIdentifier.forKey(SKYLARK_CONSTRUCTOR.getKey());
+
+ ConstraintValueInfo() {
+ super(SKYLARK_CONSTRUCTOR, ImmutableMap.<String, Object>of());
+ }
+
+ @SkylarkCallable(
+ name = "constraint",
+ doc = "The constraint setting that this value fulfills.",
+ structField = true
+ )
+ public abstract ConstraintSettingInfo constraint();
+
+ @SkylarkCallable(
+ name = "label",
+ doc = "The label used to identify this constraint value.",
+ structField = true
+ )
+ public abstract Label label();
+
+ /** Retrieves and casts the provider from the given target. */
+ public static ConstraintValueInfo fromTarget(TransitiveInfoCollection target) {
+ Object provider = target.get(SKYLARK_IDENTIFIER);
+ if (provider == null) {
+ return null;
+ }
+ Preconditions.checkState(provider instanceof ConstraintValueInfo);
+ return (ConstraintValueInfo) provider;
+ }
+
+ /** Retrieves and casts the providers from the given targets. */
+ public static Iterable<ConstraintValueInfo> fromTargets(
+ Iterable<? extends TransitiveInfoCollection> targets) {
+ return Iterables.transform(
+ targets,
+ new Function<TransitiveInfoCollection, ConstraintValueInfo>() {
+ @Override
+ public ConstraintValueInfo apply(TransitiveInfoCollection target) {
+ return fromTarget(target);
+ }
+ });
+ }
+
+ /** Returns a new {@link ConstraintValueInfo} with the given data. */
+ public static ConstraintValueInfo create(ConstraintSettingInfo constraint, Label value) {
+ return new AutoValue_ConstraintValueInfo(constraint, value);
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueProvider.java b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueProvider.java
deleted file mode 100644
index 1ade6ddded..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueProvider.java
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.rules.platform;
-
-import com.google.auto.value.AutoValue;
-import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-
-/** Provider for a platform constraint value that fulfills a {@link ConstraintSettingProvider}. */
-@AutoValue
-@Immutable
-public abstract class ConstraintValueProvider implements TransitiveInfoProvider {
- public abstract ConstraintSettingProvider constraint();
-
- public abstract Label value();
-
- public static ConstraintValueProvider create(ConstraintSettingProvider constraint, Label value) {
- return new AutoValue_ConstraintValueProvider(constraint, value);
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueRule.java b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueRule.java
index 55e85b1048..5593862754 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueRule.java
@@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.syntax.Type;
@@ -48,9 +47,7 @@ public class ConstraintValueRule implements RuleDefinition {
.mandatory()
.allowedRuleClasses(ConstraintSettingRule.RULE_NAME)
.allowedFileTypes(FileTypeSet.NO_FILE)
- .mandatoryNativeProviders(
- ImmutableList.<Class<? extends TransitiveInfoProvider>>of(
- ConstraintSettingProvider.class)))
+ .mandatoryProviders(ImmutableList.of(ConstraintSettingInfo.SKYLARK_IDENTIFIER)))
.removeAttribute("deps")
.removeAttribute("data")
.exemptFromConstraintChecking("this rule *defines* a constraint")
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 f5d7e88832..b029240e26 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
@@ -35,20 +35,20 @@ public class Platform implements RuleConfiguredTargetFactory {
public ConfiguredTarget create(RuleContext ruleContext)
throws InterruptedException, RuleErrorException {
- Iterable<ConstraintValueProvider> constraintValues =
- ruleContext.getPrerequisites(
- PlatformRule.CONSTRAINT_VALUES_ATTR, Mode.DONT_CHECK, ConstraintValueProvider.class);
+ Iterable<ConstraintValueInfo> constraintValues =
+ ConstraintValueInfo.fromTargets(
+ ruleContext.getPrerequisites(PlatformRule.CONSTRAINT_VALUES_ATTR, Mode.DONT_CHECK));
// Verify the constraints - no two values for the same setting, and construct the map.
- ImmutableMap<ConstraintSettingProvider, ConstraintValueProvider> constraints =
+ ImmutableMap<ConstraintSettingInfo, ConstraintValueInfo> constraints =
validateConstraints(ruleContext, constraintValues);
if (constraints == null) {
// An error occurred, return null.
return null;
}
- PlatformProvider.Builder platformProviderBuilder = PlatformProvider.builder();
- platformProviderBuilder.constraints(constraints);
+ PlatformInfo.Builder platformProviderBuilder = PlatformInfo.builder();
+ platformProviderBuilder.constraints(constraints.values());
Map<String, String> remoteExecutionProperties =
ruleContext.attributes().get(PlatformRule.REMOTE_EXECUTION_PROPS_ATTR, Type.STRING_DICT);
@@ -58,37 +58,36 @@ public class Platform implements RuleConfiguredTargetFactory {
.addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY)
.addProvider(FileProvider.class, FileProvider.EMPTY)
.addProvider(FilesToRunProvider.class, FilesToRunProvider.EMPTY)
- .addProvider(PlatformProvider.class, platformProviderBuilder.build())
+ .addNativeDeclaredProvider(platformProviderBuilder.build())
.build();
}
- private ImmutableMap<ConstraintSettingProvider, ConstraintValueProvider> validateConstraints(
- RuleContext ruleContext, Iterable<ConstraintValueProvider> constraintValues) {
- Multimap<ConstraintSettingProvider, ConstraintValueProvider> constraints =
- ArrayListMultimap.create();
+ private ImmutableMap<ConstraintSettingInfo, ConstraintValueInfo> validateConstraints(
+ RuleContext ruleContext, Iterable<ConstraintValueInfo> constraintValues) {
+ Multimap<ConstraintSettingInfo, ConstraintValueInfo> constraints = ArrayListMultimap.create();
- for (ConstraintValueProvider constraintValue : constraintValues) {
+ for (ConstraintValueInfo constraintValue : constraintValues) {
constraints.put(constraintValue.constraint(), constraintValue);
}
// Are there any settings with more than one value?
boolean foundError = false;
- for (ConstraintSettingProvider constraintSetting : constraints.keySet()) {
+ for (ConstraintSettingInfo constraintSetting : constraints.keySet()) {
if (constraints.get(constraintSetting).size() > 1) {
foundError = true;
// error
StringBuilder constraintValuesDescription = new StringBuilder();
- for (ConstraintValueProvider constraintValue : constraints.get(constraintSetting)) {
+ for (ConstraintValueInfo constraintValue : constraints.get(constraintSetting)) {
if (constraintValuesDescription.length() > 0) {
constraintValuesDescription.append(", ");
}
- constraintValuesDescription.append(constraintValue.value());
+ constraintValuesDescription.append(constraintValue.label());
}
ruleContext.attributeError(
PlatformRule.CONSTRAINT_VALUES_ATTR,
String.format(
"Duplicate constraint_values for constraint_setting %s: %s",
- constraintSetting.constraintSetting(), constraintValuesDescription.toString()));
+ constraintSetting.label(), constraintValuesDescription.toString()));
}
}
@@ -97,10 +96,10 @@ public class Platform implements RuleConfiguredTargetFactory {
}
// Convert to a flat map.
- ImmutableMap.Builder<ConstraintSettingProvider, ConstraintValueProvider> builder =
+ ImmutableMap.Builder<ConstraintSettingInfo, ConstraintValueInfo> builder =
new ImmutableMap.Builder<>();
- for (ConstraintSettingProvider constraintSetting : constraints.keySet()) {
- ConstraintValueProvider constraintValue =
+ for (ConstraintSettingInfo constraintSetting : constraints.keySet()) {
+ ConstraintValueInfo constraintValue =
Iterables.getOnlyElement(constraints.get(constraintSetting));
builder.put(constraintSetting, constraintValue);
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java
new file mode 100644
index 0000000000..ff4b0c3dfe
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java
@@ -0,0 +1,54 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.rules.platform;
+
+import com.google.devtools.build.lib.packages.ClassObjectConstructor;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+
+/** Skylark namespace used to interact with Blaze's platform APIs. */
+@SkylarkModule(
+ name = "platform_common",
+ doc = "Functions for Skylark to interact with Blaze's platform APIs."
+)
+public class PlatformCommon {
+
+ @SkylarkCallable(
+ name = PlatformInfo.SKYLARK_NAME,
+ doc = "The key used to retrieve the provider containing platform_info's value.",
+ structField = true
+ )
+ public ClassObjectConstructor getPlatformInfoConstructor() {
+ return PlatformInfo.SKYLARK_CONSTRUCTOR;
+ }
+
+ @SkylarkCallable(
+ name = ConstraintSettingInfo.SKYLARK_NAME,
+ doc = "The key used to retrieve the provider containing constraint_setting_info's value.",
+ structField = true
+ )
+ public ClassObjectConstructor getConstraintSettingInfoConstructor() {
+ return ConstraintSettingInfo.SKYLARK_CONSTRUCTOR;
+ }
+
+ @SkylarkCallable(
+ name = ConstraintValueInfo.SKYLARK_NAME,
+ doc = "The key used to retrieve the provider containing constraint_value_info's value.",
+ structField = true
+ )
+ public ClassObjectConstructor getConstraintValueInfoConstructor() {
+ return ConstraintValueInfo.SKYLARK_CONSTRUCTOR;
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformInfo.java b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformInfo.java
new file mode 100644
index 0000000000..7fe10724da
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformInfo.java
@@ -0,0 +1,110 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.rules.platform;
+
+import com.google.auto.value.AutoValue;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
+import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.ClassObjectConstructor;
+import com.google.devtools.build.lib.packages.NativeClassObjectConstructor;
+import com.google.devtools.build.lib.packages.SkylarkClassObject;
+import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier;
+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 com.google.devtools.build.lib.util.Preconditions;
+import java.util.Map;
+
+/** Provider for a platform, which is a group of constraints and values. */
+@SkylarkModule(
+ name = "PlatformInfo",
+ doc = "Provides access to data about a specific platform.",
+ category = SkylarkModuleCategory.PROVIDER
+)
+@AutoValue
+@Immutable
+public abstract class PlatformInfo extends SkylarkClassObject {
+
+ /** Name used in Skylark for accessing this provider. */
+ static final String SKYLARK_NAME = "PlatformInfo";
+
+ /** Skylark constructor and identifier for this provider. */
+ static final ClassObjectConstructor SKYLARK_CONSTRUCTOR =
+ new NativeClassObjectConstructor(SKYLARK_NAME) {};
+
+ /** Identifier used to retrieve this provider from rules which export it. */
+ public static final SkylarkProviderIdentifier SKYLARK_IDENTIFIER =
+ SkylarkProviderIdentifier.forKey(SKYLARK_CONSTRUCTOR.getKey());
+
+ PlatformInfo() {
+ super(SKYLARK_CONSTRUCTOR, ImmutableMap.<String, Object>of());
+ }
+
+ @SkylarkCallable(
+ name = "constraints",
+ doc = "The constraint values fulfilled by this Platform.",
+ structField = true
+ )
+ public abstract ImmutableList<ConstraintValueInfo> constraints();
+
+ @SkylarkCallable(
+ name = "remoteExecutionProperties",
+ doc = "Properties that are available for the use of remote execution.",
+ structField = true
+ )
+ public abstract ImmutableMap<String, String> remoteExecutionProperties();
+
+ /** Retrieves and casts the provider from the given target. */
+ public static PlatformInfo fromTarget(TransitiveInfoCollection target) {
+ Object provider = target.get(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> fromTargets(
+ Iterable<? extends TransitiveInfoCollection> targets) {
+ return Iterables.transform(
+ targets,
+ new Function<TransitiveInfoCollection, PlatformInfo>() {
+ @Override
+ public PlatformInfo apply(TransitiveInfoCollection target) {
+ return fromTarget(target);
+ }
+ });
+ }
+
+ /** Returns a {@link Builder} to create a new provider instance. */
+ public static Builder builder() {
+ return new AutoValue_PlatformInfo.Builder();
+ }
+
+ /** A Builder instance to configure a new {@link PlatformInfo}. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ public abstract Builder constraints(Iterable<ConstraintValueInfo> constraints);
+
+ public abstract Builder remoteExecutionProperties(Map<String, String> properties);
+
+ public abstract PlatformInfo build();
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformProvider.java b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformProvider.java
deleted file mode 100644
index 1cf5b5017f..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformProvider.java
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.rules.platform;
-
-import com.google.auto.value.AutoValue;
-import com.google.common.collect.ImmutableMap;
-import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import java.util.Map;
-
-/** Provider for a platform, which is a group of constraints and values. */
-@AutoValue
-@Immutable
-public abstract class PlatformProvider implements TransitiveInfoProvider {
- public abstract ImmutableMap<ConstraintSettingProvider, ConstraintValueProvider> constraints();
-
- public abstract ImmutableMap<String, String> remoteExecutionProperties();
-
- public static Builder builder() {
- return new AutoValue_PlatformProvider.Builder();
- }
-
- /** A Builder instance to configure a new {@link PlatformProvider}. */
- @AutoValue.Builder
- public abstract static class Builder {
- public abstract Builder constraints(
- Map<ConstraintSettingProvider, ConstraintValueProvider> constraints);
-
- public abstract Builder remoteExecutionProperties(Map<String, String> properties);
-
- public abstract PlatformProvider build();
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java
index fd965ee171..cd332435ca 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java
@@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.syntax.Type;
@@ -45,9 +44,7 @@ public class PlatformRule implements RuleDefinition {
.add(
attr(CONSTRAINT_VALUES_ATTR, BuildType.LABEL_LIST)
.allowedFileTypes(FileTypeSet.NO_FILE)
- .mandatoryNativeProviders(
- ImmutableList.<Class<? extends TransitiveInfoProvider>>of(
- ConstraintValueProvider.class)))
+ .mandatoryProviders(ImmutableList.of(ConstraintValueInfo.SKYLARK_IDENTIFIER)))
.add(attr(REMOTE_EXECUTION_PROPS_ATTR, Type.STRING_DICT))
.removeAttribute("deps")
.removeAttribute("data")