Deprecate and remove several uses of the 'values' map in NativeInfo subclasses.
These subclasses should be using @SkylarkCallable(structField = true) instead
This is a bit of a memory win, as there is now no need to store field information twice.
There are still a couple of stragglers that are more difficult, namely ToolchainInfo and DefaultInfo. Their APIs will likely need some more extensive revamping before proceeding.
RELNOTES: None.
PiperOrigin-RevId: 187364392
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index 3b7bba3..a730069 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -25,6 +25,7 @@
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.lib.packages.NativeProvider;
import com.google.devtools.build.lib.skylarkinterface.Param;
@@ -1333,6 +1334,22 @@
}
@Test
+ public void testGetattrMethods() throws Exception {
+ new SkylarkTest()
+ .update("mock", new Mock())
+ .setUp("a = getattr(mock, 'struct_field', 'no')",
+ "b = getattr(mock, 'function', 'no')",
+ "c = getattr(mock, 'is_empty', 'no')",
+ "d = getattr('str', 'replace', 'no')",
+ "e = getattr(mock, 'other', 'no')\n")
+ .testLookup("a", "a")
+ .testLookup("b", "no")
+ .testLookup("c", "no")
+ .testLookup("d", "no")
+ .testLookup("e", "no");
+ }
+
+ @Test
public void testListAnTupleConcatenationDoesNotWorkInSkylark() throws Exception {
new SkylarkTest().testIfExactError("unsupported operand type(s) for +: 'list' and 'tuple'",
"[1, 2] + (3, 4)");
@@ -1540,7 +1557,8 @@
public String invoke() {
return "fromValues";
}
- }));
+ }),
+ Location.BUILTIN);
}
@SkylarkCallable(name = "callable_only_field", doc = "", structField = true)