mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-21 03:07:46 +08:00

Removes gogo/protobuf from buildx and updates to a version of moby/buildkit where gogo is removed. This also changes how the proto files are generated. This is because newer versions of protobuf are more strict about name conflicts. If two files have the same name (even if they are relative paths) and are used in different protoc commands, they'll conflict in the registry. Since protobuf file generation doesn't work very well with `paths=source_relative`, this removes the `go:generate` expression and just relies on the dockerfile to perform the generation. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
110 lines
2.6 KiB
Go
110 lines
2.6 KiB
Go
package llb
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/moby/buildkit/solver/pb"
|
|
digest "github.com/opencontainers/go-digest"
|
|
)
|
|
|
|
type DiffOp struct {
|
|
MarshalCache
|
|
lower Output
|
|
upper Output
|
|
output Output
|
|
constraints Constraints
|
|
}
|
|
|
|
func NewDiff(lower, upper State, c Constraints) *DiffOp {
|
|
addCap(&c, pb.CapDiffOp)
|
|
op := &DiffOp{
|
|
lower: lower.Output(),
|
|
upper: upper.Output(),
|
|
constraints: c,
|
|
}
|
|
op.output = &output{vertex: op}
|
|
return op
|
|
}
|
|
|
|
func (m *DiffOp) Validate(ctx context.Context, constraints *Constraints) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *DiffOp) Marshal(ctx context.Context, constraints *Constraints) (digest.Digest, []byte, *pb.OpMetadata, []*SourceLocation, error) {
|
|
if dgst, dt, md, srcs, err := m.Load(constraints); err == nil {
|
|
return dgst, dt, md, srcs, nil
|
|
}
|
|
if err := m.Validate(ctx, constraints); err != nil {
|
|
return "", nil, nil, nil, err
|
|
}
|
|
|
|
proto, md := MarshalConstraints(constraints, &m.constraints)
|
|
proto.Platform = nil // diff op is not platform specific
|
|
|
|
op := &pb.DiffOp{}
|
|
|
|
op.Lower = &pb.LowerDiffInput{Input: int64(len(proto.Inputs))}
|
|
if m.lower == nil {
|
|
op.Lower.Input = int64(pb.Empty)
|
|
} else {
|
|
pbLowerInput, err := m.lower.ToInput(ctx, constraints)
|
|
if err != nil {
|
|
return "", nil, nil, nil, err
|
|
}
|
|
proto.Inputs = append(proto.Inputs, pbLowerInput)
|
|
}
|
|
|
|
op.Upper = &pb.UpperDiffInput{Input: int64(len(proto.Inputs))}
|
|
if m.upper == nil {
|
|
op.Upper.Input = int64(pb.Empty)
|
|
} else {
|
|
pbUpperInput, err := m.upper.ToInput(ctx, constraints)
|
|
if err != nil {
|
|
return "", nil, nil, nil, err
|
|
}
|
|
proto.Inputs = append(proto.Inputs, pbUpperInput)
|
|
}
|
|
|
|
proto.Op = &pb.Op_Diff{Diff: op}
|
|
|
|
dt, err := deterministicMarshal(proto)
|
|
if err != nil {
|
|
return "", nil, nil, nil, err
|
|
}
|
|
|
|
return m.Store(dt, md, m.constraints.SourceLocations, constraints)
|
|
}
|
|
|
|
func (m *DiffOp) Output() Output {
|
|
return m.output
|
|
}
|
|
|
|
func (m *DiffOp) Inputs() (out []Output) {
|
|
if m.lower != nil {
|
|
out = append(out, m.lower)
|
|
}
|
|
if m.upper != nil {
|
|
out = append(out, m.upper)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Diff returns a state that represents the diff of the lower and upper states.
|
|
// The returned State is useful for use with [Merge] where you can merge the lower state with the diff.
|
|
func Diff(lower, upper State, opts ...ConstraintsOpt) State {
|
|
if lower.Output() == nil {
|
|
if upper.Output() == nil {
|
|
// diff of scratch and scratch is scratch
|
|
return Scratch()
|
|
}
|
|
// diff of scratch and upper is just upper
|
|
return upper
|
|
}
|
|
|
|
var c Constraints
|
|
for _, o := range opts {
|
|
o.SetConstraintsOption(&c)
|
|
}
|
|
return lower.WithOutput(NewDiff(lower, upper, c).Output())
|
|
}
|