-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify sandbox/remote handling of empty TreeArtifact inputs #15276
Conversation
89f1519
to
d698d7e
Compare
94325a4
to
8cc1f77
Compare
@bazelbuild/remote-execution |
Still working on this one, there are test failures I don't understand yet. |
43fbd19
to
ce8e17c
Compare
@brentleyjones The tests are passing now, had to fix one case of an unexpanded |
ce8e17c
to
d465fa9
Compare
@cushon I just learned about #6393, which seems quite related to this PR. Would you appreciate a PR that fixes #6393 by having Bazel (rather than the remote executor) create the output directories? Fixing these issues would help ongoing work of @gregestren and me on #6526. |
@coeuvre Would you be available to review this PR or should I ask someone else? It's my first PR in the area, so I don't know the usual process yet. |
Yes, I can take this one. Thanks for your PR! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR only covers the case of empty dir as input.
src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTreeBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/exec/SpawnInputExpander.java
Show resolved
Hide resolved
@@ -586,7 +586,6 @@ private static Spawn createCoveragePostProcessingSpawn( | |||
.addTransitive(action.getInputs()) | |||
.addAll(expandedCoverageDir) | |||
.add(action.getCollectCoverageScript()) | |||
.add(action.getCoverageDirectoryTreeArtifact()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why this is removed. Can you explain a bit more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is passed the expanded coverage dir TreeArtifact
in expandedCoverageDir
and adds the contained files to the spawn inputs. In addition, it also used to add the TreeArtifact
itself, which doesn't really make sense to me: Either SpawnInputExpander
can expand the TreeArtifact
, in which case expanding it manually wouldn't be necessary here, or it can't, in which case it would expand to nothing just like an empty TreeArtifact
prior to this change.
It turns out that the latter is the case: For some reason beyond my understanding, the coverage directory TreeArtifact
is created in a way so that SpawnInputExpander
fails to see as non-empty, but
bazel/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
Line 834 in 5343d7c
ImmutableSet<? extends ActionInput> expandedCoverageDir = |
Since the coverage script creates the coverage directory anyway in
bazel/tools/test/collect_coverage.sh
Line 75 in f2a7475
mkdir -p "$COVERAGE_DIR" |
The commit that introduced the coverage directory TreeArtifact
expansion logic is a445cda. If you would like a better explanation for why this artifact can't be expanded in the usual way, I could ping the author.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. SpawnInputExpander
can only expand inputs which are existing prior to action execution. This post-processing spawn is collecting inputs generated by previous spawn which are not visible to SpawnInputExpander
so it is always expand to nothing -- that's the reason why we manually expand tree artifact here by reading directly from metadata provider.
I think it's safe to remove this line here. but @oquenchil can you confirm since you originally wrote this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it looks safe to me.
src/main/java/com/google/devtools/build/lib/exec/SpawnInputExpander.java
Outdated
Show resolved
Hide resolved
d465fa9
to
7f94842
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review. I addressed the comments and also updated the commit/PR title to reflect the fact that it only deals with inputs.
src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTreeBuilder.java
Outdated
Show resolved
Hide resolved
@@ -586,7 +586,6 @@ private static Spawn createCoveragePostProcessingSpawn( | |||
.addTransitive(action.getInputs()) | |||
.addAll(expandedCoverageDir) | |||
.add(action.getCollectCoverageScript()) | |||
.add(action.getCoverageDirectoryTreeArtifact()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is passed the expanded coverage dir TreeArtifact
in expandedCoverageDir
and adds the contained files to the spawn inputs. In addition, it also used to add the TreeArtifact
itself, which doesn't really make sense to me: Either SpawnInputExpander
can expand the TreeArtifact
, in which case expanding it manually wouldn't be necessary here, or it can't, in which case it would expand to nothing just like an empty TreeArtifact
prior to this change.
It turns out that the latter is the case: For some reason beyond my understanding, the coverage directory TreeArtifact
is created in a way so that SpawnInputExpander
fails to see as non-empty, but
bazel/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
Line 834 in 5343d7c
ImmutableSet<? extends ActionInput> expandedCoverageDir = |
Since the coverage script creates the coverage directory anyway in
bazel/tools/test/collect_coverage.sh
Line 75 in f2a7475
mkdir -p "$COVERAGE_DIR" |
The commit that introduced the coverage directory TreeArtifact
expansion logic is a445cda. If you would like a better explanation for why this artifact can't be expanded in the usual way, I could ping the author.
src/main/java/com/google/devtools/build/lib/exec/SpawnInputExpander.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/exec/SpawnInputExpander.java
Outdated
Show resolved
Hide resolved
7f94842
to
ce38834
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me, but I will wait for @oquenchil to confirm the change of coverage before importing. Thanks!
@coeuvre I pushed a small commit to fix an issue with The alternative approach I pursued in #15371 - expanding empty |
Actions that take a TreeArtifact as input should see a corresponding directory even if the TreeArtifact is empty. Previously, SandboxHelpers contained special handling for the case of empty TreeArtifact action inputs to ensure that they are added to the sandbox as empty directories. As pointed out in a comment, this logic should live in SpawnInputExpander, where it would also apply to remote execution. This commit adds a integration tests for this previously untested case, extracts the logic into SpawnInputExpander and adapts DirectoryTreeBuilder to handle empty TreeArtifacts when creating the Merkle trees. Note: The Merkle tree builder now reports an error when it encounters a non-empty TreeArtifact. Such an artifact should have been expanded by SpawnInputExpander and if it wasn't, e.g. because it wasn't properly registered with Skyframe, it can't be expanded at this point anyway. The tests uncovered that the spawn for split coverage postprocessing declared the coverage dir artifact as such an input. In this case, it can simply be removed as the coverage script creates the coverage dir if it doesn't exist.
ba8bf13
to
ab82887
Compare
I resolved merge conflicts and used the opportunity to squash the commits. |
@bazel-io flag |
@bazel-io fork 5.2.0 |
Actions that take a TreeArtifact as input should see a corresponding directory even if the TreeArtifact is empty. Previously, SandboxHelpers contained special handling for the case of empty TreeArtifact action inputs to ensure that they are added to the sandbox as empty directories. As pointed out in a comment, this logic should live in SpawnInputExpander, where it would also apply to remote execution. This commit adds a integration tests for this previously untested case, extracts the logic into SpawnInputExpander and adapts DirectoryTreeBuilder to handle empty TreeArtifacts when creating the Merkle trees. Note: The Merkle tree builder now reports an error when it encounters a non-empty TreeArtifact. Such an artifact should have been expanded by SpawnInputExpander and if it wasn't, e.g. because it wasn't properly registered with Skyframe, it can't be expanded at this point anyway. The tests uncovered that the spawn for split coverage postprocessing declared the coverage dir artifact as such an input. In this case, it can simply be removed as the coverage script creates the coverage dir if it doesn't exist. Closes #15276. PiperOrigin-RevId: 446452587 Co-authored-by: Fabian Meumertzheim <[email protected]>
Actions that take a TreeArtifact as input should see a corresponding directory even if the TreeArtifact is empty. Previously, SandboxHelpers contained special handling for the case of empty TreeArtifact action inputs to ensure that they are added to the sandbox as empty directories. As pointed out in a comment, this logic should live in SpawnInputExpander, where it would also apply to remote execution. This commit adds a integration tests for this previously untested case, extracts the logic into SpawnInputExpander and adapts DirectoryTreeBuilder to handle empty TreeArtifacts when creating the Merkle trees. Note: The Merkle tree builder now reports an error when it encounters a non-empty TreeArtifact. Such an artifact should have been expanded by SpawnInputExpander and if it wasn't, e.g. because it wasn't properly registered with Skyframe, it can't be expanded at this point anyway. The tests uncovered that the spawn for split coverage postprocessing declared the coverage dir artifact as such an input. In this case, it can simply be removed as the coverage script creates the coverage dir if it doesn't exist. Closes #15276. PiperOrigin-RevId: 446452587 Co-authored-by: Fabian Meumertzheim <[email protected]>
Actions that take a TreeArtifact as input should see a corresponding
directory even if the TreeArtifact is empty.
Previously, SandboxHelpers contained special handling for the case of
empty TreeArtifact action inputs to ensure that they are added to the
sandbox as empty directories. As pointed out in a comment, this logic
should live in SpawnInputExpander, where it would also apply to remote
execution.
This commit adds a integration tests for this previously untested case,
extracts the logic into SpawnInputExpander and adapts
DirectoryTreeBuilder to handle empty TreeArtifacts when creating the
Merkle trees.
Note: The Merkle tree builder now reports an error when it encounters a
non-empty TreeArtifact. Such an artifact should have been expanded by
SpawnInputExpander and if it wasn't, e.g. because it wasn't properly
registered with Skyframe, it can't be expanded at this point anyway.
The tests uncovered that the spawn for split coverage postprocessing declared the
coverage dir artifact as such an input. In this case, it can simply be
removed as the coverage script creates the coverage dir if it doesn't
exist.