use of com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps in project bazel by bazelbuild.
the class ConfiguredTargetFunction method resolveAspectDependencies.
/**
* Given a list of {@link Dependency} objects, returns a multimap from the {@link SkyKey} of the
* dependency to the {@link ConfiguredAspect} instances that should be merged into it.
*
* <p>Returns null if the required aspects are not computed yet.
*/
@Nullable
private static OrderedSetMultimap<SkyKey, ConfiguredAspect> resolveAspectDependencies(Environment env, Map<SkyKey, ConfiguredTarget> configuredTargetMap, Iterable<Dependency> deps, NestedSetBuilder<Package> transitivePackages) throws AspectCreationException, InterruptedException {
OrderedSetMultimap<SkyKey, ConfiguredAspect> result = OrderedSetMultimap.create();
Set<SkyKey> allAspectKeys = new HashSet<>();
for (Dependency dep : deps) {
allAspectKeys.addAll(getAspectKeys(dep).values());
}
Map<SkyKey, ValueOrException2<AspectCreationException, NoSuchThingException>> depAspects = env.getValuesOrThrow(allAspectKeys, AspectCreationException.class, NoSuchThingException.class);
for (Dependency dep : deps) {
SkyKey depKey = TO_KEYS.apply(dep);
// twice.
if (result.containsKey(depKey)) {
continue;
}
Map<AspectDescriptor, SkyKey> aspectToKeys = getAspectKeys(dep);
ConfiguredTarget depConfiguredTarget = configuredTargetMap.get(depKey);
for (AspectDeps depAspect : dep.getAspects().getVisibleAspects()) {
SkyKey aspectKey = aspectToKeys.get(depAspect.getAspect());
AspectValue aspectValue;
try {
// TODO(ulfjack): Catch all thrown AspectCreationException and NoSuchThingException
// instances and merge them into a single Exception to get full root cause data.
aspectValue = (AspectValue) depAspects.get(aspectKey).get();
} catch (NoSuchThingException e) {
throw new AspectCreationException(String.format("Evaluation of aspect %s on %s failed: %s", depAspect.getAspect().getAspectClass().getName(), dep.getLabel(), e.toString()));
}
if (aspectValue == null) {
// Dependent aspect has either not been computed yet or is in error.
return null;
}
if (!aspectMatchesConfiguredTarget(depConfiguredTarget, aspectValue.getAspect())) {
continue;
}
result.put(depKey, aspectValue.getConfiguredAspect());
transitivePackages.addTransitive(aspectValue.getTransitivePackages());
}
}
return result;
}
use of com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps in project bazel by bazelbuild.
the class ConfiguredTargetFunction method buildAspectKey.
private static AspectKey buildAspectKey(AspectDeps aspectDeps, HashMap<AspectDescriptor, SkyKey> result, Dependency dep) {
if (result.containsKey(aspectDeps.getAspect())) {
return (AspectKey) result.get(aspectDeps.getAspect()).argument();
}
ImmutableList.Builder<AspectKey> dependentAspects = ImmutableList.builder();
for (AspectDeps path : aspectDeps.getDependentAspects()) {
dependentAspects.add(buildAspectKey(path, result, dep));
}
AspectKey aspectKey = AspectValue.createAspectKey(dep.getLabel(), dep.getConfiguration(), dependentAspects.build(), aspectDeps.getAspect(), dep.getAspectConfiguration(aspectDeps.getAspect()));
result.put(aspectKey.getAspectDescriptor(), aspectKey.getSkyKey());
return aspectKey;
}
use of com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps in project bazel by bazelbuild.
the class ConfiguredTargetFunction method getAspectKeys.
private static Map<AspectDescriptor, SkyKey> getAspectKeys(Dependency dep) {
HashMap<AspectDescriptor, SkyKey> result = new HashMap<>();
AspectCollection aspects = dep.getAspects();
for (AspectDeps aspectDeps : aspects.getVisibleAspects()) {
buildAspectKey(aspectDeps, result, dep);
}
return result;
}
use of com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps in project bazel by bazelbuild.
the class AspectCollectionTest method validateAspectPaths.
private static void validateAspectPaths(AspectCollection collection, ImmutableList<Pair<Aspect, ImmutableList<Aspect>>> expectedList) {
HashMap<AspectDescriptor, AspectDeps> allPaths = new HashMap<>();
for (AspectDeps aspectPath : collection.getVisibleAspects()) {
collectAndValidateAspectDeps(aspectPath, allPaths);
}
HashSet<AspectDescriptor> expectedKeys = new HashSet<>();
for (Pair<Aspect, ImmutableList<Aspect>> expected : expectedList) {
assertThat(allPaths).containsKey(expected.first.getDescriptor());
AspectDeps aspectPath = allPaths.get(expected.first.getDescriptor());
assertThat(Iterables.transform(aspectPath.getDependentAspects(), ASPECT_PATH_TO_DESCRIPTOR)).containsExactlyElementsIn(Iterables.transform(expected.second, ASPECT_TO_DESCRIPTOR)).inOrder();
expectedKeys.add(expected.first.getDescriptor());
}
assertThat(allPaths.keySet()).containsExactlyElementsIn(expectedKeys);
}
Aggregations