Search in sources :

Example 1 with AspectCycleOnPathException

use of com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException in project bazel by bazelbuild.

the class AspectCollectionTest method duplicateAspect4.

/**
   * a2 wants a1, a3 wants a2, a1 wants a2. the path is [a2, a1, a2, a3], so a2 occurs twice.
   * First occurrence of a2 does not see a1, but the second does => error.
   * a1 disappears.
   */
@Test
public void duplicateAspect4() throws Exception {
    Aspect a1 = createAspect("a1", "a2");
    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 2 with AspectCycleOnPathException

use of com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException in project bazel by bazelbuild.

the class AspectCollectionTest method duplicateAspect3.

/**
   * a2 wants a1, a3 wants a1 and a2, a1 wants a2. the path is [a2, a1, a2, a3], so a2 occurs twice.
   * First occurrence of a2 does not see a1, but the second does => error.
   */
@Test
public void duplicateAspect3() throws Exception {
    Aspect a1 = createAspect("a1", "a2");
    Aspect a2 = createAspect("a2", "a1");
    Aspect a3 = createAspect("a3", "a1", "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 3 with AspectCycleOnPathException

use of com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException in project bazel by bazelbuild.

the class DependencyResolver method requiredAspects.

private AspectCollection requiredAspects(Iterable<Aspect> aspectPath, AttributeAndOwner attributeAndOwner, final Target target, Rule originalRule) throws InconsistentAspectOrderException {
    if (!(target instanceof Rule)) {
        return AspectCollection.EMPTY;
    }
    if (attributeAndOwner.ownerAspect != null) {
        // Do not propagate aspects along aspect attributes.
        return AspectCollection.EMPTY;
    }
    ImmutableList.Builder<Aspect> filteredAspectPath = ImmutableList.builder();
    ImmutableSet.Builder<AspectDescriptor> visibleAspects = ImmutableSet.builder();
    Attribute attribute = attributeAndOwner.attribute;
    collectOriginatingAspects(originalRule, attribute, (Rule) target, filteredAspectPath, visibleAspects);
    collectPropagatingAspects(aspectPath, attribute, (Rule) target, filteredAspectPath, visibleAspects);
    try {
        return AspectCollection.create(filteredAspectPath.build(), visibleAspects.build());
    } catch (AspectCycleOnPathException e) {
        throw new InconsistentAspectOrderException(originalRule, attribute, target, e);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Attribute(com.google.devtools.build.lib.packages.Attribute) AspectCycleOnPathException(com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException) ImmutableList(com.google.common.collect.ImmutableList) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) Rule(com.google.devtools.build.lib.packages.Rule) Aspect(com.google.devtools.build.lib.packages.Aspect)

Example 4 with AspectCycleOnPathException

use of com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException 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 5 with AspectCycleOnPathException

use of com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException 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)

Aggregations

AspectCycleOnPathException (com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException)5 Aspect (com.google.devtools.build.lib.packages.Aspect)5 Test (org.junit.Test)4 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)1 Attribute (com.google.devtools.build.lib.packages.Attribute)1 Rule (com.google.devtools.build.lib.packages.Rule)1