Search in sources :

Example 21 with Rule

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"))));
}
Also used : Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Example 22 with Rule

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);
}
Also used : Label(com.google.devtools.build.lib.cmdline.Label) Rule(com.google.devtools.build.lib.packages.Rule) AggregatingAttributeMapper(com.google.devtools.build.lib.packages.AggregatingAttributeMapper) Test(org.junit.Test)

Example 23 with Rule

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()));
}
Also used : Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Example 24 with Rule

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"))));
}
Also used : Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Example 25 with Rule

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");
}
Also used : Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Aggregations

Rule (com.google.devtools.build.lib.packages.Rule)79 Test (org.junit.Test)27 Label (com.google.devtools.build.lib.cmdline.Label)26 Attribute (com.google.devtools.build.lib.packages.Attribute)20 Target (com.google.devtools.build.lib.packages.Target)19 Nullable (javax.annotation.Nullable)10 RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)9 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)9 OutputFile (com.google.devtools.build.lib.packages.OutputFile)8 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)7 NoSuchThingException (com.google.devtools.build.lib.packages.NoSuchThingException)7 SkyKey (com.google.devtools.build.skyframe.SkyKey)7 ImmutableList (com.google.common.collect.ImmutableList)6 InputFile (com.google.devtools.build.lib.packages.InputFile)6 IOException (java.io.IOException)6 LinkedHashSet (java.util.LinkedHashSet)6 AggregatingAttributeMapper (com.google.devtools.build.lib.packages.AggregatingAttributeMapper)5 Package (com.google.devtools.build.lib.packages.Package)5 Artifact (com.google.devtools.build.lib.actions.Artifact)4 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)4