From 4aa7c9d013f377200fbd7aa2fda6c77461bc3968 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Thu, 7 Apr 2016 19:29:02 +0000 Subject: 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 --- .../devtools/build/lib/analysis/RuleContext.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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 @@ -687,6 +687,29 @@ public final class RuleContext extends TargetContext return elements.isEmpty() ? null : elements.get(0); } + /** + * 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 ImmutableListMultimap + getPrerequisitesByConfiguration(String attributeName, Mode mode, final Class classType) { + AnalysisUtils.checkProvider(classType); + List transitiveInfoCollections = + getPrerequisites(attributeName, mode); + + // Use an ImmutableListMultimap.Builder here to preserve ordering. + ImmutableListMultimap.Builder 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. -- cgit v1.2.3