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
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 efd1379..57e6808 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 @@ } /** + * 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. */