Skip to content

Commit

Permalink
Add test coverage for tree artifacts containing directory symlinks.
Browse files Browse the repository at this point in the history
We have been bitten twice by this use case. See bazelbuild#9054 and bazelbuild#11813.

Fixes bazelbuild#9058.

RELNOTES: None.
PiperOrigin-RevId: 322590818
  • Loading branch information
justinhorvitz authored and ehkloaj committed Aug 6, 2020
1 parent 2559841 commit d399222
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ private ActionExecutionValue(
}
for (Map.Entry<TreeFileArtifact, FileArtifactValue> file :
treeArtifact.getChildValues().entrySet()) {
// We should only have RegularFileValue instances in here, but apparently tree artifacts
// sometimes store their own root directory in here. Sad.
// https://github.com/bazelbuild/bazel/issues/9058
// Tree artifacts can contain symlinks to directories, which don't have a digest.
if (file.getValue().getType().isFile()) {
Preconditions.checkNotNull(
file.getValue().getDigest(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,28 @@ public void emptyInputAndOutputTreeArtifactInActionTemplate() throws Exception {
assertThat(artifact2.getPath().getDirectoryEntries()).isEmpty();
}

// This happens in the wild. See https://github.com/bazelbuild/bazel/issues/11813.
@Test
public void treeArtifactContainsSymlinkToDirectory() throws Exception {
SpecialArtifact treeArtifact = createTreeArtifact("tree");
registerAction(
new SimpleTestAction(/*output=*/ treeArtifact) {
@Override
void run(ActionExecutionContext context) throws IOException {
PathFragment subdir = PathFragment.create("subdir");
touchFile(treeArtifact.getPath().getRelative(subdir).getRelative("file"));
treeArtifact.getPath().getRelative("link").createSymbolicLink(subdir);
}
});

TreeArtifactValue tree = buildArtifact(treeArtifact);

assertThat(tree.getChildren())
.containsExactly(
TreeFileArtifact.createTreeOutput(treeArtifact, "subdir/file"),
TreeFileArtifact.createTreeOutput(treeArtifact, "link"));
}

private abstract static class SimpleTestAction extends TestAction {
private final Button button;

Expand Down

0 comments on commit d399222

Please sign in to comment.