Support running aspect in Bazel Sandbox by removing cwd override #824
+2
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now, the Bazel aspect does not support execution in a bazel sandbox (the default behaviour of Bazel on linux). This is due to the
sourceroot
andtargetroot
definitions pointing to locations within the repository itself, rather than locations in the bazel sandbox. If we attempt to run the aspect as-is inside of the bazel sandbox, we hit read only filesystem exceptions (as we are attempting to write to paths that live outside of the sandbox).When Bazel executes inside of the sandbox, it creates an execroot that only contains the files that have been included as inputs of the action. The structure of the execroot in practice is a mirror of the actual repository, except filtered down to the known input files. The current working directory of actions executed inside of the sandbox is a mirror of the workspace root outside of the sandbox.
For example, with the bazel root of
examples/bazel-example
, and executing the aspect onexamples/bazel-example/src/main/java/example
target, the sandbox would have the source file at location$SANDBOX/src/main/java/example/Example.java
, with the cwd set to$SANDBOX
.Right now, the aspect passes a
--cwd
flag toscip-java index
when executing inside the bazel action, which changes the working directory to outside of the sandbox, causing the issues mentioned earlier. However, if we remove the cwd override, and allowscip-java
to execute with the cwd set to$SANDBOX
, it still works appropriately without issue. The semanticdb and scip files are generated inside of the sandbox, however upon completion of the action, they will be present inbazel-out/
in the workspace still, andscip-java
can still pick this up to generate the finalindex.scip
. The semanticdb/scip files generated inside of the sandbox still use relative paths to the workspace root, so they are still applicable.This PR removes the cwd override to support executing the aspect inside of the bazel sandbox.
Test plan
We've run a patched version of this aspect on our codebase and it still seems to process correctly. Comparing a diff before and after the
index.scip
file forexamples/bazel-example
, the main difference is that before the project root is set to the current working directory ($REPO_ROOT/examples/bazel-example
), but after it is now a path into a sandbox (that will no longer exist upon completion). Runningscip snapshot
on the resulting index produces no diff of the output -- but, as before, we need to manually specify the project root as the current working directory.My understanding is that this change in project root is not an issue, as the upload should be clever enough to switch it with the cwd instead (this is equivalent to the situation where index.scip was generated on a different machine)