use of com.google.devtools.build.lib.packages.AspectDescriptor in project bazel by bazelbuild.
the class DependencyTest method equalsPassesEqualsTester.
@Test
public void equalsPassesEqualsTester() throws Exception {
update();
Label a = Label.parseAbsolute("//a");
Label aExplicit = Label.parseAbsolute("//a:a");
Label b = Label.parseAbsolute("//b");
BuildConfiguration host = getHostConfiguration();
BuildConfiguration target = getTargetConfiguration();
AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT);
AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT);
AspectDescriptor errorAspect = new AspectDescriptor(TestAspects.ERROR_ASPECT);
AspectCollection twoAspects = AspectCollection.createForTests(simpleAspect, attributeAspect);
AspectCollection inverseAspects = AspectCollection.createForTests(attributeAspect, simpleAspect);
AspectCollection differentAspects = AspectCollection.createForTests(attributeAspect, errorAspect);
AspectCollection noAspects = AspectCollection.EMPTY;
ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectsHostMap = ImmutableMap.of(simpleAspect, host, attributeAspect, host);
ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectsTargetMap = ImmutableMap.of(simpleAspect, target, attributeAspect, target);
ImmutableMap<AspectDescriptor, BuildConfiguration> differentAspectsHostMap = ImmutableMap.of(attributeAspect, host, errorAspect, host);
ImmutableMap<AspectDescriptor, BuildConfiguration> differentAspectsTargetMap = ImmutableMap.of(attributeAspect, target, errorAspect, target);
ImmutableMap<AspectDescriptor, BuildConfiguration> noAspectsMap = ImmutableMap.<AspectDescriptor, BuildConfiguration>of();
new EqualsTester().addEqualityGroup(// base set: //a, host configuration, normal aspect set
Dependency.withConfigurationAndAspects(a, host, twoAspects), Dependency.withConfigurationAndAspects(aExplicit, host, twoAspects), Dependency.withConfigurationAndAspects(a, host, inverseAspects), Dependency.withConfigurationAndAspects(aExplicit, host, inverseAspects), Dependency.withConfiguredAspects(a, host, twoAspects, twoAspectsHostMap), Dependency.withConfiguredAspects(aExplicit, host, twoAspects, twoAspectsHostMap)).addEqualityGroup(// base set but with label //b
Dependency.withConfigurationAndAspects(b, host, twoAspects), Dependency.withConfigurationAndAspects(b, host, inverseAspects), Dependency.withConfiguredAspects(b, host, twoAspects, twoAspectsHostMap)).addEqualityGroup(// base set but with target configuration
Dependency.withConfigurationAndAspects(a, target, twoAspects), Dependency.withConfigurationAndAspects(aExplicit, target, twoAspects), Dependency.withConfigurationAndAspects(a, target, inverseAspects), Dependency.withConfigurationAndAspects(aExplicit, target, inverseAspects), Dependency.withConfiguredAspects(a, target, twoAspects, twoAspectsTargetMap), Dependency.withConfiguredAspects(aExplicit, target, twoAspects, twoAspectsTargetMap)).addEqualityGroup(// base set but with null configuration
Dependency.withNullConfiguration(a), Dependency.withNullConfiguration(aExplicit)).addEqualityGroup(// base set but with different aspects
Dependency.withConfigurationAndAspects(a, host, differentAspects), Dependency.withConfigurationAndAspects(aExplicit, host, differentAspects), Dependency.withConfiguredAspects(a, host, differentAspects, differentAspectsHostMap), Dependency.withConfiguredAspects(aExplicit, host, differentAspects, differentAspectsHostMap)).addEqualityGroup(// base set but with label //b and target configuration
Dependency.withConfigurationAndAspects(b, target, twoAspects), Dependency.withConfigurationAndAspects(b, target, inverseAspects), Dependency.withConfiguredAspects(b, target, twoAspects, twoAspectsTargetMap)).addEqualityGroup(// base set but with label //b and null configuration
Dependency.withNullConfiguration(b)).addEqualityGroup(// base set but with label //b and different aspects
Dependency.withConfigurationAndAspects(b, host, differentAspects), Dependency.withConfiguredAspects(b, host, differentAspects, differentAspectsHostMap)).addEqualityGroup(// base set but with target configuration and different aspects
Dependency.withConfigurationAndAspects(a, target, differentAspects), Dependency.withConfigurationAndAspects(aExplicit, target, differentAspects), Dependency.withConfiguredAspects(a, target, differentAspects, differentAspectsTargetMap), Dependency.withConfiguredAspects(aExplicit, target, differentAspects, differentAspectsTargetMap)).addEqualityGroup(// inverse of base set: //b, target configuration, different aspects
Dependency.withConfigurationAndAspects(b, target, differentAspects), Dependency.withConfiguredAspects(b, target, differentAspects, differentAspectsTargetMap)).addEqualityGroup(// base set but with no aspects
Dependency.withConfiguration(a, host), Dependency.withConfiguration(aExplicit, host), Dependency.withConfigurationAndAspects(a, host, noAspects), Dependency.withConfigurationAndAspects(aExplicit, host, noAspects), Dependency.withConfiguredAspects(a, host, noAspects, noAspectsMap), Dependency.withConfiguredAspects(aExplicit, host, noAspects, noAspectsMap)).addEqualityGroup(// base set but with label //b and no aspects
Dependency.withConfiguration(b, host), Dependency.withConfigurationAndAspects(b, host, noAspects), Dependency.withConfiguredAspects(b, host, noAspects, noAspectsMap)).addEqualityGroup(// base set but with target configuration and no aspects
Dependency.withConfiguration(a, target), Dependency.withConfiguration(aExplicit, target), Dependency.withConfigurationAndAspects(a, target, noAspects), Dependency.withConfigurationAndAspects(aExplicit, target, noAspects), Dependency.withConfiguredAspects(a, target, noAspects, noAspectsMap), Dependency.withConfiguredAspects(aExplicit, target, noAspects, noAspectsMap)).addEqualityGroup(// inverse of base set: //b, target configuration, no aspects
Dependency.withConfiguration(b, target), Dependency.withConfigurationAndAspects(b, target, noAspects), Dependency.withConfiguredAspects(b, target, noAspects, noAspectsMap)).addEqualityGroup(// base set but with transition HOST
Dependency.withTransitionAndAspects(a, ConfigurationTransition.HOST, twoAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.HOST, twoAspects), Dependency.withTransitionAndAspects(a, ConfigurationTransition.HOST, inverseAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.HOST, inverseAspects)).addEqualityGroup(// base set but with transition HOST and different aspects
Dependency.withTransitionAndAspects(a, ConfigurationTransition.HOST, differentAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.HOST, differentAspects)).addEqualityGroup(// base set but with transition HOST and label //b
Dependency.withTransitionAndAspects(b, ConfigurationTransition.HOST, twoAspects), Dependency.withTransitionAndAspects(b, ConfigurationTransition.HOST, inverseAspects)).addEqualityGroup(// inverse of base set: transition HOST, label //b, different aspects
Dependency.withTransitionAndAspects(b, ConfigurationTransition.HOST, differentAspects), Dependency.withTransitionAndAspects(b, ConfigurationTransition.HOST, differentAspects)).addEqualityGroup(// base set but with transition NONE
Dependency.withTransitionAndAspects(a, ConfigurationTransition.NONE, twoAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.NONE, twoAspects), Dependency.withTransitionAndAspects(a, ConfigurationTransition.NONE, inverseAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.NONE, inverseAspects)).addEqualityGroup(// base set but with transition NONE and different aspects
Dependency.withTransitionAndAspects(a, ConfigurationTransition.NONE, differentAspects), Dependency.withTransitionAndAspects(aExplicit, ConfigurationTransition.NONE, differentAspects)).addEqualityGroup(// base set but with transition NONE and label //b
Dependency.withTransitionAndAspects(b, ConfigurationTransition.NONE, twoAspects), Dependency.withTransitionAndAspects(b, ConfigurationTransition.NONE, inverseAspects)).addEqualityGroup(// inverse of base set: transition NONE, label //b, different aspects
Dependency.withTransitionAndAspects(b, ConfigurationTransition.NONE, differentAspects), Dependency.withTransitionAndAspects(b, ConfigurationTransition.NONE, differentAspects)).testEquals();
}
use of com.google.devtools.build.lib.packages.AspectDescriptor in project bazel by bazelbuild.
the class DependencyTest method withConfiguredAspects_BasicAccessors.
@Test
public void withConfiguredAspects_BasicAccessors() throws Exception {
update();
AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT);
AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT);
AspectCollection aspects = AspectCollection.createForTests(ImmutableSet.of(simpleAspect, attributeAspect));
ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectMap = ImmutableMap.of(simpleAspect, getTargetConfiguration(), attributeAspect, getHostConfiguration());
Dependency targetDep = Dependency.withConfiguredAspects(Label.parseAbsolute("//a"), getTargetConfiguration(), aspects, twoAspectMap);
assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a"));
assertThat(targetDep.hasStaticConfiguration()).isTrue();
assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration());
assertThat(targetDep.getAspects().getAllAspects()).containsExactlyElementsIn(ImmutableSet.of(simpleAspect, attributeAspect));
assertThat(targetDep.getAspectConfiguration(simpleAspect)).isEqualTo(getTargetConfiguration());
assertThat(targetDep.getAspectConfiguration(attributeAspect)).isEqualTo(getHostConfiguration());
try {
targetDep.getTransition();
fail("withConfiguredAspects-created Dependencies should throw ISE on getTransition()");
} catch (IllegalStateException ex) {
// good. all according to keikaku. (TL note: keikaku means plan)
}
}
use of com.google.devtools.build.lib.packages.AspectDescriptor in project bazel by bazelbuild.
the class DependencyTest method withConfigurationAndAspects_RejectsNullConfigWithNPE.
@Test
public void withConfigurationAndAspects_RejectsNullConfigWithNPE() throws Exception {
// Although the NullPointerTester should check this, this test invokes a different code path,
// because it includes aspects (which the NPT test will not).
AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT);
AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT);
AspectCollection twoAspects = AspectCollection.createForTests(simpleAspect, attributeAspect);
try {
Dependency.withConfigurationAndAspects(Label.parseAbsolute("//a"), null, twoAspects);
fail("should not be allowed to create a dependency with a null configuration");
} catch (NullPointerException expected) {
// good. you fell rrrrright into my trap.
}
}
use of com.google.devtools.build.lib.packages.AspectDescriptor 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.packages.AspectDescriptor 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;
}
Aggregations