Skip to content

Commit

Permalink
Ensure parent directories of action outputs are made writable when bu…
Browse files Browse the repository at this point in the history
…ilding without the bytes.

Fixes bazelbuild#23462.

Closes bazelbuild#23555.

PiperOrigin-RevId: 672863567
Change-Id: I50af46f2ae637fb478e81ae31bd16ac4e306fe40
  • Loading branch information
tjgq authored and copybara-github committed Sep 10, 2024
1 parent c0a006a commit 885a6ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void createActionFsOutputDirectories(
if (done.add(outputDir)) {
try {
outputDir.createDirectoryAndParents();
outputDir.setWritable(true);
continue;
} catch (IOException e) {
/* Fall through to plan B. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,21 +1138,43 @@ public void multiplePackagePaths_buildsSuccessfully() throws Exception {
}

@Test
public void incrementalBuild_deleteOutputsInUnwritableParentDirectory() throws Exception {
public void incrementalBuild_unwritableParentDirectory_outputExists() throws Exception {
write(
"BUILD",
"genrule(",
" name = 'unwritable',",
" srcs = ['file.in'],",
" outs = ['unwritable/somefile.out'],",
" cmd = 'cat $(SRCS) > $@; chmod a-w $$(dirname $@)',",
" cmd = 'cat $(SRCS) > $@',",
" local = True,",
")");
write("file.in", "content");
buildTarget("//:unwritable");

getOutputPath("unwritable").setWritable(false);

write("file.in", "updated content");
buildTarget("//:unwritable");
}

@Test
public void incrementalBuild_unwritableParentDirectory_outputDoesNotExist() throws Exception {
write(
"BUILD",
"genrule(",
" name = 'unwritable',",
" srcs = ['file.in'],",
" outs = ['unwritable/somefile.out'],",
" cmd = 'cat $(SRCS) > $@',",
" local = True,",
")");
write("file.in", "content");
buildTarget("//:unwritable");

getOutputPath("unwritable/somefile.out").delete();
getOutputPath("unwritable").setWritable(false);

write("file.in", "updated content");
buildTarget("//:unwritable");
}

Expand Down

0 comments on commit 885a6ba

Please sign in to comment.