| // Copyright (C) 2016 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package main |
| |
| import ( |
| "flag" |
| |
| "google.golang.org/grpc" |
| |
| "android.googlesource.com/platform/tools/gpu/framework/app" |
| "android.googlesource.com/platform/tools/gpu/framework/file" |
| "android.googlesource.com/platform/tools/gpu/framework/grpcutil" |
| "android.googlesource.com/platform/tools/gpu/framework/log" |
| "android.googlesource.com/platform/tools/gpu/gapid/stash" |
| ) |
| |
| type uploader interface { |
| prepare(log.Context, *grpc.ClientConn, stash.Store) error |
| process(log.Context, string) error |
| } |
| |
| func doUpload(u uploader) func(log.Context, flag.FlagSet) error { |
| return func(ctx log.Context, flags flag.FlagSet) error { |
| if flags.NArg() == 0 { |
| app.Usage(ctx, "No files given") |
| return nil |
| } |
| return grpcutil.Client(ctx, serverAddress, func(ctx log.Context, conn *grpc.ClientConn) error { |
| store := stash.NewRemoteStore(ctx, conn) |
| u.prepare(ctx, conn, store) |
| for _, partial := range flags.Args() { |
| id, err := stash.UploadFile(ctx, store, file.Abs(partial)) |
| if err != nil { |
| return ctx.WrapError(err, "Failed calling Upload") |
| } |
| ctx.Raw("").Logf("Uploaded %s", id) |
| if err := u.process(ctx, id); err != nil { |
| return err |
| } |
| } |
| return nil |
| }, grpc.WithInsecure()) |
| } |
| } |