diff options
author | John Cater <jcater@google.com> | 2017-05-01 17:41:12 +0200 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2017-05-02 11:25:44 +0200 |
commit | 248581e8c72687c85b5c41edaea6780c8701aa55 (patch) | |
tree | f62dd1831c79c9c886cbeeebefedb1e3319f155a /src/main/java/com/google/devtools/build/lib | |
parent | 38b835097f9ae9a6062172b8a33ec2e2d1edde20 (diff) |
Move platform providers to a new package to break cyclic dependencies.
Part of #2219.
Change-Id: I87c7bc9fbfb38d3dbdf193b46247901d0f2a838d
PiperOrigin-RevId: 154719063
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
13 files changed, 146 insertions, 135 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 6e0fb14e40..02086d9fae 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -35,6 +35,7 @@ filegroup( "//src/main/java/com/google/devtools/build/lib/rules/genquery:srcs", "//src/main/java/com/google/devtools/build/lib/rules/genrule:srcs", "//src/main/java/com/google/devtools/build/lib/rules/objc:srcs", + "//src/main/java/com/google/devtools/build/lib/analysis/platform:srcs", "//src/main/java/com/google/devtools/build/lib/rules/platform:srcs", "//src/main/java/com/google/devtools/build/lib/sandbox:srcs", "//src/main/java/com/google/devtools/build/lib/ssd:srcs", @@ -1221,6 +1222,7 @@ filegroup( "//src/main/java/com/google/devtools/build/lib/rules/genquery:srcs", "//src/main/java/com/google/devtools/build/lib/rules/genrule:srcs", "//src/main/java/com/google/devtools/build/lib/rules/objc:srcs", + "//src/main/java/com/google/devtools/build/lib/analysis/platform:srcs", "//src/main/java/com/google/devtools/build/lib/rules/platform:srcs", ], ) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/platform/BUILD new file mode 100644 index 0000000000..ce3a69d759 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/BUILD @@ -0,0 +1,24 @@ +# Description: +# Providers defined for platforms, constraints, and toolchains. + +package( + default_visibility = ["//src:__subpackages__"], +) + +java_library( + name = "platform", + srcs = glob([ + "*.java", + ]), + deps = [ + "//src/main/java/com/google/devtools/build/lib:packages", + "//src/main/java/com/google/devtools/build/lib:skylarkinterface", + "//third_party:guava", + ], +) + +filegroup( + name = "srcs", + testonly = 0, # All srcs should be not test only, overwrite package default. + srcs = glob(["**"]), +) diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintSettingInfo.java index 3b203e64ca..817580e8fa 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintSettingInfo.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintSettingInfo.java @@ -12,12 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.devtools.build.lib.rules.platform; +package com.google.devtools.build.lib.analysis.platform; -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; @@ -26,7 +23,6 @@ import com.google.devtools.build.lib.packages.SkylarkClassObject; import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier; 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( @@ -38,10 +34,10 @@ import com.google.devtools.build.lib.util.Preconditions; public class ConstraintSettingInfo extends SkylarkClassObject { /** Name used in Skylark for accessing this provider. */ - static final String SKYLARK_NAME = "ConstraintSettingInfo"; + public static final String SKYLARK_NAME = "ConstraintSettingInfo"; /** Skylark constructor and identifier for this provider. */ - static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = + public static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = new NativeClassObjectConstructor(SKYLARK_NAME) {}; /** Identifier used to retrieve this provider from rules which export it. */ @@ -60,29 +56,6 @@ public class ConstraintSettingInfo extends SkylarkClassObject { return 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 ConstraintSettingInfo(constraintSetting); diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfo.java index 36854ffbfd..9e58126264 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/platform/ConstraintValueInfo.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfo.java @@ -12,12 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.devtools.build.lib.rules.platform; +package com.google.devtools.build.lib.analysis.platform; -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; @@ -26,7 +23,6 @@ import com.google.devtools.build.lib.packages.SkylarkClassObject; import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier; 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( @@ -38,10 +34,10 @@ import com.google.devtools.build.lib.util.Preconditions; public class ConstraintValueInfo extends SkylarkClassObject { /** Name used in Skylark for accessing this provider. */ - static final String SKYLARK_NAME = "ConstraintValueInfo"; + public static final String SKYLARK_NAME = "ConstraintValueInfo"; /** Skylark constructor and identifier for this provider. */ - static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = + public static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = new NativeClassObjectConstructor(SKYLARK_NAME) {}; /** Identifier used to retrieve this provider from rules which export it. */ @@ -70,29 +66,6 @@ public class ConstraintValueInfo extends SkylarkClassObject { return 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 ConstraintValueInfo(constraint, value); diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformInfo.java index 3f980733cf..64b9262adb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformInfo.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformInfo.java @@ -12,16 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.devtools.build.lib.rules.platform; +package com.google.devtools.build.lib.analysis.platform; -import com.google.common.base.Function; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; -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; @@ -30,7 +27,6 @@ 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.ArrayList; import java.util.HashMap; import java.util.List; @@ -46,10 +42,10 @@ import java.util.Map; public class PlatformInfo extends SkylarkClassObject { /** Name used in Skylark for accessing this provider. */ - static final String SKYLARK_NAME = "PlatformInfo"; + public static final String SKYLARK_NAME = "PlatformInfo"; /** Skylark constructor and identifier for this provider. */ - static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = + public static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = new NativeClassObjectConstructor(SKYLARK_NAME) {}; /** Identifier used to retrieve this provider from rules which export it. */ @@ -81,29 +77,6 @@ public class PlatformInfo extends SkylarkClassObject { return 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 new {@link Builder} for creating a fresh {@link PlatformInfo} instance. */ public static Builder builder() { return new Builder(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ToolchainInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java index 320ee5e9df..1e5e45f462 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/platform/ToolchainInfo.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/ToolchainInfo.java @@ -12,14 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.devtools.build.lib.rules.platform; +package com.google.devtools.build.lib.analysis.platform; -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.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.ClassObjectConstructor; @@ -29,7 +25,6 @@ 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; /** @@ -42,17 +37,17 @@ import java.util.Map; category = SkylarkModuleCategory.PROVIDER ) @Immutable -public class ToolchainInfo extends SkylarkClassObject implements TransitiveInfoProvider { +public class ToolchainInfo extends SkylarkClassObject { /** Name used in Skylark for accessing this provider. */ - static final String SKYLARK_NAME = "ToolchainInfo"; + public static final String SKYLARK_NAME = "ToolchainInfo"; /** Skylark constructor and identifier for this provider. */ - static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = + public static final ClassObjectConstructor SKYLARK_CONSTRUCTOR = new NativeClassObjectConstructor(SKYLARK_NAME) {}; /** Identifier used to retrieve this provider from rules which export it. */ - private static final SkylarkProviderIdentifier SKYLARK_IDENTIFIER = + public static final SkylarkProviderIdentifier SKYLARK_IDENTIFIER = SkylarkProviderIdentifier.forKey(SKYLARK_CONSTRUCTOR.getKey()); private final ImmutableList<ConstraintValueInfo> execConstraints; @@ -105,27 +100,4 @@ public class ToolchainInfo extends SkylarkClassObject implements TransitiveInfoP public ImmutableList<ConstraintValueInfo> targetConstraints() { return targetConstraints; } - - /** Retrieves and casts the provider from the given target. */ - public static ToolchainInfo fromTarget(TransitiveInfoCollection target) { - Object provider = target.get(SKYLARK_IDENTIFIER); - if (provider == null) { - return null; - } - Preconditions.checkState(provider instanceof ToolchainInfo); - return (ToolchainInfo) provider; - } - - /** Retrieves and casts the providers from the given targets. */ - public static Iterable<ToolchainInfo> fromTargets( - Iterable<? extends TransitiveInfoCollection> targets) { - return Iterables.transform( - targets, - new Function<TransitiveInfoCollection, ToolchainInfo>() { - @Override - public ToolchainInfo apply(TransitiveInfoCollection target) { - return fromTarget(target); - } - }); - } } 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 8b3f0a0d57..c3a8cc5103 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 @@ -14,6 +14,7 @@ java_library( "//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", + "//src/main/java/com/google/devtools/build/lib/analysis/platform", "//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 653ea2fe4f..6c903fd04a 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 @@ -14,13 +14,18 @@ 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; 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.ConstraintSettingInfo; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; +import com.google.devtools.build.lib.util.Preconditions; /** * Defines a category of constraint that can be fulfilled by a constraint_value rule in a platform @@ -39,4 +44,27 @@ public class ConstraintSetting implements RuleConfiguredTargetFactory { .addNativeDeclaredProvider(ConstraintSettingInfo.create(ruleContext.getLabel())) .build(); } + + /** Retrieves and casts the provider from the given target. */ + public static ConstraintSettingInfo constraintSetting(TransitiveInfoCollection target) { + Object provider = target.get(ConstraintSettingInfo.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> constraintSettings( + Iterable<? extends TransitiveInfoCollection> targets) { + return Iterables.transform( + targets, + new Function<TransitiveInfoCollection, ConstraintSettingInfo>() { + @Override + public ConstraintSettingInfo apply(TransitiveInfoCollection target) { + return constraintSetting(target); + } + }); + } } 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 e1aa6d933b..1eb3ba1802 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 @@ -14,6 +14,8 @@ 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; @@ -21,7 +23,11 @@ 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.ConstraintSettingInfo; +import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; +import com.google.devtools.build.lib.util.Preconditions; /** Defines a potential value of a constraint. */ public class ConstraintValue implements RuleConfiguredTargetFactory { @@ -31,7 +37,7 @@ public class ConstraintValue implements RuleConfiguredTargetFactory { throws InterruptedException, RuleErrorException { ConstraintSettingInfo constraint = - ConstraintSettingInfo.fromTarget( + ConstraintSetting.constraintSetting( ruleContext.getPrerequisite( ConstraintValueRule.CONSTRAINT_SETTING_ATTR, Mode.DONT_CHECK)); @@ -42,4 +48,27 @@ public class ConstraintValue implements RuleConfiguredTargetFactory { .addNativeDeclaredProvider(ConstraintValueInfo.create(constraint, ruleContext.getLabel())) .build(); } + + /** Retrieves and casts the provider from the given target. */ + public static ConstraintValueInfo constraintValue(TransitiveInfoCollection target) { + Object provider = target.get(ConstraintValueInfo.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> constraintValues( + Iterable<? extends TransitiveInfoCollection> targets) { + return Iterables.transform( + targets, + new Function<TransitiveInfoCollection, ConstraintValueInfo>() { + @Override + public ConstraintValueInfo apply(TransitiveInfoCollection target) { + return constraintValue(target); + } + }); + } } 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 5593862754..ae8fd0495c 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,6 +20,7 @@ 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.platform.ConstraintSettingInfo; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.syntax.Type; 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 d1c48e9445..184f7a8a07 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,6 +14,8 @@ 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; @@ -21,11 +23,14 @@ 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.rules.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.rules.platform.PlatformInfo.DuplicateConstraintException; 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. */ @@ -41,7 +46,7 @@ public class Platform implements RuleConfiguredTargetFactory { autodetectHostConstraints(ruleContext, platformBuilder); } else { platformBuilder.addConstraints( - ConstraintValueInfo.fromTargets( + ConstraintValue.constraintValues( ruleContext.getPrerequisites(PlatformRule.CONSTRAINT_VALUES_ATTR, Mode.DONT_CHECK))); } @@ -52,7 +57,7 @@ public class Platform implements RuleConfiguredTargetFactory { PlatformInfo platformInfo; try { platformInfo = platformBuilder.build(); - } catch (DuplicateConstraintException e) { + } catch (PlatformInfo.DuplicateConstraintException e) { // Report the error and return null. ruleContext.attributeError(PlatformRule.CONSTRAINT_VALUES_ATTR, e.getMessage()); return null; @@ -72,7 +77,7 @@ public class Platform implements RuleConfiguredTargetFactory { // Add the CPU. CPU cpu = CPU.getCurrent(); Iterable<ConstraintValueInfo> cpuConstraintValues = - ConstraintValueInfo.fromTargets( + ConstraintValue.constraintValues( ruleContext.getPrerequisites(PlatformRule.HOST_CPU_CONSTRAINTS_ATTR, Mode.DONT_CHECK)); for (ConstraintValueInfo constraint : cpuConstraintValues) { if (cpu.getCanonicalName().equals(constraint.label().getName())) { @@ -84,7 +89,7 @@ public class Platform implements RuleConfiguredTargetFactory { // Add the OS. OS os = OS.getCurrent(); Iterable<ConstraintValueInfo> osConstraintValues = - ConstraintValueInfo.fromTargets( + ConstraintValue.constraintValues( ruleContext.getPrerequisites(PlatformRule.HOST_OS_CONSTRAINTS_ATTR, Mode.DONT_CHECK)); for (ConstraintValueInfo constraint : osConstraintValues) { if (os.getCanonicalName().equals(constraint.label().getName())) { @@ -93,4 +98,27 @@ 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); + } + }); + } } 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 index 3a67979bb8..09d31c15e5 100644 --- 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 @@ -16,6 +16,10 @@ package com.google.devtools.build.lib.rules.platform; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; +import com.google.devtools.build.lib.analysis.platform.ConstraintSettingInfo; +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.ToolchainInfo; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.ClassObjectConstructor; import com.google.devtools.build.lib.skylarkinterface.Param; @@ -62,11 +66,11 @@ public class PlatformCommon { public ClassObjectConstructor getConstraintValueInfoConstructor() { return ConstraintValueInfo.SKYLARK_CONSTRUCTOR; } - + @SkylarkCallable( - name = ToolchainInfo.SKYLARK_NAME, - doc = "The key used to retrieve the provider containing toolchain data.", - structField = true + name = ToolchainInfo.SKYLARK_NAME, + doc = "The key used to retrieve the provider containing toolchain data.", + structField = true ) public ClassObjectConstructor getToolchainInfoConstructor() { return ToolchainInfo.SKYLARK_CONSTRUCTOR; @@ -85,6 +89,7 @@ public class PlatformCommon { @Param( name = "exec_compatible_with", type = SkylarkList.class, + generic1 = TransitiveInfoCollection.class, defaultValue = "[]", named = true, positional = false, @@ -93,6 +98,7 @@ public class PlatformCommon { @Param( name = "target_compatible_with", type = SkylarkList.class, + generic1 = TransitiveInfoCollection.class, defaultValue = "[]", named = true, positional = false, @@ -118,9 +124,9 @@ public class PlatformCommon { throws ConversionException, EvalException { Iterable<ConstraintValueInfo> execConstraints = - ConstraintValueInfo.fromTargets(execCompatibleWith); + ConstraintValue.constraintValues(execCompatibleWith); Iterable<ConstraintValueInfo> targetConstraints = - ConstraintValueInfo.fromTargets(targetCompatibleWith); + ConstraintValue.constraintValues(targetCompatibleWith); ImmutableMap<String, Object> toolchainData = ImmutableMap.copyOf( SkylarkDict.castSkylarkDictOrNoneToDict( 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 126cd9d15d..3e4b0f2b9f 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,6 +20,7 @@ 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.platform.ConstraintValueInfo; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.syntax.Type; |