Search in sources :

Example 16 with Attribute

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

the class SkylarkRuleClassFunctionsTest method testAttrWithProviders.

@Test
public void testAttrWithProviders() throws Exception {
    Attribute attr = buildAttribute("a1", "b = provider()", "attr.label_list(allow_files = True, providers = ['a', b])");
    assertThat(attr.getMandatoryProvidersList()).containsExactly(ImmutableSet.of(legacy("a"), declared("b")));
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Test(org.junit.Test)

Example 17 with Attribute

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

the class SkylarkRuleClassFunctionsTest method testStringDictAttr.

@Test
public void testStringDictAttr() throws Exception {
    Attribute attr = buildAttribute("a1", "attr.string_dict(default = {'a': 'b'})");
    assertEquals(Type.STRING_DICT, attr.getType());
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Test(org.junit.Test)

Example 18 with Attribute

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

the class SkylarkRuleClassFunctionsTest method testAspectExtraDeps.

@Test
public void testAspectExtraDeps() throws Exception {
    evalAndExport("def _impl(target, ctx):", "   pass", "my_aspect = aspect(_impl,", "   attrs = { '_extra_deps' : attr.label(default = Label('//foo/bar:baz')) }", ")");
    SkylarkAspect aspect = (SkylarkAspect) ev.lookup("my_aspect");
    Attribute attribute = Iterables.getOnlyElement(aspect.getAttributes());
    assertThat(attribute.getName()).isEqualTo("$extra_deps");
    assertThat(attribute.getDefaultValue(null)).isEqualTo(Label.parseAbsolute("//foo/bar:baz", false));
}
Also used : SkylarkAspect(com.google.devtools.build.lib.packages.SkylarkAspect) Attribute(com.google.devtools.build.lib.packages.Attribute) Test(org.junit.Test)

Example 19 with Attribute

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

the class SkylarkRuleClassFunctionsTest method testAttrWithProvidersList.

@Test
public void testAttrWithProvidersList() throws Exception {
    Attribute attr = buildAttribute("a1", "b = provider()", "attr.label_list(allow_files = True, providers = [['a', b], ['c']])");
    assertThat(attr.getMandatoryProvidersList()).containsExactly(ImmutableSet.of(legacy("a"), declared("b")), ImmutableSet.of(legacy("c")));
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Test(org.junit.Test)

Example 20 with Attribute

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

the class SkylarkRuleClassFunctionsTest method testAttrIntValues.

@Test
public void testAttrIntValues() throws Exception {
    Attribute attr = buildAttribute("a1", "attr.int(values = [1, 2])");
    PredicateWithMessage<Object> predicate = attr.getAllowedValues();
    assertThat(predicate.apply(2)).isTrue();
    assertThat(predicate.apply(3)).isFalse();
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) ClassObject(com.google.devtools.build.lib.syntax.ClassObject) Test(org.junit.Test)

Aggregations

Attribute (com.google.devtools.build.lib.packages.Attribute)76 Test (org.junit.Test)37 Label (com.google.devtools.build.lib.cmdline.Label)20 Rule (com.google.devtools.build.lib.packages.Rule)20 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)7 AttributeMap (com.google.devtools.build.lib.packages.AttributeMap)7 Target (com.google.devtools.build.lib.packages.Target)7 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)6 ConfigMatchingProvider (com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider)6 RuleClass (com.google.devtools.build.lib.packages.RuleClass)6 SkyKey (com.google.devtools.build.skyframe.SkyKey)6 LinkedHashSet (java.util.LinkedHashSet)6 Nullable (javax.annotation.Nullable)6 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)5 Map (java.util.Map)5 Dependency (com.google.devtools.build.lib.analysis.Dependency)4