Skip to content

Commit

Permalink
Copy NodeProperties instead of importing into command.proto (bazelbui…
Browse files Browse the repository at this point in the history
…ld#503)

* Copy definition of NodeProperties instead of importing into command.proto

* Fix linter issues

* Update command.proto to add reasoning for avoiding import

* Update command.proto

* Fix typos
  • Loading branch information
bentekkie authored Sep 5, 2023
1 parent 2caea49 commit bb66956
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 259 deletions.
3 changes: 1 addition & 2 deletions go/api/command/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ proto_library(
srcs = ["command.proto"],
visibility = ["//visibility:public"],
deps = [
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:wrappers_proto",
],
)

Expand All @@ -17,7 +17,6 @@ go_proto_library(
importpath = "github.com/bazelbuild/remote-apis-sdks/go/api/command",
proto = ":command_proto",
visibility = ["//visibility:public"],
deps = ["@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto"],
)

go_library(
Expand Down
536 changes: 347 additions & 189 deletions go/api/command/command.pb.go

Large diffs are not rendered by default.

30 changes: 28 additions & 2 deletions go/api/command/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ syntax = "proto3";

package cmd;

import "build/bazel/remote/execution/v2/remote_execution.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";

// A command to execute locally or remotely.
message Command {
Expand Down Expand Up @@ -126,7 +126,33 @@ message InputSpec {
SymlinkBehaviorType.Value symlink_behavior = 6;

// Node properties of inputs.
map<string,build.bazel.remote.execution.v2.NodeProperties> input_node_properties = 7;
map<string,NodeProperties> input_node_properties = 7;
}

// A copy of NodeProperties from https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/execution/v2/remote_execution.proto
// to avoid importing it as a proto dependency.
// Importing the messages causes resource exhaustion on high parallelism builds.
message NodeProperties {
// A list of string-based
// [NodeProperties][build.bazel.remote.execution.v2.NodeProperty].
repeated NodeProperty properties = 1;

// The file's last modification timestamp.
google.protobuf.Timestamp mtime = 2;

// The UNIX file mode, e.g., 0755.
google.protobuf.UInt32Value unix_mode = 3;
}

// A copy of NodeProperty from https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/execution/v2/remote_execution.proto
// to avoid importing it as a proto dependency.
// Importing the messages causes resource exhaustion on high parallelism builds.
message NodeProperty {
// The property name.
string name = 1;

// The property value.
string value = 2;
}

message OutputSpec {
Expand Down
1 change: 1 addition & 0 deletions go/pkg/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
importpath = "github.com/bazelbuild/remote-apis-sdks/go/pkg/client",
visibility = ["//visibility:public"],
deps = [
"//go/api/command",
"//go/pkg/actas",
"//go/pkg/balancer",
"//go/pkg/balancer/proto",
Expand Down
17 changes: 9 additions & 8 deletions go/pkg/client/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sort"
"strings"

cpb "github.com/bazelbuild/remote-apis-sdks/go/api/command"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/command"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/digest"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/filemetadata"
Expand Down Expand Up @@ -41,7 +42,7 @@ type fileSysNode struct {
file *fileNode
emptyDirectoryMarker bool
symlink *symlinkNode
nodeProperties *repb.NodeProperties
nodeProperties *cpb.NodeProperties
}

// TreeStats contains various stats/metadata of the constructed Merkle tree.
Expand Down Expand Up @@ -166,7 +167,7 @@ func getExecRootRelPaths(absPath, execRoot, workingDir, remoteWorkingDir string)

// loadFiles reads all files specified by the given InputSpec (descending into subdirectories
// recursively), and loads their contents into the provided map.
func loadFiles(execRoot, localWorkingDir, remoteWorkingDir string, excl []*command.InputExclusion, filesToProcess []string, fs map[string]*fileSysNode, cache filemetadata.Cache, opts *TreeSymlinkOpts, nodeProperties map[string]*repb.NodeProperties) error {
func loadFiles(execRoot, localWorkingDir, remoteWorkingDir string, excl []*command.InputExclusion, filesToProcess []string, fs map[string]*fileSysNode, cache filemetadata.Cache, opts *TreeSymlinkOpts, nodeProperties map[string]*cpb.NodeProperties) error {
if opts == nil {
opts = DefaultTreeSymlinkOpts()
}
Expand Down Expand Up @@ -411,7 +412,7 @@ func packageTree(t *treeNode, stats *TreeStats, prefix string, tree map[string]d
// A node can have exactly one of file/symlink/emptyDirectoryMarker.
if n.file != nil {
dg := n.file.ue.Digest
dir.Files = append(dir.Files, &repb.FileNode{Name: name, Digest: dg.ToProto(), IsExecutable: n.file.isExecutable, NodeProperties: n.nodeProperties})
dir.Files = append(dir.Files, &repb.FileNode{Name: name, Digest: dg.ToProto(), IsExecutable: n.file.isExecutable, NodeProperties: command.NodePropertiesToAPI(n.nodeProperties)})
blobs[dg] = n.file.ue
stats.InputFiles++
stats.TotalInputBytes += dg.Size
Expand All @@ -421,7 +422,7 @@ func packageTree(t *treeNode, stats *TreeStats, prefix string, tree map[string]d
continue
}
if n.symlink != nil {
dir.Symlinks = append(dir.Symlinks, &repb.SymlinkNode{Name: name, Target: n.symlink.target, NodeProperties: n.nodeProperties})
dir.Symlinks = append(dir.Symlinks, &repb.SymlinkNode{Name: name, Target: n.symlink.target, NodeProperties: command.NodePropertiesToAPI(n.nodeProperties)})
stats.InputSymlinks++
}
}
Expand Down Expand Up @@ -570,12 +571,12 @@ func packageDirectories(t *treeNode) (root *repb.Directory, files map[digest.Dig
// A node can have exactly one of file/symlink/emptyDirectoryMarker.
if n.file != nil {
dg := n.file.ue.Digest
root.Files = append(root.Files, &repb.FileNode{Name: name, Digest: dg.ToProto(), IsExecutable: n.file.isExecutable, NodeProperties: n.nodeProperties})
root.Files = append(root.Files, &repb.FileNode{Name: name, Digest: dg.ToProto(), IsExecutable: n.file.isExecutable, NodeProperties: command.NodePropertiesToAPI(n.nodeProperties)})
files[dg] = n.file.ue
continue
}
if n.symlink != nil {
root.Symlinks = append(root.Symlinks, &repb.SymlinkNode{Name: name, Target: n.symlink.target, NodeProperties: n.nodeProperties})
root.Symlinks = append(root.Symlinks, &repb.SymlinkNode{Name: name, Target: n.symlink.target, NodeProperties: command.NodePropertiesToAPI(n.nodeProperties)})
}
}
sort.Slice(root.Files, func(i, j int) bool { return root.Files[i].Name < root.Files[j].Name })
Expand All @@ -587,7 +588,7 @@ func packageDirectories(t *treeNode) (root *repb.Directory, files map[digest.Dig
// ComputeOutputsToUpload transforms the provided local output paths into uploadable Chunkers.
// The paths have to be relative to execRoot.
// It also populates the remote ActionResult, packaging output directories as trees where required.
func (c *Client) ComputeOutputsToUpload(execRoot, workingDir string, paths []string, cache filemetadata.Cache, sb command.SymlinkBehaviorType, nodeProperties map[string]*repb.NodeProperties) (map[digest.Digest]*uploadinfo.Entry, *repb.ActionResult, error) {
func (c *Client) ComputeOutputsToUpload(execRoot, workingDir string, paths []string, cache filemetadata.Cache, sb command.SymlinkBehaviorType, nodeProperties map[string]*cpb.NodeProperties) (map[digest.Digest]*uploadinfo.Entry, *repb.ActionResult, error) {
outs := make(map[digest.Digest]*uploadinfo.Entry)
resPb := &repb.ActionResult{}
for _, path := range paths {
Expand All @@ -610,7 +611,7 @@ func (c *Client) ComputeOutputsToUpload(execRoot, workingDir string, paths []str
// A regular file.
ue := uploadinfo.EntryFromFile(meta.Digest, absPath)
outs[meta.Digest] = ue
resPb.OutputFiles = append(resPb.OutputFiles, &repb.OutputFile{Path: normPath, Digest: meta.Digest.ToProto(), IsExecutable: meta.IsExecutable, NodeProperties: nodeProperties[normPath]})
resPb.OutputFiles = append(resPb.OutputFiles, &repb.OutputFile{Path: normPath, Digest: meta.Digest.ToProto(), IsExecutable: meta.IsExecutable, NodeProperties: command.NodePropertiesToAPI(nodeProperties[normPath])})
continue
}
// A directory.
Expand Down
Loading

0 comments on commit bb66956

Please sign in to comment.