Detect support for protobuf array ref on server on frontend return call

Signed-off-by: Edgar Lee <edgarl@netflix.com>
v0.7
Edgar Lee 2020-01-14 16:45:37 -08:00
parent 359574093b
commit d81832cf6c
3 changed files with 38 additions and 10 deletions

View File

@ -105,22 +105,39 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro
Metadata: res.Metadata, Metadata: res.Metadata,
} }
if res.Refs != nil { if res.Refs != nil {
m := map[string]*pb.Ref{} if c.caps.Supports(pb.CapProtoRefArray) == nil {
for k, r := range res.Refs { m := map[string]*pb.Ref{}
id, err := convertRef(r) for k, r := range res.Refs {
if err != nil { id, err := convertRef(r)
retError = err if err != nil {
continue retError = err
continue
}
m[k] = pb.NewRef(id)
} }
m[k] = pb.NewRef(id) pbRes.Result = &pb.Result_Refs{Refs: &pb.RefMap{Refs: m}}
} else {
m := map[string]string{}
for k, r := range res.Refs {
id, err := convertRef(r)
if err != nil {
retError = err
continue
}
m[k] = id
}
pbRes.Result = &pb.Result_RefsDeprecated{RefsDeprecated: &pb.RefMapDeprecated{Refs: m}}
} }
pbRes.Result = &pb.Result_Refs{Refs: &pb.RefMap{Refs: m}}
} else { } else {
id, err := convertRef(res.Ref) id, err := convertRef(res.Ref)
if err != nil { if err != nil {
retError = err retError = err
} else { } else {
pbRes.Result = &pb.Result_Ref{Ref: pb.NewRef(id)} if c.caps.Supports(pb.CapProtoRefArray) == nil {
pbRes.Result = &pb.Result_Ref{Ref: pb.NewRef(id)}
} else {
pbRes.Result = &pb.Result_RefDeprecated{RefDeprecated: id}
}
} }
} }
if retError == nil { if retError == nil {

View File

@ -19,6 +19,11 @@ const (
CapReadDir apicaps.CapID = "readdir" CapReadDir apicaps.CapID = "readdir"
CapStatFile apicaps.CapID = "statfile" CapStatFile apicaps.CapID = "statfile"
CapImportCaches apicaps.CapID = "importcaches" CapImportCaches apicaps.CapID = "importcaches"
// CapProtoRefArray is a capability to return arrays of refs instead of single
// refs. This capability is only for the wire format change and shouldn't be
// used in frontends for feature detection.
CapProtoRefArray apicaps.CapID = "proto.refarray"
) )
func init() { func init() {
@ -92,4 +97,11 @@ func init() {
Enabled: true, Enabled: true,
Status: apicaps.CapStatusExperimental, Status: apicaps.CapStatusExperimental,
}) })
Caps.Init(apicaps.Cap{
ID: CapProtoRefArray,
Name: "wire format ref arrays",
Enabled: true,
Status: apicaps.CapStatusExperimental,
})
} }

View File

@ -288,5 +288,4 @@ func init() {
Enabled: true, Enabled: true,
Status: apicaps.CapStatusExperimental, Status: apicaps.CapStatusExperimental,
}) })
} }