From 2b4364aaef955f1a00c184711db1180ba62719bb Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 11 Dec 2023 06:38:15 -0800 Subject: [PATCH] Include the blaze-out relative path in local file ouput artifact equals implementation. These objects are used as map keys. It is also possible for the same local file artifact (being, in this instance, a checked-in source file) to appear twice in the BES, if it is used by multiple configurations. Using just the file path for the `equals`/`hashcode` implementation results in duplicate key errors in that instance. Including the blaze-out relative path also fixes that, and also makes the implementation more consistent with `RemoteOutputArtifact` which implements the same interface and is used in the same way. PiperOrigin-RevId: 589806826 --- .../android/libraries/RenderJarCacheTest.java | 2 +- .../LocalFileOutputArtifactWithoutDigest.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/aswb/tests/unittests/com/google/idea/blaze/android/libraries/RenderJarCacheTest.java b/aswb/tests/unittests/com/google/idea/blaze/android/libraries/RenderJarCacheTest.java index 6236d0f5f4d..94ca66841c6 100644 --- a/aswb/tests/unittests/com/google/idea/blaze/android/libraries/RenderJarCacheTest.java +++ b/aswb/tests/unittests/com/google/idea/blaze/android/libraries/RenderJarCacheTest.java @@ -190,7 +190,7 @@ public void onSync_passesCorrectJarsToArtifactCache() { .putAll(artifactsCaptor.capture(), contextCaptor.capture(), removeCaptor.capture()); Collection passedArtifact = artifactsCaptor.getValue(); - assertThat(passedArtifact.stream().map(Object::toString)) + assertThat(passedArtifact.stream().map(OutputArtifactWithoutDigest::getRelativePath)) .containsExactly( "com/foo/bar/baz/baz_render_jar.jar", "com/foo/bar/qux/qux_render_jar.jar"); } diff --git a/base/src/com/google/idea/blaze/base/command/buildresult/LocalFileOutputArtifactWithoutDigest.java b/base/src/com/google/idea/blaze/base/command/buildresult/LocalFileOutputArtifactWithoutDigest.java index a856e72c12a..4f366afc6bc 100644 --- a/base/src/com/google/idea/blaze/base/command/buildresult/LocalFileOutputArtifactWithoutDigest.java +++ b/base/src/com/google/idea/blaze/base/command/buildresult/LocalFileOutputArtifactWithoutDigest.java @@ -15,6 +15,8 @@ */ package com.google.idea.blaze.base.command.buildresult; +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; import com.google.errorprone.annotations.MustBeClosed; import com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact; import com.google.idea.blaze.base.filecache.ArtifactState; @@ -81,16 +83,22 @@ public boolean equals(Object obj) { if (!(obj instanceof LocalFileOutputArtifactWithoutDigest)) { return false; } - return file.getPath().equals(((LocalFileOutputArtifactWithoutDigest) obj).file.getPath()); + LocalFileOutputArtifactWithoutDigest that = (LocalFileOutputArtifactWithoutDigest) obj; + return Objects.equal(this.file.getPath(), that.file.getPath()) + && Objects.equal(this.blazeOutRelativePath, that.blazeOutRelativePath); } @Override public int hashCode() { - return file.getPath().hashCode(); + return Objects.hashCode(file.getPath(), blazeOutRelativePath); } @Override public String toString() { - return blazeOutRelativePath; + return MoreObjects.toStringHelper(this) + .add("file", file.getPath()) + .add("blazeOutRelativePat", blazeOutRelativePath) + .add("configurationMnemonic", configurationMnemonic) + .toString(); } }