Search in sources :

Example 16 with Aspect

use of com.google.devtools.build.lib.packages.Aspect in project bazel by bazelbuild.

the class AspectCollectionTest method linearAspectPath1.

/**
   * a3 wants a1 and a2, a1 and a2 want no one, path is a1, a2, a3.
   */
@Test
public void linearAspectPath1() throws Exception {
    Aspect a1 = createAspect("a1");
    Aspect a2 = createAspect("a2");
    Aspect a3 = createAspect("a3", "a1", "a2");
    AspectCollection collection = AspectCollection.create(ImmutableList.of(a1, a2, a3), ImmutableSet.of(a3.getDescriptor()));
    validateAspectCollection(collection, ImmutableList.of(a1, a2, a3), ImmutableList.of(a3), expectDeps(a3, a1, a2), expectDeps(a1), expectDeps(a2));
}
Also used : Aspect(com.google.devtools.build.lib.packages.Aspect) Test(org.junit.Test)

Example 17 with Aspect

use of com.google.devtools.build.lib.packages.Aspect in project bazel by bazelbuild.

the class AspectCollectionTest method duplicateAspect.

/**
   * a2 wants a1, a3 wants a1 and a2, the path is [a2, a1, a2, a3], so a2 occurs twice.
   *
   * First occurrence of a2 would not see a1, but the second would: that is an error.
   */
@Test
public void duplicateAspect() throws Exception {
    Aspect a1 = createAspect("a1");
    Aspect a2 = createAspect("a2", "a1");
    Aspect a3 = createAspect("a3", "a2", "a1");
    try {
        AspectCollection.create(ImmutableList.of(a2, a1, a2, a3), ImmutableSet.of(a3.getDescriptor()));
        Assert.fail();
    } catch (AspectCycleOnPathException e) {
        assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
        assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
    }
}
Also used : AspectCycleOnPathException(com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException) Aspect(com.google.devtools.build.lib.packages.Aspect) Test(org.junit.Test)

Example 18 with Aspect

use of com.google.devtools.build.lib.packages.Aspect in project bazel by bazelbuild.

the class AspectCollectionTest method duplicateAspect2.

/**
   * a2 wants a1, a3 wants a2, the path is [a2, a1, a2, a3], so a2 occurs twice.
   *
   * First occurrence of a2 would not see a1, but the second would: that is an error.
   */
@Test
public void duplicateAspect2() throws Exception {
    Aspect a1 = createAspect("a1");
    Aspect a2 = createAspect("a2", "a1");
    Aspect a3 = createAspect("a3", "a2");
    try {
        AspectCollection.create(ImmutableList.of(a2, a1, a2, a3), ImmutableSet.of(a3.getDescriptor()));
        Assert.fail();
    } catch (AspectCycleOnPathException e) {
        assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
        assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
    }
}
Also used : AspectCycleOnPathException(com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException) Aspect(com.google.devtools.build.lib.packages.Aspect) Test(org.junit.Test)

Example 19 with Aspect

use of com.google.devtools.build.lib.packages.Aspect in project bazel by bazelbuild.

the class AspectCollectionTest method validateOrder.

/**
   * a3 wants a1, a1 wants a2,  path is a1, a2, a3, so a2 comes after a1.
   */
@Test
public void validateOrder() throws Exception {
    Aspect a1 = createAspect("a1", "a2");
    Aspect a2 = createAspect("a2");
    Aspect a3 = createAspect("a3", "a1");
    AspectCollection collection = AspectCollection.create(ImmutableList.of(a1, a2, a3), ImmutableSet.of(a3.getDescriptor()));
    validateAspectCollection(collection, ImmutableList.of(a1, a3), ImmutableList.of(a3), expectDeps(a3, a1), expectDeps(a1));
}
Also used : Aspect(com.google.devtools.build.lib.packages.Aspect) Test(org.junit.Test)

Example 20 with Aspect

use of com.google.devtools.build.lib.packages.Aspect 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

Aspect (com.google.devtools.build.lib.packages.Aspect)22 Test (org.junit.Test)14 AspectCycleOnPathException (com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException)5 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)5 Attribute (com.google.devtools.build.lib.packages.Attribute)4 Rule (com.google.devtools.build.lib.packages.Rule)4 ImmutableList (com.google.common.collect.ImmutableList)3 Label (com.google.devtools.build.lib.cmdline.Label)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Package (com.google.devtools.build.lib.packages.Package)2 Target (com.google.devtools.build.lib.packages.Target)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 AspectDeps (com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps)1 ConfiguredAspect (com.google.devtools.build.lib.analysis.ConfiguredAspect)1 ConfiguredAspectFactory (com.google.devtools.build.lib.analysis.ConfiguredAspectFactory)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1 InconsistentAspectOrderException (com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException)1 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)1