use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class ConfiguredAttributeMapperTest method testLabelVisitation.
/**
* Tests that label visitation only travels down configuration-appropriate paths.
*/
@Test
public void testLabelVisitation() throws Exception {
writeConfigRules();
scratch.file("a/BUILD", "sh_binary(", " name = 'bin',", " srcs = ['bin.sh'],", " deps = select({", " '//conditions:a': [':adep'],", " '//conditions:b': [':bdep'],", " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': [':defaultdep'],", " }))", "sh_library(", " name = 'adep',", " srcs = ['adep.sh'])", "sh_library(", " name = 'bdep',", " srcs = ['bdep.sh'])", "sh_library(", " name = 'defaultdep',", " srcs = ['defaultdep.sh'])");
final List<Label> visitedLabels = new ArrayList<>();
AttributeMap.AcceptsLabelAttribute testVisitor = new AttributeMap.AcceptsLabelAttribute() {
@Override
public void acceptLabelAttribute(Label label, Attribute attribute) {
if (label.toString().contains("//a:")) {
// Ignore implicit common dependencies.
visitedLabels.add(label);
}
}
};
final Label binSrc = Label.parseAbsolute("//a:bin.sh");
useConfiguration("--define", "mode=a");
getMapper("//a:bin").visitLabels(testVisitor);
assertThat(visitedLabels).containsExactlyElementsIn(ImmutableList.of(binSrc, Label.parseAbsolute("//a:adep")));
visitedLabels.clear();
useConfiguration("--define", "mode=b");
getMapper("//a:bin").visitLabels(testVisitor);
assertThat(visitedLabels).containsExactlyElementsIn(ImmutableList.of(binSrc, Label.parseAbsolute("//a:bdep")));
visitedLabels.clear();
useConfiguration("--define", "mode=c");
getMapper("//a:bin").visitLabels(testVisitor);
assertThat(visitedLabels).containsExactlyElementsIn(ImmutableList.of(binSrc, Label.parseAbsolute("//a:defaultdep")));
}
use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class DependencyResolverTest method hasAllAttributesAspect.
@Test
public void hasAllAttributesAspect() throws Exception {
setRulesAvailableInTests(new TestAspects.BaseRule(), new TestAspects.SimpleRule());
pkg("a", "simple(name='a', foo=[':b'])", "simple(name='b', foo=[])");
OrderedSetMultimap<Attribute, Dependency> map = dependentNodeMap("//a:a", TestAspects.ALL_ATTRIBUTES_ASPECT);
assertDep(map, "foo", "//a:b", new AspectDescriptor(TestAspects.ALL_ATTRIBUTES_ASPECT));
}
use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class DependencyResolverTest method assertDep.
@SafeVarargs
private final Dependency assertDep(OrderedSetMultimap<Attribute, Dependency> dependentNodeMap, String attrName, String dep, AspectDescriptor... aspects) {
Attribute attr = null;
for (Attribute candidate : dependentNodeMap.keySet()) {
if (candidate.getName().equals(attrName)) {
attr = candidate;
break;
}
}
assertNotNull("Attribute '" + attrName + "' not found", attr);
Dependency dependency = null;
for (Dependency candidate : dependentNodeMap.get(attr)) {
if (candidate.getLabel().toString().equals(dep)) {
dependency = candidate;
break;
}
}
assertNotNull("Dependency '" + dep + "' on attribute '" + attrName + "' not found", dependency);
assertThat(dependency.getAspects().getAllAspects()).containsExactly((Object[]) aspects);
return dependency;
}
use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class DependencyResolverTest method hasAspectsRequiredByRule.
@Test
public void hasAspectsRequiredByRule() throws Exception {
setRulesAvailableInTests(new AspectRequiringRule(), new TestAspects.BaseRule());
pkg("a", "aspect(name='a', foo=[':b'])", "aspect(name='b', foo=[])");
OrderedSetMultimap<Attribute, Dependency> map = dependentNodeMap("//a:a", null);
assertDep(map, "foo", "//a:b", new AspectDescriptor(TestAspects.SIMPLE_ASPECT));
}
use of com.google.devtools.build.lib.packages.Attribute in project bazel by bazelbuild.
the class SkylarkRepositoryContextTest method buildRuleClass.
protected static RuleClass buildRuleClass(Attribute... attributes) {
RuleClass.Builder ruleClassBuilder = new RuleClass.Builder("test", RuleClassType.WORKSPACE, true);
for (Attribute attr : attributes) {
ruleClassBuilder.addOrOverrideAttribute(attr);
}
ruleClassBuilder.setWorkspaceOnly();
ruleClassBuilder.setConfiguredTargetFunction(new BuiltinFunction("test") {
});
return ruleClassBuilder.build();
}
Aggregations