aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Chris Parsons <cparsons@google.com>2016-04-07 19:29:02 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-04-08 14:34:40 +0000
commit4aa7c9d013f377200fbd7aa2fda6c77461bc3968 (patch)
tree081db2d69d07bae250295c5d05bbd020e9dad3a9
parentd9571f0944a75fd0c52c987589e36797e7438d82 (diff)
Expose method on ruleContext for retrieving TransitiveInfoProviders by configuration.
This is useful for obtaining child split configurations and the information they provide. -- MOS_MIGRATED_REVID=119295699
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index efd137900b..57e680824e 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -688,6 +688,29 @@ public final class RuleContext extends TargetContext
}
/**
+ * For a given attribute, returns all {@link TransitiveInfoProvider}s provided by targets
+ * of that attribute. Each {@link TransitiveInfoProvider} is keyed by the
+ * {@link BuildConfiguration} under which the provider was created.
+ */
+ public <C extends TransitiveInfoProvider> ImmutableListMultimap<BuildConfiguration, C>
+ getPrerequisitesByConfiguration(String attributeName, Mode mode, final Class<C> classType) {
+ AnalysisUtils.checkProvider(classType);
+ List<? extends TransitiveInfoCollection> transitiveInfoCollections =
+ getPrerequisites(attributeName, mode);
+
+ // Use an ImmutableListMultimap.Builder here to preserve ordering.
+ ImmutableListMultimap.Builder<BuildConfiguration, C> result =
+ ImmutableListMultimap.builder();
+ for (TransitiveInfoCollection prerequisite : transitiveInfoCollections) {
+ C prerequisiteProvider = prerequisite.getProvider(classType);
+ if (prerequisiteProvider != null) {
+ result.put(prerequisite.getConfiguration(), prerequisiteProvider);
+ }
+ }
+ return result.build();
+ }
+
+ /**
* Returns all the providers of the specified type that are listed under the specified attribute
* of this target in the BUILD file.
*/