Search in sources :

Example 76 with Rule

use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.

the class IncrementalLoadingTest method testTransientErrorsInGlobbing.

@Test
public void testTransientErrorsInGlobbing() throws Exception {
    Path buildFile = tester.addFile("e/BUILD", "sh_library(name = 'e', data = glob(['*.txt']))");
    Path parentDir = buildFile.getParentDirectory();
    tester.addFile("e/data.txt");
    throwOnReaddir = parentDir;
    tester.sync();
    Target target = tester.getTarget("//e:e");
    assertThat(((Rule) target).containsErrors()).isTrue();
    GlobList<?> globList = (GlobList<?>) ((Rule) target).getAttributeContainer().getAttr("data");
    assertThat(globList).isEmpty();
    throwOnReaddir = null;
    tester.sync();
    target = tester.getTarget("//e:e");
    assertThat(((Rule) target).containsErrors()).isFalse();
    globList = (GlobList<?>) ((Rule) target).getAttributeContainer().getAttr("data");
    assertThat(globList).containsExactly(Label.parseAbsolute("//e:data.txt"));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) GlobList(com.google.devtools.build.lib.syntax.GlobList) Target(com.google.devtools.build.lib.packages.Target) Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Example 77 with Rule

use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.

the class AggregatingAttributeMapperTest method testGetReachableLabelsWithDefaultValues.

@Test
public void testGetReachableLabelsWithDefaultValues() throws Exception {
    Rule rule = scratchRule("a", "myrule", "cc_binary(name = 'myrule',", "    srcs = [],", "    malloc = select({", "        '//conditions:a': None,", "    }))");
    AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
    assertThat(mapper.getReachableLabels("malloc", true)).containsExactly(getDefaultMallocLabel(rule), Label.create("@//conditions", "a"));
}
Also used : Rule(com.google.devtools.build.lib.packages.Rule) AggregatingAttributeMapper(com.google.devtools.build.lib.packages.AggregatingAttributeMapper) Test(org.junit.Test)

Example 78 with Rule

use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.

the class AggregatingAttributeMapperTest method testGetPossibleValuesDirectAttribute.

/**
   * Tests that {@link AggregatingAttributeMapper#visitAttribute} returns an
   * attribute's sole value when declared directly (i.e. not as a configurable dict).
   */
@Test
public void testGetPossibleValuesDirectAttribute() throws Exception {
    Rule rule = scratchRule("a", "myrule", "sh_binary(name = 'myrule',", "          srcs = ['a.sh'])");
    assertThat(AggregatingAttributeMapper.of(rule).visitAttribute("srcs", BuildType.LABEL_LIST)).containsExactlyElementsIn(ImmutableList.of(ImmutableList.of(Label.create("@//a", "a.sh"))));
}
Also used : Rule(com.google.devtools.build.lib.packages.Rule) Test(org.junit.Test)

Example 79 with Rule

use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.

the class AggregatingAttributeMapperTest method testComputedDefaultWithoutConfigurableDeps.

@Test
public void testComputedDefaultWithoutConfigurableDeps() throws Exception {
    Rule rule = scratchRule("x", "bb", "rule_with_computed_defaults(", "    name = 'bb',", "    nonconfigurable = 'swim up')");
    assertThat(AggregatingAttributeMapper.of(rule).visitAttribute("$computed_default_without_configurable_deps", STRING)).containsExactly("swim up");
}
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