Search in sources :

Example 1 with ClassObject

use of com.google.devtools.build.lib.syntax.ClassObject in project bazel by bazelbuild.

the class SkylarkRuleClassFunctionsTest method testStructFields.

@Test
public void testStructFields() throws Exception {
    // TODO(fwe): cannot be handled by current testing suite
    eval("x = struct(a = 1, b = 2)");
    ClassObject x = (ClassObject) lookup("x");
    assertEquals(1, x.getValue("a"));
    assertEquals(2, x.getValue("b"));
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) ClassObject(com.google.devtools.build.lib.syntax.ClassObject) Test(org.junit.Test)

Example 2 with ClassObject

use of com.google.devtools.build.lib.syntax.ClassObject in project bazel by bazelbuild.

the class PackageFactory method newNativeModule.

/**
   * Returns a native module with the functions created using the {@link RuleClassProvider}
   * of this {@link PackageFactory}.
   */
private ClassObject newNativeModule() {
    ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
    for (String nativeFunction : Runtime.getFunctionNames(SkylarkNativeModule.class)) {
        builder.put(nativeFunction, Runtime.getFunction(SkylarkNativeModule.class, nativeFunction));
    }
    for (String ruleClass : ruleFactory.getRuleClassNames()) {
        builder.put(ruleClass, newRuleFunction(ruleFactory, ruleClass));
    }
    builder.put("package", newPackageFunction(packageArguments));
    for (EnvironmentExtension extension : environmentExtensions) {
        for (BaseFunction function : extension.nativeModuleFunctions()) {
            builder.put(function.getName(), function);
        }
    }
    return NativeClassObjectConstructor.STRUCT.create(builder.build(), "no native function or rule '%s'");
}
Also used : BaseFunction(com.google.devtools.build.lib.syntax.BaseFunction) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ClassObject(com.google.devtools.build.lib.syntax.ClassObject) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ClassObject (com.google.devtools.build.lib.syntax.ClassObject)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)1 BaseFunction (com.google.devtools.build.lib.syntax.BaseFunction)1 Test (org.junit.Test)1