| // 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" |
| "strings" |
| |
| "github.com/gogo/protobuf/proto" |
| |
| "android.googlesource.com/platform/tools/gpu/framework/app" |
| "android.googlesource.com/platform/tools/gpu/framework/grpcutil" |
| "android.googlesource.com/platform/tools/gpu/framework/log" |
| "android.googlesource.com/platform/tools/gpu/gapid/robot/subject" |
| "android.googlesource.com/platform/tools/gpu/gapid/search/script" |
| "android.googlesource.com/platform/tools/gpu/gapid/stash" |
| "google.golang.org/grpc" |
| ) |
| |
| func init() { |
| subjectUpload := &app.Verb{ |
| Name: "subject", |
| ShortHelp: "Upload a traceable application to the server", |
| ShortUsage: "<filenames>", |
| Run: doUpload(&subjectUploader{}), |
| } |
| uploadVerb.Add(subjectUpload) |
| subjectSearch := &app.Verb{ |
| Name: "subject", |
| ShortHelp: "List traceable applications in the server", |
| ShortUsage: "<query>", |
| Run: doSubjectSearch, |
| } |
| searchVerb.Add(subjectSearch) |
| } |
| |
| type subjectUploader struct { |
| subjects subject.Subjects |
| } |
| |
| func (u *subjectUploader) prepare(ctx log.Context, conn *grpc.ClientConn, store stash.Store) error { |
| u.subjects = subject.NewRemote(ctx, conn) |
| return nil |
| } |
| |
| func (u *subjectUploader) process(ctx log.Context, id string) error { |
| subject, created, err := u.subjects.Add(ctx, id) |
| if err != nil { |
| return ctx.WrapError(err, "Failed processing subject") |
| } |
| out := ctx.Raw("") |
| if created { |
| out.Logf("Added new subject") |
| } else { |
| out.Logf("Already existing subject") |
| } |
| |
| out.Logf("Subject info %s", subject) |
| return nil |
| } |
| |
| func doSubjectSearch(ctx log.Context, flags flag.FlagSet) error { |
| return grpcutil.Client(ctx, serverAddress, func(ctx log.Context, conn *grpc.ClientConn) error { |
| subjects := subject.NewRemote(ctx, conn) |
| expression := strings.Join(flags.Args(), " ") |
| out := ctx.Raw("").Writer() |
| expr, err := script.Parse(ctx, expression) |
| if err != nil { |
| return ctx.WrapError(err, "Malformed search query") |
| } |
| return subjects.Search(ctx, expr.Query(), func(ctx log.Context, entry *subject.Subject) error { |
| proto.MarshalText(out, entry) |
| return nil |
| }) |
| }, grpc.WithInsecure()) |
| } |