Skip to content

Commit

Permalink
executor/dirtools: ensure UploadTree set result symlinks (#3800)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Duffany <[email protected]>
  • Loading branch information
sluongng and bduffany authored Apr 27, 2023
1 parent aef2416 commit eb3e711
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 5 deletions.
2 changes: 2 additions & 0 deletions enterprise/server/remote_execution/dirtools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ go_test(
"//proto:remote_execution_go_proto",
"//proto:resource_go_proto",
"//server/remote_cache/byte_stream_server",
"//server/remote_cache/content_addressable_storage_server",
"//server/remote_cache/digest",
"//server/testutil/testenv",
"//server/testutil/testfs",
"//server/util/hash",
"//server/util/prefix",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@go_googleapis//google/bytestream:bytestream_go_proto",
],
)
35 changes: 33 additions & 2 deletions enterprise/server/remote_execution/dirtools/dirtools.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func NewDirHelper(rootDir string, outputDirectories, outputPaths []string, dirPe
// of the output_directories, so go ahead and do that. The directories are
// also present in output_paths, so they're forgotten after creation here
// and then selected for upload through the output_paths.
//
// As of Bazel 6.0.0, the output directories are included as part of the
// InputRoot, so this hack is only needed for older clients.
// See: https://github.com/bazelbuild/bazel/pull/15366 for more info.
for _, outputDirectory := range outputDirectories {
fullPath := filepath.Join(c.rootDir, outputDirectory)
c.dirsToCreate = append(c.dirsToCreate, fullPath)
Expand Down Expand Up @@ -285,7 +289,7 @@ func uploadFiles(uploader *cachetools.BatchCASUploader, fc interfaces.FileCache,
return nil
}

func UploadTree(ctx context.Context, env environment.Env, dirHelper *DirHelper, instanceName string, digestFunction repb.DigestFunction_Value, rootDir string, actionResult *repb.ActionResult) (*TransferInfo, error) {
func UploadTree(ctx context.Context, env environment.Env, dirHelper *DirHelper, instanceName string, digestFunction repb.DigestFunction_Value, rootDir string, cmd *repb.Command, actionResult *repb.ActionResult) (*TransferInfo, error) {
txInfo := &TransferInfo{}
startTime := time.Now()
treesToUpload := make([]string, 0)
Expand Down Expand Up @@ -325,7 +329,7 @@ func UploadTree(ctx context.Context, env environment.Env, dirHelper *DirHelper,
return nil, err
}
fqfn := filepath.Join(fullPath, info.Name())
if info.Mode().IsDir() {
if info.IsDir() {
// Don't recurse on non-uploadable directories.
if !dirHelper.ShouldUploadAnythingInDir(fqfn) {
continue
Expand Down Expand Up @@ -357,6 +361,33 @@ func UploadTree(ctx context.Context, env environment.Env, dirHelper *DirHelper,
if err != nil {
return nil, err
}

// OutputFileSymlinks and OutputDirectorySymlinks are deprecated in REAPI v2.1,
// but Bazel still uses them as of v6.2.0.
//
// TODO(sluongng): Set OutputSymlinks when Bazel has support for it.
// References:
// - https://github.com/bazelbuild/remote-apis/blob/35aee1c4a4250d3df846f7ba3e4a4e66cb014ecd/build/bazel/remote/execution/v2/remote_execution.proto#L1071
// - https://github.com/bazelbuild/bazel/pull/18198
// - https://github.com/bazelbuild/bazel/pull/18202
symlinkPath := trimPathPrefix(fqfn, rootDir)
symlink := &repb.OutputSymlink{
Path: symlinkPath,
Target: target,
}
for _, expectedFile := range cmd.OutputFiles {
if symlinkPath == expectedFile {
actionResult.OutputFileSymlinks = append(actionResult.OutputFileSymlinks, symlink)
break
}
}
for _, expectedDir := range cmd.OutputDirectories {
if symlinkPath == expectedDir {
actionResult.OutputDirectorySymlinks = append(actionResult.OutputDirectorySymlinks, symlink)
break
}
}

directory.Symlinks = append(directory.Symlinks, &repb.SymlinkNode{
Name: trimPathPrefix(fqfn, rootDir),
Target: target,
Expand Down
Loading

0 comments on commit eb3e711

Please sign in to comment.