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"));
}
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'");
}
Aggregations