diff options
Diffstat (limited to 'src')
3 files changed, 33 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkClassObject.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkClassObject.java index 963b30eee6..b65411f00c 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkClassObject.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkClassObject.java @@ -238,6 +238,23 @@ public class SkylarkClassObject implements ClassObject, SkylarkValue, Concatable @Override public void repr(SkylarkPrinter printer) { boolean first = true; + printer.append("struct("); + // Sort by key to ensure deterministic output. + for (String key : Ordering.natural().sortedCopy(values.keySet())) { + if (!first) { + printer.append(", "); + } + first = false; + printer.append(key); + printer.append(" = "); + printer.repr(values.get(key)); + } + printer.append(")"); + } + + @Override + public void reprLegacy(SkylarkPrinter printer) { + boolean first = true; printer.append(constructor.getPrintableName()); printer.append("("); // Sort by key to ensure deterministic output. diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkClassObjectConstructor.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkClassObjectConstructor.java index 03b4ddb7d9..8bd600852a 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkClassObjectConstructor.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkClassObjectConstructor.java @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.packages; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.Location; +import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.FunctionSignature; import com.google.devtools.build.lib.syntax.SkylarkType; @@ -123,6 +124,11 @@ public class SkylarkClassObjectConstructor extends ClassObjectConstructor return isExported(); } + @Override + public void repr(SkylarkPrinter printer) { + printer.append("<provider>"); + } + /** * A serializable representation of Skylark-defined {@link SkylarkClassObjectConstructor} * that uniquely identifies all {@link SkylarkClassObjectConstructor}s that @@ -169,5 +175,4 @@ public class SkylarkClassObjectConstructor extends ClassObjectConstructor && Objects.equals(this.exportedName, other.exportedName); } } - } diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java index 82e2c1e1c1..01686d6c96 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java @@ -238,6 +238,15 @@ public class SkylarkStringRepresentationsTest extends SkylarkTestCase { } @Test + public void testStringRepresentations_Providers() throws Exception { + setSkylarkSemanticsOptions("--incompatible_descriptive_string_representations=true"); + + assertStringRepresentation("provider()", "<provider>"); + assertStringRepresentation( + "p = provider()", "p(b = 'foo', a = 1)", "struct(a = 1, b = \"foo\")"); + } + + @Test public void testStringRepresentations_Select() throws Exception { setSkylarkSemanticsOptions("--incompatible_descriptive_string_representations=true"); @@ -312,7 +321,7 @@ public class SkylarkStringRepresentationsTest extends SkylarkTestCase { setSkylarkSemanticsOptions("--incompatible_descriptive_string_representations=false"); assertStringRepresentation("provider()", "<function <no name>>"); - assertStringRepresentation("p = provider()", "p(b = 2, a = 1)", "p(a = 1, b = 2)"); + assertStringRepresentation("p = provider()", "p(b = 'foo', a = 1)", "p(a = 1, b = \"foo\")"); } @Test |