use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class AggregatingAttributeMapperTest method testGetPossibleValuesWithConcatenatedSelects.
@Test
public void testGetPossibleValuesWithConcatenatedSelects() throws Exception {
Rule rule = scratchRule("a", "myrule", "sh_binary(name = 'myrule',", " srcs = select({", " '//conditions:a1': ['a1.sh'],", " '//conditions:b1': ['b1.sh']})", " + select({", " '//conditions:a2': ['a2.sh'],", " '//conditions:b2': ['b2.sh']})", " )");
assertThat(AggregatingAttributeMapper.of(rule).visitAttribute("srcs", BuildType.LABEL_LIST)).containsExactlyElementsIn(ImmutableList.of(ImmutableList.of(Label.create("@//a", "a1.sh"), Label.create("@//a", "a2.sh")), ImmutableList.of(Label.create("@//a", "a1.sh"), Label.create("@//a", "b2.sh")), ImmutableList.of(Label.create("@//a", "b1.sh"), Label.create("@//a", "a2.sh")), ImmutableList.of(Label.create("@//a", "b1.sh"), Label.create("@//a", "b2.sh"))));
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class AggregatingAttributeMapperTest method testGetReachableLabels.
@Test
public void testGetReachableLabels() throws Exception {
Rule rule = scratchRule("x", "main", "cc_binary(", " name = 'main',", " srcs = select({", " '//conditions:a': ['a.cc'],", " '//conditions:b': ['b.cc']})", " + ", " ['always.cc']", " + ", " select({", " '//conditions:c': ['c.cc'],", " '//conditions:d': ['d.cc'],", " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': ['default.cc'],", " }))");
ImmutableList<Label> valueLabels = ImmutableList.of(Label.create("@//x", "a.cc"), Label.create("@//x", "b.cc"), Label.create("@//x", "always.cc"), Label.create("@//x", "c.cc"), Label.create("@//x", "d.cc"), Label.create("@//x", "default.cc"));
ImmutableList<Label> keyLabels = ImmutableList.of(Label.create("@//conditions", "a"), Label.create("@//conditions", "b"), Label.create("@//conditions", "c"), Label.create("@//conditions", "d"));
AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
assertThat(mapper.getReachableLabels("srcs", true)).containsExactlyElementsIn(Iterables.concat(valueLabels, keyLabels));
assertThat(mapper.getReachableLabels("srcs", false)).containsExactlyElementsIn(valueLabels);
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class AggregatingAttributeMapperTest method testVisitationWithDefaultValues.
@Test
public void testVisitationWithDefaultValues() throws Exception {
Rule rule = scratchRule("a", "myrule", "cc_binary(name = 'myrule',", " srcs = [],", " malloc = select({", " '//conditions:a': None,", " }))");
VisitationRecorder recorder = new VisitationRecorder("malloc");
AggregatingAttributeMapper.of(rule).visitLabels(recorder);
assertThat(recorder.labelsVisited).containsExactlyElementsIn(ImmutableList.of("//conditions:a", getDefaultMallocLabel(rule).toString()));
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class AggregatingAttributeMapperTest method testGetPossibleValuesConfigurableAttribute.
/**
* Tests that {@link AggregatingAttributeMapper#visitAttribute} returns
* every possible value that a configurable attribute can resolve to.
*/
@Test
public void testGetPossibleValuesConfigurableAttribute() throws Exception {
Rule rule = scratchRule("a", "myrule", "sh_binary(name = 'myrule',", " srcs = select({", " '//conditions:a': ['a.sh'],", " '//conditions:b': ['b.sh'],", " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': ['default.sh'],", " }))");
assertThat(AggregatingAttributeMapper.of(rule).visitAttribute("srcs", BuildType.LABEL_LIST)).containsExactlyElementsIn(ImmutableList.of(ImmutableList.of(Label.create("@//a", "a.sh")), ImmutableList.of(Label.create("@//a", "b.sh")), ImmutableList.of(Label.create("@//a", "default.sh"))));
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class AggregatingAttributeMapperTest method testGetPossibleValuesWithManySelects.
/**
* Given a large number of selects, we expect better than the naive
* exponential performance from evaluating select1 x select2 x select3 x ...
*/
@Test
public void testGetPossibleValuesWithManySelects() throws Exception {
String pattern = " + select({'//conditions:a1': '%c', '//conditions:a2': '%s'})";
StringBuilder ruleDef = new StringBuilder();
ruleDef.append("genrule(name = 'gen', srcs = [], outs = ['gen.out'], cmd = ''");
for (char c : "abcdefghijklmnopqrstuvwxyz".toCharArray()) {
ruleDef.append(String.format(pattern, c, Character.toUpperCase(c)));
}
ruleDef.append(")");
Rule rule = scratchRule("a", "gen", ruleDef.toString());
// Naive evaluation would visit 2^26 cases and either overflow memory or timeout the test.
assertThat(AggregatingAttributeMapper.of(rule).visitAttribute("cmd", Type.STRING)).containsExactly("abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
Aggregations