use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.
the class DumpCommand method dumpRuleClasses.
private void dumpRuleClasses(BlazeRuntime runtime, PrintStream out) {
PackageFactory factory = runtime.getPackageFactory();
List<String> ruleClassNames = new ArrayList<>(factory.getRuleClassNames());
Collections.sort(ruleClassNames);
for (String name : ruleClassNames) {
if (name.startsWith("$")) {
continue;
}
RuleClass ruleClass = factory.getRuleClass(name);
out.print(ruleClass + "(");
boolean first = true;
for (Attribute attribute : ruleClass.getAttributes()) {
if (attribute.isImplicit()) {
continue;
}
if (first) {
first = false;
} else {
out.print(", ");
}
out.print(attribute.getName());
}
out.println(")");
}
}
use of com.google.devtools.build.lib.packages.RuleClass 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());
}
use of com.google.devtools.build.lib.packages.RuleClass 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));
}
use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.
the class SkylarkRuleClassFunctionsTest method testIntDefaultValue.
@Test
public void testIntDefaultValue() throws Exception {
evalAndExport("def impl(ctx): return None", "r1 = rule(impl, attrs = {'a1': attr.int(default = 40+2)})");
RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
Attribute a = c.getAttributeByName("a1");
assertEquals(42, a.getDefaultValueForTesting());
}
use of com.google.devtools.build.lib.packages.RuleClass in project bazel by bazelbuild.
the class SkylarkRuleClassFunctionsTest method testRuleAddAttribute.
@Test
public void testRuleAddAttribute() throws Exception {
evalAndExport("def impl(ctx): return None", "r1 = rule(impl, attrs={'a1': attr.string()})");
RuleClass c = ((RuleFunction) lookup("r1")).getRuleClass();
assertTrue(c.hasAttr("a1", Type.STRING));
}
Aggregations