Skip to content

Commit

Permalink
Include the blaze-out relative path in local file ouput artifact equa…
Browse files Browse the repository at this point in the history
…ls 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: 589819515
  • Loading branch information
Googler authored and copybara-github committed Dec 11, 2023
1 parent f486224 commit 372339b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void onSync_passesCorrectJarsToArtifactCache() {
.putAll(artifactsCaptor.capture(), contextCaptor.capture(), removeCaptor.capture());

Collection<OutputArtifactWithoutDigest> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 372339b

Please sign in to comment.