Expose structField callable methods of skylark objects to dir() and str() calls
RELNOTES: None.
PiperOrigin-RevId: 184498836
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/platform/PlatformInfoTest.java b/src/test/java/com/google/devtools/build/lib/analysis/platform/PlatformInfoTest.java
index fa0add7..8980635 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/platform/PlatformInfoTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/platform/PlatformInfoTest.java
@@ -95,12 +95,6 @@
.setLabel(makeLabel("//platform/plat1"))
.addConstraint(value1)
.addConstraint(value2)
- .build(),
- PlatformInfo.builder()
- .setLabel(makeLabel("//platform/plat1"))
- .addConstraint(value1)
- .addConstraint(value2)
- .setRemoteExecutionProperties("key=val") // execution properties are ignored.
.build())
.addEqualityGroup(
// Different label.
diff --git a/src/test/java/com/google/devtools/build/lib/packages/SkylarkProviderTest.java b/src/test/java/com/google/devtools/build/lib/packages/SkylarkProviderTest.java
index ef0b746..a4cb31a 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/SkylarkProviderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/SkylarkProviderTest.java
@@ -139,7 +139,7 @@
}
/** Asserts that a {@link SkylarkInfo} has fields a=1, b=2, c=3 (and nothing else). */
- private static void assertHasExactlyValuesA1B2C3(SkylarkInfo info) {
+ private static void assertHasExactlyValuesA1B2C3(SkylarkInfo info) throws Exception {
assertThat(info.getFieldNames()).containsExactly("a", "b", "c");
assertThat(info.getValue("a")).isEqualTo(1);
assertThat(info.getValue("b")).isEqualTo(2);
diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoSkylarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoSkylarkApiTest.java
index dc8b505..c0e9ade 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoSkylarkApiTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoSkylarkApiTest.java
@@ -19,7 +19,6 @@
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.Info;
import com.google.devtools.build.lib.packages.SkylarkProvider.SkylarkKey;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar;
@@ -724,7 +723,7 @@
}
}
- private JavaInfo fetchJavaInfo() throws LabelSyntaxException {
+ private JavaInfo fetchJavaInfo() throws Exception {
ConfiguredTarget myRuleTarget = getConfiguredTarget("//foo:my_skylark_rule");
Info info =
myRuleTarget.get(new SkylarkKey(Label.parseAbsolute("//foo:extension.bzl"), "result"));
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 6baa230..c234a92 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
@@ -76,6 +76,42 @@
};
@SkylarkModule(name = "Mock", doc = "")
+ static class NativeInfoMock extends NativeInfo {
+
+ private static final NativeProvider<NativeInfoMock> CONSTRUCTOR =
+ new NativeProvider<NativeInfoMock>(NativeInfoMock.class, "native_info_mock") {};
+
+ public NativeInfoMock() {
+ super(CONSTRUCTOR);
+ }
+
+ @SkylarkCallable(name = "callable_string", doc = "", structField = false)
+ public String callableString() {
+ return "a";
+ }
+
+ @SkylarkCallable(name = "struct_field_string", doc = "", structField = true)
+ public String structFieldString() {
+ return "a";
+ }
+
+ @SkylarkCallable(name = "struct_field_callable", doc = "", structField = true)
+ public BuiltinFunction structFieldCallable() {
+ return foobar;
+ }
+
+ @SkylarkCallable(
+ name = "struct_field_none",
+ doc = "",
+ structField = true,
+ allowReturnNones = true
+ )
+ public String structFieldNone() {
+ return null;
+ }
+ }
+
+ @SkylarkModule(name = "Mock", doc = "")
static class Mock {
@SkylarkCallable(doc = "")
public static Integer valueOf(String str) {
@@ -1193,7 +1229,7 @@
" return e",
"e = str(func())").testLookup("e", "[3, [1, 4]]");
}
-
+
@Test
public void testDictTupleAssignmentAsLValue() throws Exception {
new SkylarkTest().setUp("def func():",
@@ -1355,6 +1391,26 @@
}
@Test
+ public void testStrNativeInfo() throws Exception {
+ new SkylarkTest()
+ .update("mock", new NativeInfoMock())
+ .testEval(
+ "str(mock)",
+ "'struct(struct_field_callable = <built-in function foobar>, struct_field_none = None, "
+ + "struct_field_string = \"a\")'");
+ }
+
+ @Test
+ public void testDirNativeInfo() throws Exception {
+ new SkylarkTest()
+ .update("mock", new NativeInfoMock())
+ .testEval(
+ "dir(mock)",
+ "['callable_string', 'struct_field_callable', "
+ + "'struct_field_none', 'struct_field_string']");
+ }
+
+ @Test
public void testPrint() throws Exception {
// TODO(fwe): cannot be handled by current testing suite
setFailFast(false);
@@ -1561,10 +1617,10 @@
new SkylarkTest()
.update("val", new SkylarkClassObjectWithSkylarkCallables())
.testIfExactError(
- // TODO(bazel-team): This should probably list callable_only_field/method as well.
+ // TODO(bazel-team): This should probably list callable_only_method as well.
"'struct_with_skylark_callables' object has no attribute 'nonexistent_field'\n"
- + "Available attributes: collision_field, collision_method, values_only_field, "
- + "values_only_method",
+ + "Available attributes: callable_only_field, collision_field, collision_method, "
+ + "values_only_field, values_only_method",
"v = val.nonexistent_field");
}