Jonathan A. Sternberg 64c5139ab6
hack: generate vtproto files for buildx
Integrates vtproto into buildx. The generated files dockerfile has been
modified to copy the buildkit equivalent file to ensure files are laid
out in the appropriate way for imports.

An import has also been included to change the grpc codec to the version
in buildkit that supports vtproto. This will allow buildx to utilize the
speed and memory improvements from that.

Also updates the gc control options for prune.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-10-08 13:35:06 -05:00

129 lines
2.1 KiB
Go

package errdefs
import (
"fmt"
"io"
"strings"
pb "github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/grpcerrors"
"github.com/pkg/errors"
)
func WithSource(err error, src *Source) error {
if err == nil {
return nil
}
return &ErrorSource{Source: src, error: err}
}
type ErrorSource struct {
*Source
error
}
func (e *ErrorSource) Unwrap() error {
return e.error
}
func (e *ErrorSource) ToProto() grpcerrors.TypedErrorProto {
return e.Source
}
func Sources(err error) []*Source {
var out []*Source
var es *ErrorSource
if errors.As(err, &es) {
out = Sources(es.Unwrap())
out = append(out, es.Source.CloneVT())
}
return out
}
func (s *Source) WrapError(err error) error {
return &ErrorSource{error: err, Source: s}
}
func (s *Source) Print(w io.Writer) error {
si := s.Info
if si == nil {
return nil
}
lines := strings.Split(string(si.Data), "\n")
start, end, ok := getStartEndLine(s.Ranges)
if !ok {
return nil
}
if start > len(lines) || start < 1 {
return nil
}
if end > len(lines) {
end = len(lines)
}
pad := 2
if end == start {
pad = 4
}
var p int
prepadStart := start
for {
if p >= pad {
break
}
if start > 1 {
start--
p++
}
if end != len(lines) {
end++
p++
}
p++
}
fmt.Fprintf(w, "%s:%d\n--------------------\n", si.Filename, prepadStart)
for i := start; i <= end; i++ {
pfx := " "
if containsLine(s.Ranges, i) {
pfx = ">>>"
}
fmt.Fprintf(w, " %3d | %s %s\n", i, pfx, lines[i-1])
}
fmt.Fprintf(w, "--------------------\n")
return nil
}
func containsLine(rr []*pb.Range, l int) bool {
for _, r := range rr {
e := r.End.Line
if e < r.Start.Line {
e = r.Start.Line
}
if r.Start.Line <= int32(l) && e >= int32(l) {
return true
}
}
return false
}
func getStartEndLine(rr []*pb.Range) (start int, end int, ok bool) {
first := true
for _, r := range rr {
e := r.End.Line
if e < r.Start.Line {
e = r.Start.Line
}
if first || int(r.Start.Line) < start {
start = int(r.Start.Line)
}
if int(e) > end {
end = int(e)
}
first = false
}
return start, end, !first
}