Search in sources :

Example 26 with Attribute

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

the class AggregatingAttributeMapperTest method testDuplicateCheckOnNullValues.

@Test
public void testDuplicateCheckOnNullValues() throws Exception {
    if (getAnalysisMock().isThisBazel()) {
        return;
    }
    Rule rule = scratchRule("x", "main", "java_binary(", "    name = 'main',", "    srcs = ['main.java'])");
    AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
    Attribute launcherAttribute = mapper.getAttributeDefinition("launcher");
    assertNull(mapper.get(launcherAttribute.getName(), launcherAttribute.getType()));
    assertThat(mapper.checkForDuplicateLabels(launcherAttribute)).containsExactlyElementsIn(ImmutableList.of());
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Rule(com.google.devtools.build.lib.packages.Rule) AggregatingAttributeMapper(com.google.devtools.build.lib.packages.AggregatingAttributeMapper) Test(org.junit.Test)

Example 27 with Attribute

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

the class RuleDocumentationAttributeTest method testSynopsisForLabelListAttribute.

@Test
public void testSynopsisForLabelListAttribute() {
    Attribute attribute = Attribute.attr("some_labels", BuildType.LABEL_LIST).allowedRuleClasses("foo_rule").allowedFileTypes().build();
    RuleDocumentationAttribute attributeDoc = RuleDocumentationAttribute.create(TestRule.class, "testrule", "", 0, "", NO_FLAGS);
    attributeDoc.setAttribute(attribute);
    String doc = attributeDoc.getSynopsis();
    assertEquals("List of <a href=\"../build-ref.html#labels\">labels</a>; optional", doc);
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Test(org.junit.Test)

Example 28 with Attribute

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

the class RuleDocumentationAttributeTest method testSynopsisForStringAttribute.

@Test
public void testSynopsisForStringAttribute() {
    final String defaultValue = "9";
    Attribute attribute = Attribute.attr("foo_version", Type.STRING).value(defaultValue).build();
    RuleDocumentationAttribute attributeDoc = RuleDocumentationAttribute.create(TestRule.class, "testrule", "", 0, "", NO_FLAGS);
    attributeDoc.setAttribute(attribute);
    String doc = attributeDoc.getSynopsis();
    assertEquals("String; optional; default is \"" + defaultValue + "\"", doc);
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Test(org.junit.Test)

Example 29 with Attribute

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

the class RuleDocumentationAttributeTest method testSynopsisForMandatoryAttribute.

@Test
public void testSynopsisForMandatoryAttribute() {
    Attribute attribute = Attribute.attr("baz_labels", BuildType.LABEL).mandatory().allowedFileTypes(CppFileTypes.CPP_HEADER).build();
    RuleDocumentationAttribute attributeDoc = RuleDocumentationAttribute.create(TestRule.class, "testrule", "", 0, "", NO_FLAGS);
    attributeDoc.setAttribute(attribute);
    String doc = attributeDoc.getSynopsis();
    assertEquals("<a href=\"../build-ref.html#labels\">Label</a>; required", doc);
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Test(org.junit.Test)

Example 30 with Attribute

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

the class AspectAwareAttributeMapperTest method createMapper.

@Before
public final void createMapper() throws Exception {
    RuleConfiguredTarget ct = (RuleConfiguredTarget) scratchConfiguredTarget("foo", "myrule", "cc_binary(", "    name = 'myrule',", "    srcs = [':a.cc'],", "    linkstatic = select({'//conditions:default': 1}))");
    rule = ct.getTarget();
    Attribute aspectAttr = new Attribute.Builder<Label>("fromaspect", BuildType.LABEL).allowedFileTypes(FileTypeSet.ANY_FILE).build();
    aspectAttributes = ImmutableMap.<String, Attribute>of(aspectAttr.getName(), aspectAttr);
    mapper = new AspectAwareAttributeMapper(ConfiguredAttributeMapper.of(ct), aspectAttributes);
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Before(org.junit.Before)

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