mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update buildkit to 93b40706a007
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
26
vendor/github.com/moby/buildkit/solver/result/attestation.go
generated
vendored
26
vendor/github.com/moby/buildkit/solver/result/attestation.go
generated
vendored
@ -1,6 +1,8 @@
|
||||
package result
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
pb "github.com/moby/buildkit/frontend/gateway/pb"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
)
|
||||
@ -15,12 +17,12 @@ var (
|
||||
AttestationReasonProvenance = []byte("provenance")
|
||||
)
|
||||
|
||||
type Attestation struct {
|
||||
type Attestation[T any] struct {
|
||||
Kind pb.AttestationKind
|
||||
|
||||
Metadata map[string][]byte
|
||||
|
||||
Ref string
|
||||
Ref T
|
||||
Path string
|
||||
ContentFunc func() ([]byte, error)
|
||||
|
||||
@ -54,3 +56,23 @@ func FromDigestMap(m map[string]string) []digest.Digest {
|
||||
}
|
||||
return ds
|
||||
}
|
||||
|
||||
func ConvertAttestation[U any, V any](a *Attestation[U], fn func(U) (V, error)) (*Attestation[V], error) {
|
||||
var ref V
|
||||
if reflect.ValueOf(a.Ref).IsValid() {
|
||||
var err error
|
||||
ref, err = fn(a.Ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &Attestation[V]{
|
||||
Kind: a.Kind,
|
||||
Metadata: a.Metadata,
|
||||
Ref: ref,
|
||||
Path: a.Path,
|
||||
ContentFunc: a.ContentFunc,
|
||||
InToto: a.InToto,
|
||||
}, nil
|
||||
}
|
||||
|
99
vendor/github.com/moby/buildkit/solver/result/result.go
generated
vendored
99
vendor/github.com/moby/buildkit/solver/result/result.go
generated
vendored
@ -2,23 +2,17 @@ package result
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/moby/buildkit/identity"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
attestationRefPrefix = "attestation:"
|
||||
)
|
||||
|
||||
type Result[T any] struct {
|
||||
mu sync.Mutex
|
||||
Ref T
|
||||
Refs map[string]T
|
||||
Metadata map[string][]byte
|
||||
Attestations map[string][]Attestation
|
||||
Attestations map[string][]Attestation[T]
|
||||
}
|
||||
|
||||
func (r *Result[T]) AddMeta(k string, v []byte) {
|
||||
@ -39,19 +33,10 @@ func (r *Result[T]) AddRef(k string, ref T) {
|
||||
r.mu.Unlock()
|
||||
}
|
||||
|
||||
func (r *Result[T]) AddAttestation(k string, v Attestation, ref T) {
|
||||
func (r *Result[T]) AddAttestation(k string, v Attestation[T]) {
|
||||
r.mu.Lock()
|
||||
if reflect.ValueOf(ref).IsValid() {
|
||||
if r.Refs == nil {
|
||||
r.Refs = map[string]T{}
|
||||
}
|
||||
if !strings.HasPrefix(v.Ref, attestationRefPrefix) {
|
||||
v.Ref = attestationRefPrefix + identity.NewID()
|
||||
r.Refs[v.Ref] = ref
|
||||
}
|
||||
}
|
||||
if r.Attestations == nil {
|
||||
r.Attestations = map[string][]Attestation{}
|
||||
r.Attestations = map[string][]Attestation[T]{}
|
||||
}
|
||||
r.Attestations[k] = append(r.Attestations[k], v)
|
||||
r.mu.Unlock()
|
||||
@ -72,6 +57,25 @@ func (r *Result[T]) SingleRef() (T, error) {
|
||||
return r.Ref, nil
|
||||
}
|
||||
|
||||
func (r *Result[T]) FindRef(key string) (T, bool) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
if r.Refs != nil {
|
||||
if ref, ok := r.Refs[key]; ok {
|
||||
return ref, true
|
||||
}
|
||||
if len(r.Refs) == 1 {
|
||||
for _, ref := range r.Refs {
|
||||
return ref, true
|
||||
}
|
||||
}
|
||||
var t T
|
||||
return t, false
|
||||
}
|
||||
return r.Ref, true
|
||||
}
|
||||
|
||||
func (r *Result[T]) EachRef(fn func(T) error) (err error) {
|
||||
if reflect.ValueOf(r.Ref).IsValid() {
|
||||
err = fn(r.Ref)
|
||||
@ -83,6 +87,15 @@ func (r *Result[T]) EachRef(fn func(T) error) (err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, as := range r.Attestations {
|
||||
for _, a := range as {
|
||||
if reflect.ValueOf(a.Ref).IsValid() {
|
||||
if err1 := fn(a.Ref); err1 != nil && err == nil {
|
||||
err = err1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -94,12 +107,33 @@ func EachRef[U any, V any](a *Result[U], b *Result[V], fn func(U, V) error) (err
|
||||
err = fn(a.Ref, b.Ref)
|
||||
}
|
||||
for k, r := range a.Refs {
|
||||
if reflect.ValueOf(r).IsValid() && reflect.ValueOf(b.Refs[k]).IsValid() {
|
||||
if err1 := fn(r, b.Refs[k]); err1 != nil && err == nil {
|
||||
r2, ok := b.Refs[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if reflect.ValueOf(r).IsValid() && reflect.ValueOf(r2).IsValid() {
|
||||
if err1 := fn(r, r2); err1 != nil && err == nil {
|
||||
err = err1
|
||||
}
|
||||
}
|
||||
}
|
||||
for k, atts := range a.Attestations {
|
||||
atts2, ok := b.Attestations[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for i, att := range atts {
|
||||
if i >= len(atts2) {
|
||||
break
|
||||
}
|
||||
att2 := atts2[i]
|
||||
if reflect.ValueOf(att.Ref).IsValid() && reflect.ValueOf(att2.Ref).IsValid() {
|
||||
if err1 := fn(att.Ref, att2.Ref); err1 != nil && err == nil {
|
||||
err = err1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -118,15 +152,28 @@ func ConvertResult[U any, V any](r *Result[U], fn func(U) (V, error)) (*Result[V
|
||||
r2.Refs = map[string]V{}
|
||||
}
|
||||
for k, r := range r.Refs {
|
||||
if reflect.ValueOf(r).IsValid() {
|
||||
r2.Refs[k], err = fn(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !reflect.ValueOf(r).IsValid() {
|
||||
continue
|
||||
}
|
||||
r2.Refs[k], err = fn(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if r.Attestations != nil {
|
||||
r2.Attestations = map[string][]Attestation[V]{}
|
||||
}
|
||||
for k, as := range r.Attestations {
|
||||
for _, a := range as {
|
||||
a2, err := ConvertAttestation(&a, fn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r2.Attestations[k] = append(r2.Attestations[k], *a2)
|
||||
}
|
||||
}
|
||||
|
||||
r2.Attestations = r.Attestations
|
||||
r2.Metadata = r.Metadata
|
||||
|
||||
return r2, nil
|
||||
|
Reference in New Issue
Block a user