Skip to content

Commit e270b50

Browse files
fix(cli): use localExecRoot if possible when constructing path to results files (#7299)
Synced from #768 by withered-magic: use `localExecRoot` if possible when constructing path to results files during `aspect lint` --- Currently, when remote caching is enabled and `readBEPFile` needs to handle `bytestream` URIs, it constructs the path to the corresponding results file using the workspace root, such that the resulting path looks something like `/path/to/workspace/bazel-out/k8-fastbuild/bin/path/to/file`. However, this only works if the convenience symlinks are in place; if the convenience symlinks have been disabled, e.g. if `--experimental_convenience_symlinks=ignore` is specified in `.bazelrc`, then such paths are no longer valid, and `aspect lint` fails with the following sort of error: ``` Error: failed to find lint results file /path/to/workspace/bazel-out/k8-fastbuild/bin/file1.AspectRulesLintESLint.out.exit_code: stat /path/to/workspace/bazel-out/k8-fastbuild/bin/file1.AspectRulesLintESLint.out.exit_code: no such file or directory ``` Therefore, in the case when the convenience symlinks are missing, the path to the results file must be constructed using the execroot as the base. Fortunately, since we are already processing BEP events, we can simply use the `workspaceInfo` event to record the current execroot and later use it to construct paths as needed. --- ### Changes are visible to end-users: yes - Searched for relevant documentation and updated as needed: yes - Breaking change (forces users to change their own code or config): no - Suggested release notes appear below: yes ### Test plan - Manual testing; please provide instructions so we can reproduce: Added a repro with instructions here: https://github.com/withered-magic/aspect-cli-repro Closes [#768](#768) Co-authored-by: withered-magic <withering.magic@gmail.com> GitOrigin-RevId: 9141bac4333aeb052c0f9aec1e6b3683a45d2adc
1 parent f53c08f commit e270b50

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/aspect/lint/bep.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type ResultForLabel struct {
4040
type LintBEPHandler struct {
4141
namedSets map[string]*buildeventstream.NamedSetOfFiles
4242
workspaceRoot string
43+
localExecRoot string
4344
besCompleted chan<- struct{}
4445
resultsByLabel map[string]*ResultForLabel
4546
}
@@ -71,7 +72,14 @@ func (runner *LintBEPHandler) readBEPFile(file *buildeventstream.File) ([]byte,
7172
}
7273
// Because we set --experimental_remote_download_regex, we can depend on the results file being
7374
// in the output tree even when using a remote cache with build without the bytes.
74-
resultsFile = path.Join(runner.workspaceRoot, path.Join(file.PathPrefix...), file.Name)
75+
// If possible, we use the localExecRoot from the workspaceInfo event when constructing the path
76+
// to the results file in case the convenience symlinks are not present, e.g. if
77+
// --experimental_convenience_symlinks=ignore is specified.
78+
root := runner.workspaceRoot
79+
if runner.localExecRoot != "" {
80+
root = runner.localExecRoot
81+
}
82+
resultsFile = path.Join(root, path.Join(file.PathPrefix...), file.Name)
7583
} else {
7684
return nil, fmt.Errorf("unsupported BES file uri %v", f.Uri)
7785
}
@@ -122,6 +130,9 @@ func parseLinterMnemonicFromFilename(filename string) string {
122130
func (runner *LintBEPHandler) bepEventCallback(event *buildeventstream.BuildEvent) error {
123131
switch event.Payload.(type) {
124132

133+
case *buildeventstream.BuildEvent_WorkspaceInfo:
134+
runner.localExecRoot = event.GetWorkspaceInfo().GetLocalExecRoot()
135+
125136
case *buildeventstream.BuildEvent_NamedSetOfFiles:
126137
runner.namedSets[event.Id.GetNamedSet().Id] = event.GetNamedSetOfFiles()
127138

0 commit comments

Comments
 (0)