Skip to content

Commit

Permalink
Removing old copy of tree package and migrating remaining deps. bazel…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ola Rozenfeld authored Nov 18, 2019
1 parent d0bfafe commit 2abbe5b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 989 deletions.
7 changes: 2 additions & 5 deletions go/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ go_library(
"client.go",
"client_context.go",
"exec.go",
"tree.go",
],
importpath = "github.com/bazelbuild/remote-apis-sdks/go/client",
visibility = ["//visibility:public"],
deps = [
"//go/actas:go_default_library",
"//go/digest:go_default_library",
"//go/pkg/chunker:go_default_library",
"//go/pkg/command:go_default_library",
"//go/pkg/tree:go_default_library",
"//go/retry:go_default_library",
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:go_default_library",
"@com_github_golang_glog//:go_default_library",
Expand Down Expand Up @@ -45,22 +44,20 @@ go_test(
"cas_test.go",
"exec_test.go",
"retries_test.go",
"tree_test.go",
],
embed = [":go_default_library"],
deps = [
"//go/digest:go_default_library",
"//go/pkg/chunker:go_default_library",
"//go/pkg/command:go_default_library",
"//go/pkg/fakes:go_default_library",
"//go/pkg/portpicker:go_default_library",
"//go/pkg/tree:go_default_library",
"//go/retry:go_default_library",
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
"@com_github_google_go_cmp//cmp:go_default_library",
"@com_github_google_go_cmp//cmp/cmpopts:go_default_library",
"@com_github_kylelemons_godebug//pretty:go_default_library",
"@go_googleapis//google/bytestream:bytestream_go_proto",
"@go_googleapis//google/longrunning:longrunning_go_proto",
"@go_googleapis//google/rpc:status_go_proto",
Expand Down
23 changes: 12 additions & 11 deletions go/client/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/bazelbuild/remote-apis-sdks/go/digest"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/chunker"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/tree"
"github.com/golang/protobuf/proto"
"github.com/pborman/uuid"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -506,34 +507,34 @@ func (c *Client) GetDirectoryTree(ctx context.Context, d *repb.Digest) (result [

// FlattenActionOutputs collects and flattens all the outputs of an action.
// It downloads the output directory metadata, if required, but not the leaf file blobs.
func (c *Client) FlattenActionOutputs(ctx context.Context, ar *repb.ActionResult) (map[string]*Output, error) {
outs := make(map[string]*Output)
func (c *Client) FlattenActionOutputs(ctx context.Context, ar *repb.ActionResult) (map[string]*tree.Output, error) {
outs := make(map[string]*tree.Output)
for _, file := range ar.OutputFiles {
outs[file.Path] = &Output{
outs[file.Path] = &tree.Output{
Path: file.Path,
Digest: digest.NewFromProtoUnvalidated(file.Digest),
IsExecutable: file.IsExecutable,
}
}
for _, sm := range ar.OutputFileSymlinks {
outs[sm.Path] = &Output{
outs[sm.Path] = &tree.Output{
Path: sm.Path,
SymlinkTarget: sm.Target,
}
}
for _, sm := range ar.OutputDirectorySymlinks {
outs[sm.Path] = &Output{
outs[sm.Path] = &tree.Output{
Path: sm.Path,
SymlinkTarget: sm.Target,
}
}
for _, dir := range ar.OutputDirectories {
if blob, err := c.ReadBlob(ctx, digest.NewFromProtoUnvalidated(dir.TreeDigest)); err == nil {
tree := &repb.Tree{}
if err := proto.Unmarshal(blob, tree); err != nil {
t := &repb.Tree{}
if err := proto.Unmarshal(blob, t); err != nil {
return nil, err
}
dirouts, err := FlattenTree(tree, dir.Path)
dirouts, err := tree.FlattenTree(t, dir.Path)
if err != nil {
return nil, err
}
Expand All @@ -551,8 +552,8 @@ func (c *Client) DownloadActionOutputs(ctx context.Context, resPb *repb.ActionRe
if err != nil {
return err
}
var symlinks, copies []*Output
downloads := make(map[digest.Digest]*Output)
var symlinks, copies []*tree.Output
downloads := make(map[digest.Digest]*tree.Output)
for _, out := range outs {
path := filepath.Join(execRoot, out.Path)
// TODO(olaola): fix the (upstream) bug that this doesn't download empty directory trees.
Expand Down Expand Up @@ -614,7 +615,7 @@ func copyFile(execRoot, from, to string) error {
return err
}

func (c *Client) downloadFiles(ctx context.Context, execRoot string, outputs map[digest.Digest]*Output) error {
func (c *Client) downloadFiles(ctx context.Context, execRoot string, outputs map[digest.Digest]*tree.Output) error {
if cap(c.casDownloaders) <= 0 {
return fmt.Errorf("CASConcurrency should be at least 1")
}
Expand Down
23 changes: 12 additions & 11 deletions go/client/cas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/bazelbuild/remote-apis-sdks/go/pkg/chunker"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/fakes"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/portpicker"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/tree"
"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc"
Expand Down Expand Up @@ -581,11 +582,11 @@ func TestFlattenActionOutputs(t *testing.T) {
{Name: "b", Digest: bDigest.ToProto()},
},
}
tree := &repb.Tree{
tr := &repb.Tree{
Root: root,
Children: []*repb.Directory{dirA, dirB},
}
treeBlob, err := proto.Marshal(tree)
treeBlob, err := proto.Marshal(tr)
if err != nil {
t.Errorf("failed marshalling Tree: %s", err)
}
Expand Down Expand Up @@ -615,15 +616,15 @@ func TestFlattenActionOutputs(t *testing.T) {
if err != nil {
t.Errorf("error in FlattenActionOutputs: %s", err)
}
wantOutputs := map[string]*client.Output{
"dir/a/b/foo": &client.Output{Digest: fooDigest, IsExecutable: true},
"dir/a/bar": &client.Output{Digest: barDigest},
"dir/b/foo": &client.Output{Digest: fooDigest, IsExecutable: true},
"dir2/b/foo": &client.Output{Digest: fooDigest, IsExecutable: true},
"dir2/bar": &client.Output{Digest: barDigest},
"foo": &client.Output{Digest: fooDigest},
"x/a": &client.Output{SymlinkTarget: "../dir/a"},
"x/bar": &client.Output{SymlinkTarget: "../dir/a/bar"},
wantOutputs := map[string]*tree.Output{
"dir/a/b/foo": &tree.Output{Digest: fooDigest, IsExecutable: true},
"dir/a/bar": &tree.Output{Digest: barDigest},
"dir/b/foo": &tree.Output{Digest: fooDigest, IsExecutable: true},
"dir2/b/foo": &tree.Output{Digest: fooDigest, IsExecutable: true},
"dir2/bar": &tree.Output{Digest: barDigest},
"foo": &tree.Output{Digest: fooDigest},
"x/a": &tree.Output{SymlinkTarget: "../dir/a"},
"x/bar": &tree.Output{SymlinkTarget: "../dir/a/bar"},
}
if len(outputs) != len(wantOutputs) {
t.Errorf("FlattenActionOutputs gave wrong number of outputs: want %d, got %d", len(wantOutputs), len(outputs))
Expand Down
Loading

0 comments on commit 2abbe5b

Please sign in to comment.