Search in sources :

Example 1 with AspectDeps

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;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) Dependency(com.google.devtools.build.lib.analysis.Dependency) ValueOrException2(com.google.devtools.build.skyframe.ValueOrException2) AspectCreationException(com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) AspectDeps(com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Example 2 with AspectDeps

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;
}
Also used : AspectDeps(com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps) AspectKey(com.google.devtools.build.lib.skyframe.AspectValue.AspectKey) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with AspectDeps

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;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) AspectDeps(com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) AspectCollection(com.google.devtools.build.lib.analysis.AspectCollection)

Example 4 with AspectDeps

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);
}
Also used : AspectDeps(com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) Aspect(com.google.devtools.build.lib.packages.Aspect) HashSet(java.util.HashSet)

Aggregations

AspectDeps (com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps)4 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)3 ImmutableList (com.google.common.collect.ImmutableList)2 SkyKey (com.google.devtools.build.skyframe.SkyKey)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 AspectCollection (com.google.devtools.build.lib.analysis.AspectCollection)1 ConfiguredAspect (com.google.devtools.build.lib.analysis.ConfiguredAspect)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 Dependency (com.google.devtools.build.lib.analysis.Dependency)1 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)1 Aspect (com.google.devtools.build.lib.packages.Aspect)1 NoSuchThingException (com.google.devtools.build.lib.packages.NoSuchThingException)1 AspectCreationException (com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException)1 AspectKey (com.google.devtools.build.lib.skyframe.AspectValue.AspectKey)1 ValueOrException2 (com.google.devtools.build.skyframe.ValueOrException2)1 LinkedHashMap (java.util.LinkedHashMap)1 Nullable (javax.annotation.Nullable)1