Search in sources :

Example 16 with RuleClass

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(")");
    }
}
Also used : PackageFactory(com.google.devtools.build.lib.packages.PackageFactory) Attribute(com.google.devtools.build.lib.packages.Attribute) ArrayList(java.util.ArrayList) RuleClass(com.google.devtools.build.lib.packages.RuleClass)

Example 17 with RuleClass

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());
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 18 with RuleClass

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));
}
Also used : RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 19 with RuleClass

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());
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) RuleFunction(com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction) RuleClass(com.google.devtools.build.lib.packages.RuleClass) Test(org.junit.Test)

Example 20 with RuleClass

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));
}
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)23 RuleFunction (com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.RuleFunction)9 Test (org.junit.Test)9 Attribute (com.google.devtools.build.lib.packages.Attribute)6 ConfiguredRuleClassProvider (com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider)2 Rule (com.google.devtools.build.lib.packages.Rule)2 ArrayList (java.util.ArrayList)2 NoBuildEvent (com.google.devtools.build.lib.analysis.NoBuildEvent)1 ConfigurationFragmentFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory)1 FragmentOptions (com.google.devtools.build.lib.analysis.config.FragmentOptions)1 Label (com.google.devtools.build.lib.cmdline.Label)1 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)1 AdvertisedProviderSet (com.google.devtools.build.lib.packages.AdvertisedProviderSet)1 Aspect (com.google.devtools.build.lib.packages.Aspect)1 FileTarget (com.google.devtools.build.lib.packages.FileTarget)1 ImplicitOutputsFunction (com.google.devtools.build.lib.packages.ImplicitOutputsFunction)1 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)1 RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)1 RuleClassProvider (com.google.devtools.build.lib.packages.RuleClassProvider)1 AllowedRuleClassInfo (com.google.devtools.build.lib.query2.proto.proto2api.Build.AllowedRuleClassInfo)1