Make some objects SkylarkValues
Skylark's Printer.BasePrinter doesn't guarantee it will call `.toString` on
objects of unknown types, and in the future that won't be the case anymore.
In order to keep their current string representations objects should implement
the SkylarkValue interface by providing an explicit implementation of `repr`.
PiperOrigin-RevId: 161526182
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
index 8640f26..e276793 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
@@ -17,6 +17,8 @@
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.Canonicalizer;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -27,12 +29,13 @@
/**
* Uniquely identifies a package, given a repository name and a package's path fragment.
*
- * <p>The repository the build is happening in is the <i>default workspace</i>, and is identified
- * by the workspace name "". Other repositories can be named in the WORKSPACE file. These
- * workspaces are prefixed by {@literal @}.</p>
+ * <p>The repository the build is happening in is the <i>default workspace</i>, and is identified by
+ * the workspace name "". Other repositories can be named in the WORKSPACE file. These workspaces
+ * are prefixed by {@literal @}.
*/
@Immutable
-public final class PackageIdentifier implements Comparable<PackageIdentifier>, Serializable {
+public final class PackageIdentifier
+ implements Comparable<PackageIdentifier>, Serializable, SkylarkValue {
private static final Interner<PackageIdentifier> INTERNER = BlazeInterners.newWeakInterner();
@@ -216,4 +219,9 @@
.compare(pkgName, that.pkgName)
.result();
}
+
+ @Override
+ public void repr(SkylarkPrinter printer) {
+ printer.repr(toString());
+ }
}