Search in sources :

Example 1 with RuleFunction

use of com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testRuleAddMultipleAttributes.

@Test
public void testRuleAddMultipleAttributes() throws Exception {
    evalAndExport("def impl(ctx): return None", "r1 = rule(impl,", "     attrs = {", "            'a1': attr.label_list(allow_files=True),", "            'a2': attr.int()", "})");
    RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
    assertTrue(c.hasAttr("a1", BuildType.LABEL_LIST));
    assertTrue(c.hasAttr("a2", Type.INTEGER));
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 2 with RuleFunction

use of com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testRuleOutputs.

@Test
public void testRuleOutputs() throws Exception {
    evalAndExport("def impl(ctx): return None", "r1 = rule(impl, outputs = {'a': 'a.txt'})");
    RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
    ImplicitOutputsFunction function = c.getDefaultImplicitOutputsFunction();
    assertEquals("a.txt", Iterables.getOnlyElement(function.getImplicitOutputs(null)));
}
Also used : ImplicitOutputsFunction(com.google.devtools.build.lib.packages.ImplicitOutputsFunction) RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 3 with RuleFunction

use of com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testRuleImplementation.

@Test
public void testRuleImplementation() throws Exception {
    evalAndExport("def impl(ctx): return None", "rule1 = rule(impl)");
    RuleClass c = ((RuleFunction) lookup("rule1")).getRuleClass();
    assertEquals("impl", c.getConfiguredTargetFunction().getName());
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 4 with RuleFunction

use of com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testRuleAttributeFlag.

@Test
public void testRuleAttributeFlag() throws Exception {
    evalAndExport("def impl(ctx): return None", "r1 = rule(impl, attrs = {'a1': attr.string(mandatory=True)})");
    RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
    assertTrue(c.getAttributeByName("a1").isMandatory());
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 5 with RuleFunction

use of com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testRuleInheritsBaseRuleAttributes.

@Test
public void testRuleInheritsBaseRuleAttributes() throws Exception {
    evalAndExport("def impl(ctx): return None", "r1 = rule(impl)");
    RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
    assertTrue(c.hasAttr("tags", Type.STRING_LIST));
    assertTrue(c.hasAttr("visibility", BuildType.NODEP_LABEL_LIST));
    assertTrue(c.hasAttr("deprecation", Type.STRING));
    // required for extra actions
    assertTrue(c.hasAttr(":action_listener", BuildType.LABEL_LIST));
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Aggregations

RuleClass (com.google.devtools.build.lib.packages.RuleClass)9 RuleFunction (com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction)9 Test (org.junit.Test)9 Attribute (com.google.devtools.build.lib.packages.Attribute)2 ImplicitOutputsFunction (com.google.devtools.build.lib.packages.ImplicitOutputsFunction)1