From 728de510f3e2521dfb16f1bb6a7071be6576cde8 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 21 Jun 2017 14:48:21 -0700 Subject: [PATCH] llb: improve llb generation Signed-off-by: Tonis Tiigi --- client/client_test.go | 4 +- client/llb/llb.go | 241 +++-- examples/llbout/example.go | 23 +- hack/dockerfiles/test.Dockerfile | 2 +- solver/pb/generate.go | 2 +- solver/pb/ops.pb.go | 1256 ++++------------------- solver/pb/ops.proto | 4 +- solver/solver.go | 6 +- util/system/path_unix.go | 14 + util/system/path_windows.go | 37 + util/system/path_windows_test.go | 78 ++ vendor.conf | 1 + vendor/github.com/google/shlex/COPYING | 202 ++++ vendor/github.com/google/shlex/README | 2 + vendor/github.com/google/shlex/shlex.go | 417 ++++++++ worker/oci/spec_unix.go | 2 +- 16 files changed, 1181 insertions(+), 1110 deletions(-) create mode 100644 util/system/path_unix.go create mode 100644 util/system/path_windows.go create mode 100644 util/system/path_windows_test.go create mode 100644 vendor/github.com/google/shlex/COPYING create mode 100644 vendor/github.com/google/shlex/README create mode 100644 vendor/github.com/google/shlex/shlex.go diff --git a/client/client_test.go b/client/client_test.go index e8b16f71..43c77a02 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -115,9 +115,9 @@ func testBuildMultiMount(t *testing.T, address string) { assert.Nil(t, err) alpine := llb.Image("docker.io/library/alpine:latest") - ls := alpine.Run(llb.Meta{Args: []string{"/bin/ls", "-l"}, Cwd: "/"}) + ls := alpine.Run(llb.Shlex("/bin/ls -l")) busybox := llb.Image("docker.io/library/busybox:latest") - cp := ls.Run(llb.Meta{Args: []string{"/bin/cp", "-a", "/busybox/etc/passwd", "baz"}, Cwd: "/"}) + cp := ls.Run(llb.Shlex("/bin/cp -a /busybox/etc/passwd baz")) cp.AddMount("/busybox", busybox) dt, err := cp.Marshal() diff --git a/client/llb/llb.go b/client/llb/llb.go index 783812db..d8c84b05 100644 --- a/client/llb/llb.go +++ b/client/llb/llb.go @@ -2,19 +2,18 @@ package llb import ( _ "crypto/sha256" + "fmt" "sort" "github.com/gogo/protobuf/proto" + "github.com/google/shlex" digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" "github.com/tonistiigi/buildkit_poc/solver/pb" + "github.com/tonistiigi/buildkit_poc/util/system" ) -type Op interface { - Validate() error - Marshal() ([][]byte, error) - Run(meta Meta) *ExecOp -} +type RunOption func(m Meta) Meta type SourceOp struct { id string @@ -33,52 +32,138 @@ type Meta struct { } type Mount struct { - op *ExecOp - dest string - mount *Mount - src *SourceOp - output bool + op *ExecOp + dest string + mount *Mount + src *SourceOp + output bool + inputIndex int64 } -func Source(id string) *SourceOp { - return &SourceOp{id: id} +func NewMeta(args ...string) Meta { + m := Meta{} + m = m.addEnv("PATH", system.DefaultPathEnv) + m = m.setArgs(args...) + m.Cwd = "/" + return m } -func (so *SourceOp) Validate() error { - // TODO: basic identifier validation - if so.id == "" { - return errors.Errorf("source identifier can't be empty") +func (m *Meta) ensurePrivate() { + m.Env = append([]string{}, m.Env...) + m.Args = append([]string{}, m.Args...) +} + +func (m Meta) addEnv(k, v string) Meta { + (&m).ensurePrivate() + // TODO: flatten + m.Env = append(m.Env, k+"="+v) + return m +} + +func (m Meta) setArgs(args ...string) Meta { + m.Args = append([]string{}, args...) + return m +} + +func Shlex(str string, v ...string) RunOption { + return func(m Meta) Meta { + vi := make([]interface{}, 0, len(v)) + for _, v := range v { + vi = append(vi, v) + } + sp, err := shlex.Split(fmt.Sprintf(str, vi...)) + if err != nil { + panic(err) // TODO + } + (&m).ensurePrivate() + return m.setArgs(sp...) + } +} + +type State struct { + src *SourceOp + exec *ExecOp + meta Meta + mount *Mount + metaNext Meta +} + +type ExecState struct { + State +} + +func (s *State) Validate() error { + if s.src != nil { + if err := s.src.Validate(); err != nil { + return err + } + } + if s.exec != nil { + if err := s.exec.Validate(); err != nil { + return err + } } return nil } -func (so *SourceOp) Run(m Meta) *ExecOp { - return newExec(m, so, nil) +func (s *State) Run(opts ...RunOption) *ExecState { + var es ExecState + meta := s.metaNext + for _, o := range opts { + meta = o(meta) + } + exec := newExec(meta, s.src, s.mount) + es.exec = exec + es.mount = exec.root + es.metaNext = meta + es.meta = meta + return &es } -func (so *SourceOp) Marshal() ([][]byte, error) { - if err := so.Validate(); err != nil { +func (s *State) AddEnv(k, v string) *State { + s.metaNext = s.metaNext.addEnv(k, v) + return s +} +func (s *State) Dir(wd string) *State { + s.metaNext.Cwd = wd + return s +} + +func (s *State) Marshal() ([][]byte, error) { + if err := s.Validate(); err != nil { return nil, err } cache := make(map[digest.Digest]struct{}) - _, list, err := so.recursiveMarshal(nil, cache) + var list [][]byte + var err error + if s.src != nil { // TODO: fix repetition + _, list, err = s.src.recursiveMarshal(nil, cache) + } else if s.exec != nil { + _, list, err = s.exec.root.recursiveMarshal(nil, cache) + } else { + _, list, err = s.mount.recursiveMarshal(nil, cache) + } return list, err } -func (so *SourceOp) recursiveMarshal(list [][]byte, cache map[digest.Digest]struct{}) (digest.Digest, [][]byte, error) { - if err := so.Validate(); err != nil { - return "", nil, err +func (s *ExecState) AddMount(dest string, mount *State) *State { + m := &Mount{ + dest: dest, + src: mount.src, + mount: mount.mount, + op: s.exec, + output: true, // TODO: should be set only if something inherits } - po := &pb.Op{ - Op: &pb.Op_Source{ - Source: &pb.SourceOp{Identifier: so.id}, - }, - } - return marshal(po, list, cache) + var newState State + newState.meta = s.meta + newState.metaNext = s.meta + newState.mount = m + s.exec.mounts = append(s.exec.mounts, m) + return &newState } -func Image(ref string) *SourceOp { - return Source("docker-image://" + ref) // controversial +func (s *ExecState) Root() *State { + return &s.State } func newExec(meta Meta, src *SourceOp, m *Mount) *ExecOp { @@ -97,26 +182,35 @@ func newExec(meta Meta, src *SourceOp, m *Mount) *ExecOp { return exec } -func (eo *ExecOp) AddMount(dest string, src interface{}) *Mount { - var s *SourceOp - var m *Mount - switch v := src.(type) { - case *SourceOp: - s = v - case *Mount: - m = v - case *ExecOp: - m = v.root - default: - panic("invalid input") +func Source(id string) *State { + return &State{ + metaNext: NewMeta(), + src: &SourceOp{id: id}, } - eo.mounts = append(eo.mounts, &Mount{ - dest: dest, - src: s, - mount: m, - output: true, // TODO: should be set only if something inherits - }) - return m +} + +func (so *SourceOp) Validate() error { + // TODO: basic identifier validation + if so.id == "" { + return errors.Errorf("source identifier can't be empty") + } + return nil +} + +func (so *SourceOp) recursiveMarshal(list [][]byte, cache map[digest.Digest]struct{}) (digest.Digest, [][]byte, error) { + if err := so.Validate(); err != nil { + return "", nil, err + } + po := &pb.Op{ + Op: &pb.Op_Source{ + Source: &pb.SourceOp{Identifier: so.id}, + }, + } + return appendResult(po, list, cache) +} + +func Image(ref string) *State { + return Source("docker-image://" + ref) // controversial } func (eo *ExecOp) Validate() error { @@ -136,10 +230,6 @@ func (eo *ExecOp) Validate() error { return nil } -func (eo *ExecOp) Run(meta Meta) *ExecOp { - return newExec(meta, nil, eo.root) -} - func (eo *ExecOp) Marshal() ([][]byte, error) { if err := eo.Validate(); err != nil { return nil, err @@ -173,7 +263,7 @@ func (eo *ExecOp) recursiveMarshal(list [][]byte, cache map[digest.Digest]struct for _, m := range eo.mounts { var dgst digest.Digest var err error - var op Op + var op interface{} if m.src != nil { op = m.src } else { @@ -185,15 +275,19 @@ func (eo *ExecOp) recursiveMarshal(list [][]byte, cache map[digest.Digest]struct } inputIndex := len(pop.Inputs) for i := range pop.Inputs { - if pop.Inputs[i].Digest == dgst.String() { + if pop.Inputs[i].Digest == dgst { inputIndex = i break } } if inputIndex == len(pop.Inputs) { + var mountIndex int64 + if m.mount != nil { + mountIndex = m.mount.inputIndex + } pop.Inputs = append(pop.Inputs, &pb.Input{ - Digest: dgst.String(), - Index: 0, // TODO + Digest: dgst, + Index: mountIndex, }) } @@ -207,13 +301,36 @@ func (eo *ExecOp) recursiveMarshal(list [][]byte, cache map[digest.Digest]struct } else { pm.Output = -1 } + m.inputIndex = outputIndex - 1 peo.Mounts = append(peo.Mounts, pm) } - return marshal(pop, list, cache) + return appendResult(pop, list, cache) } -func marshal(p proto.Marshaler, list [][]byte, cache map[digest.Digest]struct{}) (dgst digest.Digest, out [][]byte, err error) { +func (m *Mount) recursiveMarshal(list [][]byte, cache map[digest.Digest]struct{}) (digest.Digest, [][]byte, error) { + if m.op == nil { + return "", nil, errors.Errorf("invalid mount") + } + var dgst digest.Digest + dgst, list, err := m.op.recursiveMarshal(list, cache) + if err != nil { + return "", list, err + } + for _, m2 := range m.op.mounts { + if m2 == m { + po := &pb.Op{} + po.Inputs = append(po.Inputs, &pb.Input{ + Digest: dgst, + Index: int64(m.inputIndex), + }) + return appendResult(po, list, cache) + } + } + return "", nil, errors.Errorf("invalid mount") +} + +func appendResult(p proto.Marshaler, list [][]byte, cache map[digest.Digest]struct{}) (dgst digest.Digest, out [][]byte, err error) { dt, err := p.Marshal() if err != nil { return "", nil, err @@ -227,7 +344,7 @@ func marshal(p proto.Marshaler, list [][]byte, cache map[digest.Digest]struct{}) return dgst, list, nil } -func recursiveMarshalAny(op Op, list [][]byte, cache map[digest.Digest]struct{}) (dgst digest.Digest, out [][]byte, err error) { +func recursiveMarshalAny(op interface{}, list [][]byte, cache map[digest.Digest]struct{}) (dgst digest.Digest, out [][]byte, err error) { switch op := op.(type) { case *ExecOp: return op.recursiveMarshal(list, cache) diff --git a/examples/llbout/example.go b/examples/llbout/example.go index 2806ab5c..b6f18d2a 100644 --- a/examples/llbout/example.go +++ b/examples/llbout/example.go @@ -1,24 +1,29 @@ package main import ( + "log" "os" "github.com/tonistiigi/buildkit_poc/client/llb" ) func main() { - busybox := llb.Image("docker.io/library/redis:latest") - mod1 := busybox.Run(llb.Meta{Args: []string{"/bin/sleep", "1"}, Cwd: "/"}) - mod2 := mod1.Run(llb.Meta{Args: []string{"/bin/sh", "-c", "echo foo > /bar"}, Cwd: "/"}) - alpine := llb.Image("docker.io/library/alpine:latest") - mod3 := mod2.Run(llb.Meta{Args: []string{"/bin/cp", "-a", "/alpine/etc/passwd", "baz"}, Cwd: "/"}) - mod3.AddMount("/alpine", alpine) - mod3.AddMount("/redis", busybox) - mod4 := mod3.Run(llb.Meta{Args: []string{"/bin/ls", "-l", "/"}, Cwd: "/"}) + busybox := llb.Image("docker.io/library/busybox:latest") + img1 := busybox. + Run(llb.Shlex("sleep 1")). + Run(llb.Shlex("sh -c \"echo foo > /bar\"")) + + alpine := llb.Image("docker.io/library/alpine:latest") + + copy := img1.Run(llb.Shlex("cp -a /alpine/etc/passwd /baz")) + copy.AddMount("/alpine", alpine) + copy.AddMount("/subroot", busybox) + + res := copy.Run(llb.Shlex("ls -l /")) - res := mod4 dt, err := res.Marshal() if err != nil { + log.Printf("%+v\n", err) panic(err) } llb.WriteTo(dt, os.Stdout) diff --git a/hack/dockerfiles/test.Dockerfile b/hack/dockerfiles/test.Dockerfile index 25ae307e..47e03fdf 100644 --- a/hack/dockerfiles/test.Dockerfile +++ b/hack/dockerfiles/test.Dockerfile @@ -17,7 +17,7 @@ RUN apk add --no-cache btrfs-progs-dev ARG CONTAINERD_VERSION RUN git clone https://github.com/containerd/containerd.git "$GOPATH/src/github.com/containerd/containerd" \ && cd "$GOPATH/src/github.com/containerd/containerd" \ - && git checkout -q "$RUNC_VERSION" \ + && git checkout -q "$CONTAINERD_VERSION" \ && make bin/containerd FROM gobuild-base AS unit-tests diff --git a/solver/pb/generate.go b/solver/pb/generate.go index a824cfdc..c31e148f 100644 --- a/solver/pb/generate.go +++ b/solver/pb/generate.go @@ -1,3 +1,3 @@ package pb -//go:generate protoc --gogoslick_out=. ops.proto +//go:generate protoc -I=. -I=../../vendor/ --gogofaster_out=. ops.proto diff --git a/solver/pb/ops.pb.go b/solver/pb/ops.pb.go index e93e99ce..4e61296d 100644 --- a/solver/pb/ops.pb.go +++ b/solver/pb/ops.pb.go @@ -23,9 +23,9 @@ package pb import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" +import _ "github.com/gogo/protobuf/gogoproto" -import strings "strings" -import reflect "reflect" +import github_com_opencontainers_go_digest "github.com/opencontainers/go-digest" import io "io" @@ -34,12 +34,6 @@ var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package - type Op struct { Inputs []*Input `protobuf:"bytes,1,rep,name=inputs" json:"inputs,omitempty"` // Types that are valid to be assigned to Op: @@ -49,13 +43,12 @@ type Op struct { Op isOp_Op `protobuf_oneof:"op"` } -func (m *Op) Reset() { *m = Op{} } -func (*Op) ProtoMessage() {} -func (*Op) Descriptor() ([]byte, []int) { return fileDescriptorOps, []int{0} } +func (m *Op) Reset() { *m = Op{} } +func (m *Op) String() string { return proto.CompactTextString(m) } +func (*Op) ProtoMessage() {} type isOp_Op interface { isOp_Op() - Equal(interface{}) bool MarshalTo([]byte) (int, error) Size() int } @@ -110,8 +103,8 @@ func (m *Op) GetCopy() *CopyOp { } // XXX_OneofFuncs is for the internal use of the proto package. -func (*Op) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _Op_OneofMarshaler, _Op_OneofUnmarshaler, _Op_OneofSizer, []interface{}{ +func (*Op) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), []interface{}) { + return _Op_OneofMarshaler, _Op_OneofUnmarshaler, []interface{}{ (*Op_Exec)(nil), (*Op_Source)(nil), (*Op_Copy)(nil), @@ -176,63 +169,23 @@ func _Op_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bo } } -func _Op_OneofSizer(msg proto.Message) (n int) { - m := msg.(*Op) - // op - switch x := m.Op.(type) { - case *Op_Exec: - s := proto.Size(x.Exec) - n += proto.SizeVarint(2<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *Op_Source: - s := proto.Size(x.Source) - n += proto.SizeVarint(3<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case *Op_Copy: - s := proto.Size(x.Copy) - n += proto.SizeVarint(4<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - type Input struct { - Digest string `protobuf:"bytes,1,opt,name=digest,proto3" json:"digest,omitempty"` - Index int64 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` + Digest github_com_opencontainers_go_digest.Digest `protobuf:"bytes,1,opt,name=digest,proto3,customtype=github.com/opencontainers/go-digest.Digest" json:"digest"` + Index int64 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` } -func (m *Input) Reset() { *m = Input{} } -func (*Input) ProtoMessage() {} -func (*Input) Descriptor() ([]byte, []int) { return fileDescriptorOps, []int{1} } - -func (m *Input) GetDigest() string { - if m != nil { - return m.Digest - } - return "" -} - -func (m *Input) GetIndex() int64 { - if m != nil { - return m.Index - } - return 0 -} +func (m *Input) Reset() { *m = Input{} } +func (m *Input) String() string { return proto.CompactTextString(m) } +func (*Input) ProtoMessage() {} type ExecOp struct { Meta *Meta `protobuf:"bytes,1,opt,name=meta" json:"meta,omitempty"` Mounts []*Mount `protobuf:"bytes,2,rep,name=mounts" json:"mounts,omitempty"` } -func (m *ExecOp) Reset() { *m = ExecOp{} } -func (*ExecOp) ProtoMessage() {} -func (*ExecOp) Descriptor() ([]byte, []int) { return fileDescriptorOps, []int{2} } +func (m *ExecOp) Reset() { *m = ExecOp{} } +func (m *ExecOp) String() string { return proto.CompactTextString(m) } +func (*ExecOp) ProtoMessage() {} func (m *ExecOp) GetMeta() *Meta { if m != nil { @@ -254,30 +207,9 @@ type Meta struct { Cwd string `protobuf:"bytes,3,opt,name=cwd,proto3" json:"cwd,omitempty"` } -func (m *Meta) Reset() { *m = Meta{} } -func (*Meta) ProtoMessage() {} -func (*Meta) Descriptor() ([]byte, []int) { return fileDescriptorOps, []int{3} } - -func (m *Meta) GetArgs() []string { - if m != nil { - return m.Args - } - return nil -} - -func (m *Meta) GetEnv() []string { - if m != nil { - return m.Env - } - return nil -} - -func (m *Meta) GetCwd() string { - if m != nil { - return m.Cwd - } - return "" -} +func (m *Meta) Reset() { *m = Meta{} } +func (m *Meta) String() string { return proto.CompactTextString(m) } +func (*Meta) ProtoMessage() {} type Mount struct { Input int64 `protobuf:"varint,1,opt,name=input,proto3" json:"input,omitempty"` @@ -286,46 +218,18 @@ type Mount struct { Output int64 `protobuf:"varint,4,opt,name=output,proto3" json:"output,omitempty"` } -func (m *Mount) Reset() { *m = Mount{} } -func (*Mount) ProtoMessage() {} -func (*Mount) Descriptor() ([]byte, []int) { return fileDescriptorOps, []int{4} } - -func (m *Mount) GetInput() int64 { - if m != nil { - return m.Input - } - return 0 -} - -func (m *Mount) GetSelector() string { - if m != nil { - return m.Selector - } - return "" -} - -func (m *Mount) GetDest() string { - if m != nil { - return m.Dest - } - return "" -} - -func (m *Mount) GetOutput() int64 { - if m != nil { - return m.Output - } - return 0 -} +func (m *Mount) Reset() { *m = Mount{} } +func (m *Mount) String() string { return proto.CompactTextString(m) } +func (*Mount) ProtoMessage() {} type CopyOp struct { Src []*CopySource `protobuf:"bytes,1,rep,name=src" json:"src,omitempty"` Dest string `protobuf:"bytes,2,opt,name=dest,proto3" json:"dest,omitempty"` } -func (m *CopyOp) Reset() { *m = CopyOp{} } -func (*CopyOp) ProtoMessage() {} -func (*CopyOp) Descriptor() ([]byte, []int) { return fileDescriptorOps, []int{5} } +func (m *CopyOp) Reset() { *m = CopyOp{} } +func (m *CopyOp) String() string { return proto.CompactTextString(m) } +func (*CopyOp) ProtoMessage() {} func (m *CopyOp) GetSrc() []*CopySource { if m != nil { @@ -334,50 +238,22 @@ func (m *CopyOp) GetSrc() []*CopySource { return nil } -func (m *CopyOp) GetDest() string { - if m != nil { - return m.Dest - } - return "" -} - type CopySource struct { Input int64 `protobuf:"varint,1,opt,name=input,proto3" json:"input,omitempty"` Selector string `protobuf:"bytes,2,opt,name=selector,proto3" json:"selector,omitempty"` } -func (m *CopySource) Reset() { *m = CopySource{} } -func (*CopySource) ProtoMessage() {} -func (*CopySource) Descriptor() ([]byte, []int) { return fileDescriptorOps, []int{6} } - -func (m *CopySource) GetInput() int64 { - if m != nil { - return m.Input - } - return 0 -} - -func (m *CopySource) GetSelector() string { - if m != nil { - return m.Selector - } - return "" -} +func (m *CopySource) Reset() { *m = CopySource{} } +func (m *CopySource) String() string { return proto.CompactTextString(m) } +func (*CopySource) ProtoMessage() {} type SourceOp struct { Identifier string `protobuf:"bytes,1,opt,name=identifier,proto3" json:"identifier,omitempty"` } -func (m *SourceOp) Reset() { *m = SourceOp{} } -func (*SourceOp) ProtoMessage() {} -func (*SourceOp) Descriptor() ([]byte, []int) { return fileDescriptorOps, []int{7} } - -func (m *SourceOp) GetIdentifier() string { - if m != nil { - return m.Identifier - } - return "" -} +func (m *SourceOp) Reset() { *m = SourceOp{} } +func (m *SourceOp) String() string { return proto.CompactTextString(m) } +func (*SourceOp) ProtoMessage() {} func init() { proto.RegisterType((*Op)(nil), "pb.Op") @@ -389,550 +265,27 @@ func init() { proto.RegisterType((*CopySource)(nil), "pb.CopySource") proto.RegisterType((*SourceOp)(nil), "pb.SourceOp") } -func (this *Op) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*Op) - if !ok { - that2, ok := that.(Op) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if len(this.Inputs) != len(that1.Inputs) { - return false - } - for i := range this.Inputs { - if !this.Inputs[i].Equal(that1.Inputs[i]) { - return false - } - } - if that1.Op == nil { - if this.Op != nil { - return false - } - } else if this.Op == nil { - return false - } else if !this.Op.Equal(that1.Op) { - return false - } - return true -} -func (this *Op_Exec) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*Op_Exec) - if !ok { - that2, ok := that.(Op_Exec) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if !this.Exec.Equal(that1.Exec) { - return false - } - return true -} -func (this *Op_Source) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*Op_Source) - if !ok { - that2, ok := that.(Op_Source) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if !this.Source.Equal(that1.Source) { - return false - } - return true -} -func (this *Op_Copy) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*Op_Copy) - if !ok { - that2, ok := that.(Op_Copy) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if !this.Copy.Equal(that1.Copy) { - return false - } - return true -} -func (this *Input) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*Input) - if !ok { - that2, ok := that.(Input) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if this.Digest != that1.Digest { - return false - } - if this.Index != that1.Index { - return false - } - return true -} -func (this *ExecOp) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*ExecOp) - if !ok { - that2, ok := that.(ExecOp) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if !this.Meta.Equal(that1.Meta) { - return false - } - if len(this.Mounts) != len(that1.Mounts) { - return false - } - for i := range this.Mounts { - if !this.Mounts[i].Equal(that1.Mounts[i]) { - return false - } - } - return true -} -func (this *Meta) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*Meta) - if !ok { - that2, ok := that.(Meta) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if len(this.Args) != len(that1.Args) { - return false - } - for i := range this.Args { - if this.Args[i] != that1.Args[i] { - return false - } - } - if len(this.Env) != len(that1.Env) { - return false - } - for i := range this.Env { - if this.Env[i] != that1.Env[i] { - return false - } - } - if this.Cwd != that1.Cwd { - return false - } - return true -} -func (this *Mount) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*Mount) - if !ok { - that2, ok := that.(Mount) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if this.Input != that1.Input { - return false - } - if this.Selector != that1.Selector { - return false - } - if this.Dest != that1.Dest { - return false - } - if this.Output != that1.Output { - return false - } - return true -} -func (this *CopyOp) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*CopyOp) - if !ok { - that2, ok := that.(CopyOp) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if len(this.Src) != len(that1.Src) { - return false - } - for i := range this.Src { - if !this.Src[i].Equal(that1.Src[i]) { - return false - } - } - if this.Dest != that1.Dest { - return false - } - return true -} -func (this *CopySource) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*CopySource) - if !ok { - that2, ok := that.(CopySource) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if this.Input != that1.Input { - return false - } - if this.Selector != that1.Selector { - return false - } - return true -} -func (this *SourceOp) Equal(that interface{}) bool { - if that == nil { - if this == nil { - return true - } - return false - } - - that1, ok := that.(*SourceOp) - if !ok { - that2, ok := that.(SourceOp) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - if this == nil { - return true - } - return false - } else if this == nil { - return false - } - if this.Identifier != that1.Identifier { - return false - } - return true -} -func (this *Op) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 8) - s = append(s, "&pb.Op{") - if this.Inputs != nil { - s = append(s, "Inputs: "+fmt.Sprintf("%#v", this.Inputs)+",\n") - } - if this.Op != nil { - s = append(s, "Op: "+fmt.Sprintf("%#v", this.Op)+",\n") - } - s = append(s, "}") - return strings.Join(s, "") -} -func (this *Op_Exec) GoString() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&pb.Op_Exec{` + - `Exec:` + fmt.Sprintf("%#v", this.Exec) + `}`}, ", ") - return s -} -func (this *Op_Source) GoString() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&pb.Op_Source{` + - `Source:` + fmt.Sprintf("%#v", this.Source) + `}`}, ", ") - return s -} -func (this *Op_Copy) GoString() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&pb.Op_Copy{` + - `Copy:` + fmt.Sprintf("%#v", this.Copy) + `}`}, ", ") - return s -} -func (this *Input) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&pb.Input{") - s = append(s, "Digest: "+fmt.Sprintf("%#v", this.Digest)+",\n") - s = append(s, "Index: "+fmt.Sprintf("%#v", this.Index)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *ExecOp) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&pb.ExecOp{") - if this.Meta != nil { - s = append(s, "Meta: "+fmt.Sprintf("%#v", this.Meta)+",\n") - } - if this.Mounts != nil { - s = append(s, "Mounts: "+fmt.Sprintf("%#v", this.Mounts)+",\n") - } - s = append(s, "}") - return strings.Join(s, "") -} -func (this *Meta) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 7) - s = append(s, "&pb.Meta{") - s = append(s, "Args: "+fmt.Sprintf("%#v", this.Args)+",\n") - s = append(s, "Env: "+fmt.Sprintf("%#v", this.Env)+",\n") - s = append(s, "Cwd: "+fmt.Sprintf("%#v", this.Cwd)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *Mount) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 8) - s = append(s, "&pb.Mount{") - s = append(s, "Input: "+fmt.Sprintf("%#v", this.Input)+",\n") - s = append(s, "Selector: "+fmt.Sprintf("%#v", this.Selector)+",\n") - s = append(s, "Dest: "+fmt.Sprintf("%#v", this.Dest)+",\n") - s = append(s, "Output: "+fmt.Sprintf("%#v", this.Output)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *CopyOp) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&pb.CopyOp{") - if this.Src != nil { - s = append(s, "Src: "+fmt.Sprintf("%#v", this.Src)+",\n") - } - s = append(s, "Dest: "+fmt.Sprintf("%#v", this.Dest)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *CopySource) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&pb.CopySource{") - s = append(s, "Input: "+fmt.Sprintf("%#v", this.Input)+",\n") - s = append(s, "Selector: "+fmt.Sprintf("%#v", this.Selector)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *SourceOp) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 5) - s = append(s, "&pb.SourceOp{") - s = append(s, "Identifier: "+fmt.Sprintf("%#v", this.Identifier)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringOps(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *Op) Marshal() (dAtA []byte, err error) { +func (m *Op) Marshal() (data []byte, err error) { size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + data = make([]byte, size) + n, err := m.MarshalTo(data) if err != nil { return nil, err } - return dAtA[:n], nil + return data[:n], nil } -func (m *Op) MarshalTo(dAtA []byte) (int, error) { +func (m *Op) MarshalTo(data []byte) (int, error) { var i int _ = i var l int _ = l if len(m.Inputs) > 0 { for _, msg := range m.Inputs { - dAtA[i] = 0xa + data[i] = 0xa i++ - i = encodeVarintOps(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) + i = encodeVarintOps(data, i, uint64(msg.Size())) + n, err := msg.MarshalTo(data[i:]) if err != nil { return 0, err } @@ -940,7 +293,7 @@ func (m *Op) MarshalTo(dAtA []byte) (int, error) { } } if m.Op != nil { - nn1, err := m.Op.MarshalTo(dAtA[i:]) + nn1, err := m.Op.MarshalTo(data[i:]) if err != nil { return 0, err } @@ -949,13 +302,13 @@ func (m *Op) MarshalTo(dAtA []byte) (int, error) { return i, nil } -func (m *Op_Exec) MarshalTo(dAtA []byte) (int, error) { +func (m *Op_Exec) MarshalTo(data []byte) (int, error) { i := 0 if m.Exec != nil { - dAtA[i] = 0x12 + data[i] = 0x12 i++ - i = encodeVarintOps(dAtA, i, uint64(m.Exec.Size())) - n2, err := m.Exec.MarshalTo(dAtA[i:]) + i = encodeVarintOps(data, i, uint64(m.Exec.Size())) + n2, err := m.Exec.MarshalTo(data[i:]) if err != nil { return 0, err } @@ -963,13 +316,13 @@ func (m *Op_Exec) MarshalTo(dAtA []byte) (int, error) { } return i, nil } -func (m *Op_Source) MarshalTo(dAtA []byte) (int, error) { +func (m *Op_Source) MarshalTo(data []byte) (int, error) { i := 0 if m.Source != nil { - dAtA[i] = 0x1a + data[i] = 0x1a i++ - i = encodeVarintOps(dAtA, i, uint64(m.Source.Size())) - n3, err := m.Source.MarshalTo(dAtA[i:]) + i = encodeVarintOps(data, i, uint64(m.Source.Size())) + n3, err := m.Source.MarshalTo(data[i:]) if err != nil { return 0, err } @@ -977,13 +330,13 @@ func (m *Op_Source) MarshalTo(dAtA []byte) (int, error) { } return i, nil } -func (m *Op_Copy) MarshalTo(dAtA []byte) (int, error) { +func (m *Op_Copy) MarshalTo(data []byte) (int, error) { i := 0 if m.Copy != nil { - dAtA[i] = 0x22 + data[i] = 0x22 i++ - i = encodeVarintOps(dAtA, i, uint64(m.Copy.Size())) - n4, err := m.Copy.MarshalTo(dAtA[i:]) + i = encodeVarintOps(data, i, uint64(m.Copy.Size())) + n4, err := m.Copy.MarshalTo(data[i:]) if err != nil { return 0, err } @@ -991,55 +344,55 @@ func (m *Op_Copy) MarshalTo(dAtA []byte) (int, error) { } return i, nil } -func (m *Input) Marshal() (dAtA []byte, err error) { +func (m *Input) Marshal() (data []byte, err error) { size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + data = make([]byte, size) + n, err := m.MarshalTo(data) if err != nil { return nil, err } - return dAtA[:n], nil + return data[:n], nil } -func (m *Input) MarshalTo(dAtA []byte) (int, error) { +func (m *Input) MarshalTo(data []byte) (int, error) { var i int _ = i var l int _ = l if len(m.Digest) > 0 { - dAtA[i] = 0xa + data[i] = 0xa i++ - i = encodeVarintOps(dAtA, i, uint64(len(m.Digest))) - i += copy(dAtA[i:], m.Digest) + i = encodeVarintOps(data, i, uint64(len(m.Digest))) + i += copy(data[i:], m.Digest) } if m.Index != 0 { - dAtA[i] = 0x10 + data[i] = 0x10 i++ - i = encodeVarintOps(dAtA, i, uint64(m.Index)) + i = encodeVarintOps(data, i, uint64(m.Index)) } return i, nil } -func (m *ExecOp) Marshal() (dAtA []byte, err error) { +func (m *ExecOp) Marshal() (data []byte, err error) { size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + data = make([]byte, size) + n, err := m.MarshalTo(data) if err != nil { return nil, err } - return dAtA[:n], nil + return data[:n], nil } -func (m *ExecOp) MarshalTo(dAtA []byte) (int, error) { +func (m *ExecOp) MarshalTo(data []byte) (int, error) { var i int _ = i var l int _ = l if m.Meta != nil { - dAtA[i] = 0xa + data[i] = 0xa i++ - i = encodeVarintOps(dAtA, i, uint64(m.Meta.Size())) - n5, err := m.Meta.MarshalTo(dAtA[i:]) + i = encodeVarintOps(data, i, uint64(m.Meta.Size())) + n5, err := m.Meta.MarshalTo(data[i:]) if err != nil { return 0, err } @@ -1047,10 +400,10 @@ func (m *ExecOp) MarshalTo(dAtA []byte) (int, error) { } if len(m.Mounts) > 0 { for _, msg := range m.Mounts { - dAtA[i] = 0x12 + data[i] = 0x12 i++ - i = encodeVarintOps(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) + i = encodeVarintOps(data, i, uint64(msg.Size())) + n, err := msg.MarshalTo(data[i:]) if err != nil { return 0, err } @@ -1060,121 +413,121 @@ func (m *ExecOp) MarshalTo(dAtA []byte) (int, error) { return i, nil } -func (m *Meta) Marshal() (dAtA []byte, err error) { +func (m *Meta) Marshal() (data []byte, err error) { size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + data = make([]byte, size) + n, err := m.MarshalTo(data) if err != nil { return nil, err } - return dAtA[:n], nil + return data[:n], nil } -func (m *Meta) MarshalTo(dAtA []byte) (int, error) { +func (m *Meta) MarshalTo(data []byte) (int, error) { var i int _ = i var l int _ = l if len(m.Args) > 0 { for _, s := range m.Args { - dAtA[i] = 0xa + data[i] = 0xa i++ l = len(s) for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) + data[i] = uint8(uint64(l)&0x7f | 0x80) l >>= 7 i++ } - dAtA[i] = uint8(l) + data[i] = uint8(l) i++ - i += copy(dAtA[i:], s) + i += copy(data[i:], s) } } if len(m.Env) > 0 { for _, s := range m.Env { - dAtA[i] = 0x12 + data[i] = 0x12 i++ l = len(s) for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) + data[i] = uint8(uint64(l)&0x7f | 0x80) l >>= 7 i++ } - dAtA[i] = uint8(l) + data[i] = uint8(l) i++ - i += copy(dAtA[i:], s) + i += copy(data[i:], s) } } if len(m.Cwd) > 0 { - dAtA[i] = 0x1a + data[i] = 0x1a i++ - i = encodeVarintOps(dAtA, i, uint64(len(m.Cwd))) - i += copy(dAtA[i:], m.Cwd) + i = encodeVarintOps(data, i, uint64(len(m.Cwd))) + i += copy(data[i:], m.Cwd) } return i, nil } -func (m *Mount) Marshal() (dAtA []byte, err error) { +func (m *Mount) Marshal() (data []byte, err error) { size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + data = make([]byte, size) + n, err := m.MarshalTo(data) if err != nil { return nil, err } - return dAtA[:n], nil + return data[:n], nil } -func (m *Mount) MarshalTo(dAtA []byte) (int, error) { +func (m *Mount) MarshalTo(data []byte) (int, error) { var i int _ = i var l int _ = l if m.Input != 0 { - dAtA[i] = 0x8 + data[i] = 0x8 i++ - i = encodeVarintOps(dAtA, i, uint64(m.Input)) + i = encodeVarintOps(data, i, uint64(m.Input)) } if len(m.Selector) > 0 { - dAtA[i] = 0x12 + data[i] = 0x12 i++ - i = encodeVarintOps(dAtA, i, uint64(len(m.Selector))) - i += copy(dAtA[i:], m.Selector) + i = encodeVarintOps(data, i, uint64(len(m.Selector))) + i += copy(data[i:], m.Selector) } if len(m.Dest) > 0 { - dAtA[i] = 0x1a + data[i] = 0x1a i++ - i = encodeVarintOps(dAtA, i, uint64(len(m.Dest))) - i += copy(dAtA[i:], m.Dest) + i = encodeVarintOps(data, i, uint64(len(m.Dest))) + i += copy(data[i:], m.Dest) } if m.Output != 0 { - dAtA[i] = 0x20 + data[i] = 0x20 i++ - i = encodeVarintOps(dAtA, i, uint64(m.Output)) + i = encodeVarintOps(data, i, uint64(m.Output)) } return i, nil } -func (m *CopyOp) Marshal() (dAtA []byte, err error) { +func (m *CopyOp) Marshal() (data []byte, err error) { size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + data = make([]byte, size) + n, err := m.MarshalTo(data) if err != nil { return nil, err } - return dAtA[:n], nil + return data[:n], nil } -func (m *CopyOp) MarshalTo(dAtA []byte) (int, error) { +func (m *CopyOp) MarshalTo(data []byte) (int, error) { var i int _ = i var l int _ = l if len(m.Src) > 0 { for _, msg := range m.Src { - dAtA[i] = 0xa + data[i] = 0xa i++ - i = encodeVarintOps(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) + i = encodeVarintOps(data, i, uint64(msg.Size())) + n, err := msg.MarshalTo(data[i:]) if err != nil { return 0, err } @@ -1182,92 +535,92 @@ func (m *CopyOp) MarshalTo(dAtA []byte) (int, error) { } } if len(m.Dest) > 0 { - dAtA[i] = 0x12 + data[i] = 0x12 i++ - i = encodeVarintOps(dAtA, i, uint64(len(m.Dest))) - i += copy(dAtA[i:], m.Dest) + i = encodeVarintOps(data, i, uint64(len(m.Dest))) + i += copy(data[i:], m.Dest) } return i, nil } -func (m *CopySource) Marshal() (dAtA []byte, err error) { +func (m *CopySource) Marshal() (data []byte, err error) { size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + data = make([]byte, size) + n, err := m.MarshalTo(data) if err != nil { return nil, err } - return dAtA[:n], nil + return data[:n], nil } -func (m *CopySource) MarshalTo(dAtA []byte) (int, error) { +func (m *CopySource) MarshalTo(data []byte) (int, error) { var i int _ = i var l int _ = l if m.Input != 0 { - dAtA[i] = 0x8 + data[i] = 0x8 i++ - i = encodeVarintOps(dAtA, i, uint64(m.Input)) + i = encodeVarintOps(data, i, uint64(m.Input)) } if len(m.Selector) > 0 { - dAtA[i] = 0x12 + data[i] = 0x12 i++ - i = encodeVarintOps(dAtA, i, uint64(len(m.Selector))) - i += copy(dAtA[i:], m.Selector) + i = encodeVarintOps(data, i, uint64(len(m.Selector))) + i += copy(data[i:], m.Selector) } return i, nil } -func (m *SourceOp) Marshal() (dAtA []byte, err error) { +func (m *SourceOp) Marshal() (data []byte, err error) { size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + data = make([]byte, size) + n, err := m.MarshalTo(data) if err != nil { return nil, err } - return dAtA[:n], nil + return data[:n], nil } -func (m *SourceOp) MarshalTo(dAtA []byte) (int, error) { +func (m *SourceOp) MarshalTo(data []byte) (int, error) { var i int _ = i var l int _ = l if len(m.Identifier) > 0 { - dAtA[i] = 0xa + data[i] = 0xa i++ - i = encodeVarintOps(dAtA, i, uint64(len(m.Identifier))) - i += copy(dAtA[i:], m.Identifier) + i = encodeVarintOps(data, i, uint64(len(m.Identifier))) + i += copy(data[i:], m.Identifier) } return i, nil } -func encodeFixed64Ops(dAtA []byte, offset int, v uint64) int { - dAtA[offset] = uint8(v) - dAtA[offset+1] = uint8(v >> 8) - dAtA[offset+2] = uint8(v >> 16) - dAtA[offset+3] = uint8(v >> 24) - dAtA[offset+4] = uint8(v >> 32) - dAtA[offset+5] = uint8(v >> 40) - dAtA[offset+6] = uint8(v >> 48) - dAtA[offset+7] = uint8(v >> 56) +func encodeFixed64Ops(data []byte, offset int, v uint64) int { + data[offset] = uint8(v) + data[offset+1] = uint8(v >> 8) + data[offset+2] = uint8(v >> 16) + data[offset+3] = uint8(v >> 24) + data[offset+4] = uint8(v >> 32) + data[offset+5] = uint8(v >> 40) + data[offset+6] = uint8(v >> 48) + data[offset+7] = uint8(v >> 56) return offset + 8 } -func encodeFixed32Ops(dAtA []byte, offset int, v uint32) int { - dAtA[offset] = uint8(v) - dAtA[offset+1] = uint8(v >> 8) - dAtA[offset+2] = uint8(v >> 16) - dAtA[offset+3] = uint8(v >> 24) +func encodeFixed32Ops(data []byte, offset int, v uint32) int { + data[offset] = uint8(v) + data[offset+1] = uint8(v >> 8) + data[offset+2] = uint8(v >> 16) + data[offset+3] = uint8(v >> 24) return offset + 4 } -func encodeVarintOps(dAtA []byte, offset int, v uint64) int { +func encodeVarintOps(data []byte, offset int, v uint64) int { for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) + data[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } - dAtA[offset] = uint8(v) + data[offset] = uint8(v) return offset + 1 } func (m *Op) Size() (n int) { @@ -1435,136 +788,8 @@ func sovOps(x uint64) (n int) { func sozOps(x uint64) (n int) { return sovOps(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (this *Op) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Op{`, - `Inputs:` + strings.Replace(fmt.Sprintf("%v", this.Inputs), "Input", "Input", 1) + `,`, - `Op:` + fmt.Sprintf("%v", this.Op) + `,`, - `}`, - }, "") - return s -} -func (this *Op_Exec) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Op_Exec{`, - `Exec:` + strings.Replace(fmt.Sprintf("%v", this.Exec), "ExecOp", "ExecOp", 1) + `,`, - `}`, - }, "") - return s -} -func (this *Op_Source) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Op_Source{`, - `Source:` + strings.Replace(fmt.Sprintf("%v", this.Source), "SourceOp", "SourceOp", 1) + `,`, - `}`, - }, "") - return s -} -func (this *Op_Copy) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Op_Copy{`, - `Copy:` + strings.Replace(fmt.Sprintf("%v", this.Copy), "CopyOp", "CopyOp", 1) + `,`, - `}`, - }, "") - return s -} -func (this *Input) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Input{`, - `Digest:` + fmt.Sprintf("%v", this.Digest) + `,`, - `Index:` + fmt.Sprintf("%v", this.Index) + `,`, - `}`, - }, "") - return s -} -func (this *ExecOp) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&ExecOp{`, - `Meta:` + strings.Replace(fmt.Sprintf("%v", this.Meta), "Meta", "Meta", 1) + `,`, - `Mounts:` + strings.Replace(fmt.Sprintf("%v", this.Mounts), "Mount", "Mount", 1) + `,`, - `}`, - }, "") - return s -} -func (this *Meta) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Meta{`, - `Args:` + fmt.Sprintf("%v", this.Args) + `,`, - `Env:` + fmt.Sprintf("%v", this.Env) + `,`, - `Cwd:` + fmt.Sprintf("%v", this.Cwd) + `,`, - `}`, - }, "") - return s -} -func (this *Mount) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Mount{`, - `Input:` + fmt.Sprintf("%v", this.Input) + `,`, - `Selector:` + fmt.Sprintf("%v", this.Selector) + `,`, - `Dest:` + fmt.Sprintf("%v", this.Dest) + `,`, - `Output:` + fmt.Sprintf("%v", this.Output) + `,`, - `}`, - }, "") - return s -} -func (this *CopyOp) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&CopyOp{`, - `Src:` + strings.Replace(fmt.Sprintf("%v", this.Src), "CopySource", "CopySource", 1) + `,`, - `Dest:` + fmt.Sprintf("%v", this.Dest) + `,`, - `}`, - }, "") - return s -} -func (this *CopySource) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&CopySource{`, - `Input:` + fmt.Sprintf("%v", this.Input) + `,`, - `Selector:` + fmt.Sprintf("%v", this.Selector) + `,`, - `}`, - }, "") - return s -} -func (this *SourceOp) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&SourceOp{`, - `Identifier:` + fmt.Sprintf("%v", this.Identifier) + `,`, - `}`, - }, "") - return s -} -func valueToStringOps(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *Op) Unmarshal(dAtA []byte) error { - l := len(dAtA) +func (m *Op) Unmarshal(data []byte) error { + l := len(data) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -1576,7 +801,7 @@ func (m *Op) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ wire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -1604,7 +829,7 @@ func (m *Op) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ msglen |= (int(b) & 0x7F) << shift if b < 0x80 { @@ -1619,7 +844,7 @@ func (m *Op) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } m.Inputs = append(m.Inputs, &Input{}) - if err := m.Inputs[len(m.Inputs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Inputs[len(m.Inputs)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1635,7 +860,7 @@ func (m *Op) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ msglen |= (int(b) & 0x7F) << shift if b < 0x80 { @@ -1650,7 +875,7 @@ func (m *Op) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } v := &ExecOp{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := v.Unmarshal(data[iNdEx:postIndex]); err != nil { return err } m.Op = &Op_Exec{v} @@ -1667,7 +892,7 @@ func (m *Op) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ msglen |= (int(b) & 0x7F) << shift if b < 0x80 { @@ -1682,7 +907,7 @@ func (m *Op) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } v := &SourceOp{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := v.Unmarshal(data[iNdEx:postIndex]); err != nil { return err } m.Op = &Op_Source{v} @@ -1699,7 +924,7 @@ func (m *Op) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ msglen |= (int(b) & 0x7F) << shift if b < 0x80 { @@ -1714,14 +939,14 @@ func (m *Op) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } v := &CopyOp{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := v.Unmarshal(data[iNdEx:postIndex]); err != nil { return err } m.Op = &Op_Copy{v} iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipOps(dAtA[iNdEx:]) + skippy, err := skipOps(data[iNdEx:]) if err != nil { return err } @@ -1740,8 +965,8 @@ func (m *Op) Unmarshal(dAtA []byte) error { } return nil } -func (m *Input) Unmarshal(dAtA []byte) error { - l := len(dAtA) +func (m *Input) Unmarshal(data []byte) error { + l := len(data) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -1753,7 +978,7 @@ func (m *Input) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ wire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -1781,7 +1006,7 @@ func (m *Input) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -1796,7 +1021,7 @@ func (m *Input) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Digest = string(dAtA[iNdEx:postIndex]) + m.Digest = github_com_opencontainers_go_digest.Digest(data[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 0 { @@ -1810,7 +1035,7 @@ func (m *Input) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ m.Index |= (int64(b) & 0x7F) << shift if b < 0x80 { @@ -1819,7 +1044,7 @@ func (m *Input) Unmarshal(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skipOps(dAtA[iNdEx:]) + skippy, err := skipOps(data[iNdEx:]) if err != nil { return err } @@ -1838,8 +1063,8 @@ func (m *Input) Unmarshal(dAtA []byte) error { } return nil } -func (m *ExecOp) Unmarshal(dAtA []byte) error { - l := len(dAtA) +func (m *ExecOp) Unmarshal(data []byte) error { + l := len(data) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -1851,7 +1076,7 @@ func (m *ExecOp) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ wire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -1879,7 +1104,7 @@ func (m *ExecOp) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ msglen |= (int(b) & 0x7F) << shift if b < 0x80 { @@ -1896,7 +1121,7 @@ func (m *ExecOp) Unmarshal(dAtA []byte) error { if m.Meta == nil { m.Meta = &Meta{} } - if err := m.Meta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Meta.Unmarshal(data[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1912,7 +1137,7 @@ func (m *ExecOp) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ msglen |= (int(b) & 0x7F) << shift if b < 0x80 { @@ -1927,13 +1152,13 @@ func (m *ExecOp) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } m.Mounts = append(m.Mounts, &Mount{}) - if err := m.Mounts[len(m.Mounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Mounts[len(m.Mounts)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipOps(dAtA[iNdEx:]) + skippy, err := skipOps(data[iNdEx:]) if err != nil { return err } @@ -1952,8 +1177,8 @@ func (m *ExecOp) Unmarshal(dAtA []byte) error { } return nil } -func (m *Meta) Unmarshal(dAtA []byte) error { - l := len(dAtA) +func (m *Meta) Unmarshal(data []byte) error { + l := len(data) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -1965,7 +1190,7 @@ func (m *Meta) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ wire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -1993,7 +1218,7 @@ func (m *Meta) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2008,7 +1233,7 @@ func (m *Meta) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Args = append(m.Args, string(dAtA[iNdEx:postIndex])) + m.Args = append(m.Args, string(data[iNdEx:postIndex])) iNdEx = postIndex case 2: if wireType != 2 { @@ -2022,7 +1247,7 @@ func (m *Meta) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2037,7 +1262,7 @@ func (m *Meta) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Env = append(m.Env, string(dAtA[iNdEx:postIndex])) + m.Env = append(m.Env, string(data[iNdEx:postIndex])) iNdEx = postIndex case 3: if wireType != 2 { @@ -2051,7 +1276,7 @@ func (m *Meta) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2066,11 +1291,11 @@ func (m *Meta) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Cwd = string(dAtA[iNdEx:postIndex]) + m.Cwd = string(data[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipOps(dAtA[iNdEx:]) + skippy, err := skipOps(data[iNdEx:]) if err != nil { return err } @@ -2089,8 +1314,8 @@ func (m *Meta) Unmarshal(dAtA []byte) error { } return nil } -func (m *Mount) Unmarshal(dAtA []byte) error { - l := len(dAtA) +func (m *Mount) Unmarshal(data []byte) error { + l := len(data) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -2102,7 +1327,7 @@ func (m *Mount) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ wire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2130,7 +1355,7 @@ func (m *Mount) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ m.Input |= (int64(b) & 0x7F) << shift if b < 0x80 { @@ -2149,7 +1374,7 @@ func (m *Mount) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2164,7 +1389,7 @@ func (m *Mount) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Selector = string(dAtA[iNdEx:postIndex]) + m.Selector = string(data[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { @@ -2178,7 +1403,7 @@ func (m *Mount) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2193,7 +1418,7 @@ func (m *Mount) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Dest = string(dAtA[iNdEx:postIndex]) + m.Dest = string(data[iNdEx:postIndex]) iNdEx = postIndex case 4: if wireType != 0 { @@ -2207,7 +1432,7 @@ func (m *Mount) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ m.Output |= (int64(b) & 0x7F) << shift if b < 0x80 { @@ -2216,7 +1441,7 @@ func (m *Mount) Unmarshal(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skipOps(dAtA[iNdEx:]) + skippy, err := skipOps(data[iNdEx:]) if err != nil { return err } @@ -2235,8 +1460,8 @@ func (m *Mount) Unmarshal(dAtA []byte) error { } return nil } -func (m *CopyOp) Unmarshal(dAtA []byte) error { - l := len(dAtA) +func (m *CopyOp) Unmarshal(data []byte) error { + l := len(data) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -2248,7 +1473,7 @@ func (m *CopyOp) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ wire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2276,7 +1501,7 @@ func (m *CopyOp) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ msglen |= (int(b) & 0x7F) << shift if b < 0x80 { @@ -2291,7 +1516,7 @@ func (m *CopyOp) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } m.Src = append(m.Src, &CopySource{}) - if err := m.Src[len(m.Src)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Src[len(m.Src)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -2307,7 +1532,7 @@ func (m *CopyOp) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2322,11 +1547,11 @@ func (m *CopyOp) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Dest = string(dAtA[iNdEx:postIndex]) + m.Dest = string(data[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipOps(dAtA[iNdEx:]) + skippy, err := skipOps(data[iNdEx:]) if err != nil { return err } @@ -2345,8 +1570,8 @@ func (m *CopyOp) Unmarshal(dAtA []byte) error { } return nil } -func (m *CopySource) Unmarshal(dAtA []byte) error { - l := len(dAtA) +func (m *CopySource) Unmarshal(data []byte) error { + l := len(data) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -2358,7 +1583,7 @@ func (m *CopySource) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ wire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2386,7 +1611,7 @@ func (m *CopySource) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ m.Input |= (int64(b) & 0x7F) << shift if b < 0x80 { @@ -2405,7 +1630,7 @@ func (m *CopySource) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2420,11 +1645,11 @@ func (m *CopySource) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Selector = string(dAtA[iNdEx:postIndex]) + m.Selector = string(data[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipOps(dAtA[iNdEx:]) + skippy, err := skipOps(data[iNdEx:]) if err != nil { return err } @@ -2443,8 +1668,8 @@ func (m *CopySource) Unmarshal(dAtA []byte) error { } return nil } -func (m *SourceOp) Unmarshal(dAtA []byte) error { - l := len(dAtA) +func (m *SourceOp) Unmarshal(data []byte) error { + l := len(data) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -2456,7 +1681,7 @@ func (m *SourceOp) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ wire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2484,7 +1709,7 @@ func (m *SourceOp) Unmarshal(dAtA []byte) error { if iNdEx >= l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ stringLen |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2499,11 +1724,11 @@ func (m *SourceOp) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Identifier = string(dAtA[iNdEx:postIndex]) + m.Identifier = string(data[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipOps(dAtA[iNdEx:]) + skippy, err := skipOps(data[iNdEx:]) if err != nil { return err } @@ -2522,8 +1747,8 @@ func (m *SourceOp) Unmarshal(dAtA []byte) error { } return nil } -func skipOps(dAtA []byte) (n int, err error) { - l := len(dAtA) +func skipOps(data []byte) (n int, err error) { + l := len(data) iNdEx := 0 for iNdEx < l { var wire uint64 @@ -2534,7 +1759,7 @@ func skipOps(dAtA []byte) (n int, err error) { if iNdEx >= l { return 0, io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ wire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2552,7 +1777,7 @@ func skipOps(dAtA []byte) (n int, err error) { return 0, io.ErrUnexpectedEOF } iNdEx++ - if dAtA[iNdEx-1] < 0x80 { + if data[iNdEx-1] < 0x80 { break } } @@ -2569,7 +1794,7 @@ func skipOps(dAtA []byte) (n int, err error) { if iNdEx >= l { return 0, io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ length |= (int(b) & 0x7F) << shift if b < 0x80 { @@ -2592,7 +1817,7 @@ func skipOps(dAtA []byte) (n int, err error) { if iNdEx >= l { return 0, io.ErrUnexpectedEOF } - b := dAtA[iNdEx] + b := data[iNdEx] iNdEx++ innerWire |= (uint64(b) & 0x7F) << shift if b < 0x80 { @@ -2603,7 +1828,7 @@ func skipOps(dAtA []byte) (n int, err error) { if innerWireType == 4 { break } - next, err := skipOps(dAtA[start:]) + next, err := skipOps(data[start:]) if err != nil { return 0, err } @@ -2626,36 +1851,3 @@ var ( ErrInvalidLengthOps = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowOps = fmt.Errorf("proto: integer overflow") ) - -func init() { proto.RegisterFile("ops.proto", fileDescriptorOps) } - -var fileDescriptorOps = []byte{ - // 422 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x94, 0x52, 0xb1, 0x8e, 0xd3, 0x40, - 0x10, 0xf5, 0xda, 0x8e, 0x15, 0x4f, 0x10, 0x42, 0x2b, 0x84, 0x2c, 0x84, 0x56, 0x66, 0x0b, 0x14, - 0x21, 0x94, 0x22, 0x88, 0x36, 0xc5, 0x21, 0x24, 0xae, 0x38, 0x9d, 0xb4, 0x7c, 0x41, 0x62, 0x2f, - 0x27, 0x4b, 0xc4, 0xbb, 0xb2, 0xd7, 0x90, 0x74, 0x7c, 0x02, 0x2d, 0x7f, 0xc0, 0xa7, 0x50, 0xa6, - 0xa4, 0x24, 0xa6, 0xa1, 0xcc, 0x27, 0xa0, 0x99, 0x75, 0x62, 0xda, 0xeb, 0x66, 0xde, 0x9b, 0x7d, - 0x7e, 0x6f, 0xc6, 0x90, 0x1a, 0xdb, 0x2e, 0x6c, 0x63, 0x9c, 0xe1, 0xa1, 0xdd, 0xc8, 0xef, 0x0c, - 0xc2, 0x5b, 0xcb, 0x9f, 0x43, 0x52, 0xd5, 0xb6, 0x73, 0x6d, 0xc6, 0xf2, 0x68, 0x3e, 0x5b, 0xa6, - 0x0b, 0xbb, 0x59, 0x5c, 0x23, 0xa2, 0x06, 0x82, 0xe7, 0x10, 0xeb, 0x9d, 0x2e, 0xb2, 0x30, 0x67, - 0xf3, 0xd9, 0x12, 0x70, 0xe0, 0xdd, 0x4e, 0x17, 0xb7, 0xf6, 0x7d, 0xa0, 0x88, 0xe1, 0x2f, 0x20, - 0x69, 0x4d, 0xd7, 0x14, 0x3a, 0x8b, 0x68, 0xe6, 0x01, 0xce, 0x7c, 0x20, 0x84, 0xa6, 0x06, 0x16, - 0x95, 0x0a, 0x63, 0xf7, 0x59, 0x3c, 0x2a, 0xbd, 0x35, 0x76, 0xef, 0x95, 0x90, 0xb9, 0x8a, 0x21, - 0x34, 0x56, 0xbe, 0x81, 0x09, 0x59, 0xe0, 0x4f, 0x20, 0x29, 0xab, 0x3b, 0xdd, 0xba, 0x8c, 0xe5, - 0x6c, 0x9e, 0xaa, 0xa1, 0xe3, 0x8f, 0x61, 0x52, 0xd5, 0xa5, 0xde, 0x91, 0xa7, 0x48, 0xf9, 0x46, - 0x5e, 0x43, 0xe2, 0x8d, 0xf1, 0x67, 0x10, 0x6f, 0xb5, 0x5b, 0xd3, 0xab, 0xd9, 0x72, 0x8a, 0x1f, - 0xba, 0xd1, 0x6e, 0xad, 0x08, 0xc5, 0xcc, 0x5b, 0xd3, 0xd5, 0xae, 0xcd, 0xc2, 0x31, 0xf3, 0x0d, - 0x22, 0x6a, 0x20, 0xe4, 0x0a, 0x62, 0x7c, 0xc0, 0x39, 0xc4, 0xeb, 0xe6, 0xce, 0x2f, 0x27, 0x55, - 0x54, 0xf3, 0x47, 0x10, 0xe9, 0xfa, 0x33, 0xbd, 0x4d, 0x15, 0x96, 0x88, 0x14, 0x5f, 0x4a, 0x0a, - 0x9f, 0x2a, 0x2c, 0xa5, 0x86, 0x09, 0x09, 0x7a, 0xa7, 0xb6, 0xf3, 0x01, 0xc8, 0x29, 0xe6, 0x7a, - 0x0a, 0xd3, 0x56, 0x7f, 0xd2, 0x85, 0x33, 0x0d, 0x45, 0x48, 0xd5, 0xa5, 0xc7, 0x4f, 0x96, 0x98, - 0xd8, 0xab, 0x51, 0x8d, 0x7b, 0x30, 0x9d, 0x43, 0x99, 0x98, 0x64, 0x86, 0x4e, 0xae, 0x20, 0xf1, - 0x0b, 0xe4, 0x39, 0x44, 0x6d, 0x53, 0x0c, 0x47, 0x7c, 0x78, 0xde, 0xac, 0xbf, 0x81, 0x42, 0xea, - 0xa2, 0x1b, 0x8e, 0xba, 0x72, 0x05, 0x30, 0x8e, 0xdd, 0xdf, 0xab, 0x7c, 0x09, 0xd3, 0xf3, 0x99, - 0xb9, 0x00, 0xa8, 0x4a, 0x5d, 0xbb, 0xea, 0x63, 0xa5, 0x9b, 0xe1, 0x5e, 0xff, 0x21, 0x57, 0xaf, - 0x0e, 0x47, 0x11, 0xfc, 0x3a, 0x8a, 0xe0, 0x74, 0x14, 0xec, 0x6b, 0x2f, 0xd8, 0x8f, 0x5e, 0xb0, - 0x9f, 0xbd, 0x60, 0x87, 0x5e, 0xb0, 0xdf, 0xbd, 0x60, 0x7f, 0x7b, 0x11, 0x9c, 0x7a, 0xc1, 0xbe, - 0xfd, 0x11, 0xc1, 0x26, 0xa1, 0x3f, 0xf5, 0xf5, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa9, 0xb7, - 0xed, 0xb5, 0xb6, 0x02, 0x00, 0x00, -} diff --git a/solver/pb/ops.proto b/solver/pb/ops.proto index 9f24f414..fa902075 100644 --- a/solver/pb/ops.proto +++ b/solver/pb/ops.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package pb; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + message Op { repeated Input inputs = 1; oneof op { @@ -12,7 +14,7 @@ message Op { } message Input { - string digest = 1; + string digest = 1 [(gogoproto.customtype) = "github.com/opencontainers/go-digest.Digest", (gogoproto.nullable) = false]; int64 index = 2; } diff --git a/solver/solver.go b/solver/solver.go index 6b039b38..f1f1ff72 100644 --- a/solver/solver.go +++ b/solver/solver.go @@ -41,6 +41,10 @@ func (s *Solver) Solve(ctx context.Context, id string, g *opVertex) error { pr, ctx, closeProgressWriter := progress.NewContext(ctx) + if len(g.inputs) > 0 { // TODO: detect op_return better + g = g.inputs[0] + } + _, err := s.jobs.new(ctx, id, g, pr) if err != nil { return err @@ -158,7 +162,7 @@ func (g *opVertex) solve(ctx context.Context, opt Opt) (retErr error) { return err } default: - return errors.Errorf("invalid op type") + return errors.Errorf("invalid op type %T", g.op.Op) } return nil } diff --git a/util/system/path_unix.go b/util/system/path_unix.go new file mode 100644 index 00000000..c607c4db --- /dev/null +++ b/util/system/path_unix.go @@ -0,0 +1,14 @@ +// +build !windows + +package system + +// DefaultPathEnv is unix style list of directories to search for +// executables. Each directory is separated from the next by a colon +// ':' character . +const DefaultPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + +// CheckSystemDriveAndRemoveDriveLetter verifies that a path, if it includes a drive letter, +// is the system drive. This is a no-op on Linux. +func CheckSystemDriveAndRemoveDriveLetter(path string) (string, error) { + return path, nil +} diff --git a/util/system/path_windows.go b/util/system/path_windows.go new file mode 100644 index 00000000..cbfe2c15 --- /dev/null +++ b/util/system/path_windows.go @@ -0,0 +1,37 @@ +// +build windows + +package system + +import ( + "fmt" + "path/filepath" + "strings" +) + +// DefaultPathEnv is deliberately empty on Windows as the default path will be set by +// the container. Docker has no context of what the default path should be. +const DefaultPathEnv = "" + +// CheckSystemDriveAndRemoveDriveLetter verifies and manipulates a Windows path. +// This is used, for example, when validating a user provided path in docker cp. +// If a drive letter is supplied, it must be the system drive. The drive letter +// is always removed. Also, it translates it to OS semantics (IOW / to \). We +// need the path in this syntax so that it can ultimately be contatenated with +// a Windows long-path which doesn't support drive-letters. Examples: +// C: --> Fail +// C:\ --> \ +// a --> a +// /a --> \a +// d:\ --> Fail +func CheckSystemDriveAndRemoveDriveLetter(path string) (string, error) { + if len(path) == 2 && string(path[1]) == ":" { + return "", fmt.Errorf("No relative path specified in %q", path) + } + if !filepath.IsAbs(path) || len(path) < 2 { + return filepath.FromSlash(path), nil + } + if string(path[1]) == ":" && !strings.EqualFold(string(path[0]), "c") { + return "", fmt.Errorf("The specified path is not on the system drive (C:)") + } + return filepath.FromSlash(path[2:]), nil +} diff --git a/util/system/path_windows_test.go b/util/system/path_windows_test.go new file mode 100644 index 00000000..f44d77e6 --- /dev/null +++ b/util/system/path_windows_test.go @@ -0,0 +1,78 @@ +// +build windows + +package system + +import "testing" + +// TestCheckSystemDriveAndRemoveDriveLetter tests CheckSystemDriveAndRemoveDriveLetter +func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) { + // Fails if not C drive. + _, err := CheckSystemDriveAndRemoveDriveLetter(`d:\`) + if err == nil || (err != nil && err.Error() != "The specified path is not on the system drive (C:)") { + t.Fatalf("Expected error for d:") + } + + // Single character is unchanged + if path, err = CheckSystemDriveAndRemoveDriveLetter("z"); err != nil { + t.Fatalf("Single character should pass") + } + if path != "z" { + t.Fatalf("Single character should be unchanged") + } + + // Two characters without colon is unchanged + if path, err = CheckSystemDriveAndRemoveDriveLetter("AB"); err != nil { + t.Fatalf("2 characters without colon should pass") + } + if path != "AB" { + t.Fatalf("2 characters without colon should be unchanged") + } + + // Abs path without drive letter + if path, err = CheckSystemDriveAndRemoveDriveLetter(`\l`); err != nil { + t.Fatalf("abs path no drive letter should pass") + } + if path != `\l` { + t.Fatalf("abs path without drive letter should be unchanged") + } + + // Abs path without drive letter, linux style + if path, err = CheckSystemDriveAndRemoveDriveLetter(`/l`); err != nil { + t.Fatalf("abs path no drive letter linux style should pass") + } + if path != `\l` { + t.Fatalf("abs path without drive letter linux failed %s", path) + } + + // Drive-colon should be stripped + if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:\`); err != nil { + t.Fatalf("An absolute path should pass") + } + if path != `\` { + t.Fatalf(`An absolute path should have been shortened to \ %s`, path) + } + + // Verify with a linux-style path + if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:/`); err != nil { + t.Fatalf("An absolute path should pass") + } + if path != `\` { + t.Fatalf(`A linux style absolute path should have been shortened to \ %s`, path) + } + + // Failure on c: + if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:`); err == nil { + t.Fatalf("c: should fail") + } + if err.Error() != `No relative path specified in "c:"` { + t.Fatalf(path, err) + } + + // Failure on d: + if path, err = CheckSystemDriveAndRemoveDriveLetter(`d:`); err == nil { + t.Fatalf("c: should fail") + } + if err.Error() != `No relative path specified in "d:"` { + t.Fatalf(path, err) + } +} diff --git a/vendor.conf b/vendor.conf index a453935d..9b7038d7 100644 --- a/vendor.conf +++ b/vendor.conf @@ -28,3 +28,4 @@ golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4 github.com/urfave/cli d70f47eeca3afd795160003bc6e28b001d60c67c github.com/docker/go-units 0dadbb0345b35ec7ef35e228dabb8de89a65bf52 +github.com/google/shlex 6f45313302b9c56850fc17f99e40caebce98c716 \ No newline at end of file diff --git a/vendor/github.com/google/shlex/COPYING b/vendor/github.com/google/shlex/COPYING new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/vendor/github.com/google/shlex/COPYING @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/vendor/github.com/google/shlex/README b/vendor/github.com/google/shlex/README new file mode 100644 index 00000000..c86bcc06 --- /dev/null +++ b/vendor/github.com/google/shlex/README @@ -0,0 +1,2 @@ +go-shlex is a simple lexer for go that supports shell-style quoting, +commenting, and escaping. diff --git a/vendor/github.com/google/shlex/shlex.go b/vendor/github.com/google/shlex/shlex.go new file mode 100644 index 00000000..3cb37b7e --- /dev/null +++ b/vendor/github.com/google/shlex/shlex.go @@ -0,0 +1,417 @@ +/* +Copyright 2012 Google Inc. All Rights Reserved. + +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 shlex implements a simple lexer which splits input in to tokens using +shell-style rules for quoting and commenting. + +The basic use case uses the default ASCII lexer to split a string into sub-strings: + + shlex.Split("one \"two three\" four") -> []string{"one", "two three", "four"} + +To process a stream of strings: + + l := NewLexer(os.Stdin) + for ; token, err := l.Next(); err != nil { + // process token + } + +To access the raw token stream (which includes tokens for comments): + + t := NewTokenizer(os.Stdin) + for ; token, err := t.Next(); err != nil { + // process token + } + +*/ +package shlex + +import ( + "bufio" + "fmt" + "io" + "strings" +) + +// TokenType is a top-level token classification: A word, space, comment, unknown. +type TokenType int + +// runeTokenClass is the type of a UTF-8 character classification: A quote, space, escape. +type runeTokenClass int + +// the internal state used by the lexer state machine +type lexerState int + +// Token is a (type, value) pair representing a lexographical token. +type Token struct { + tokenType TokenType + value string +} + +// Equal reports whether tokens a, and b, are equal. +// Two tokens are equal if both their types and values are equal. A nil token can +// never be equal to another token. +func (a *Token) Equal(b *Token) bool { + if a == nil || b == nil { + return false + } + if a.tokenType != b.tokenType { + return false + } + return a.value == b.value +} + +// Named classes of UTF-8 runes +const ( + spaceRunes = " \t\r\n" + escapingQuoteRunes = `"` + nonEscapingQuoteRunes = "'" + escapeRunes = `\` + commentRunes = "#" +) + +// Classes of rune token +const ( + unknownRuneClass runeTokenClass = iota + spaceRuneClass + escapingQuoteRuneClass + nonEscapingQuoteRuneClass + escapeRuneClass + commentRuneClass + eofRuneClass +) + +// Classes of lexographic token +const ( + UnknownToken TokenType = iota + WordToken + SpaceToken + CommentToken +) + +// Lexer state machine states +const ( + startState lexerState = iota // no runes have been seen + inWordState // processing regular runes in a word + escapingState // we have just consumed an escape rune; the next rune is literal + escapingQuotedState // we have just consumed an escape rune within a quoted string + quotingEscapingState // we are within a quoted string that supports escaping ("...") + quotingState // we are within a string that does not support escaping ('...') + commentState // we are within a comment (everything following an unquoted or unescaped # +) + +// tokenClassifier is used for classifying rune characters. +type tokenClassifier map[rune]runeTokenClass + +func (typeMap tokenClassifier) addRuneClass(runes string, tokenType runeTokenClass) { + for _, runeChar := range runes { + typeMap[runeChar] = tokenType + } +} + +// newDefaultClassifier creates a new classifier for ASCII characters. +func newDefaultClassifier() tokenClassifier { + t := tokenClassifier{} + t.addRuneClass(spaceRunes, spaceRuneClass) + t.addRuneClass(escapingQuoteRunes, escapingQuoteRuneClass) + t.addRuneClass(nonEscapingQuoteRunes, nonEscapingQuoteRuneClass) + t.addRuneClass(escapeRunes, escapeRuneClass) + t.addRuneClass(commentRunes, commentRuneClass) + return t +} + +// ClassifyRune classifiees a rune +func (t tokenClassifier) ClassifyRune(runeVal rune) runeTokenClass { + return t[runeVal] +} + +// Lexer turns an input stream into a sequence of tokens. Whitespace and comments are skipped. +type Lexer Tokenizer + +// NewLexer creates a new lexer from an input stream. +func NewLexer(r io.Reader) *Lexer { + + return (*Lexer)(NewTokenizer(r)) +} + +// Next returns the next word, or an error. If there are no more words, +// the error will be io.EOF. +func (l *Lexer) Next() (string, error) { + for { + token, err := (*Tokenizer)(l).Next() + if err != nil { + return "", err + } + switch token.tokenType { + case WordToken: + return token.value, nil + case CommentToken: + // skip comments + default: + return "", fmt.Errorf("Unknown token type: %v", token.tokenType) + } + } +} + +// Tokenizer turns an input stream into a sequence of typed tokens +type Tokenizer struct { + input bufio.Reader + classifier tokenClassifier +} + +// NewTokenizer creates a new tokenizer from an input stream. +func NewTokenizer(r io.Reader) *Tokenizer { + input := bufio.NewReader(r) + classifier := newDefaultClassifier() + return &Tokenizer{ + input: *input, + classifier: classifier} +} + +// scanStream scans the stream for the next token using the internal state machine. +// It will panic if it encounters a rune which it does not know how to handle. +func (t *Tokenizer) scanStream() (*Token, error) { + state := startState + var tokenType TokenType + var value []rune + var nextRune rune + var nextRuneType runeTokenClass + var err error + + for { + nextRune, _, err = t.input.ReadRune() + nextRuneType = t.classifier.ClassifyRune(nextRune) + + if err == io.EOF { + nextRuneType = eofRuneClass + err = nil + } else if err != nil { + return nil, err + } + + switch state { + case startState: // no runes read yet + { + switch nextRuneType { + case eofRuneClass: + { + return nil, io.EOF + } + case spaceRuneClass: + { + } + case escapingQuoteRuneClass: + { + tokenType = WordToken + state = quotingEscapingState + } + case nonEscapingQuoteRuneClass: + { + tokenType = WordToken + state = quotingState + } + case escapeRuneClass: + { + tokenType = WordToken + state = escapingState + } + case commentRuneClass: + { + tokenType = CommentToken + state = commentState + } + default: + { + tokenType = WordToken + value = append(value, nextRune) + state = inWordState + } + } + } + case inWordState: // in a regular word + { + switch nextRuneType { + case eofRuneClass: + { + token := &Token{ + tokenType: tokenType, + value: string(value)} + return token, err + } + case spaceRuneClass: + { + t.input.UnreadRune() + token := &Token{ + tokenType: tokenType, + value: string(value)} + return token, err + } + case escapingQuoteRuneClass: + { + state = quotingEscapingState + } + case nonEscapingQuoteRuneClass: + { + state = quotingState + } + case escapeRuneClass: + { + state = escapingState + } + default: + { + value = append(value, nextRune) + } + } + } + case escapingState: // the rune after an escape character + { + switch nextRuneType { + case eofRuneClass: + { + err = fmt.Errorf("EOF found after escape character") + token := &Token{ + tokenType: tokenType, + value: string(value)} + return token, err + } + default: + { + state = inWordState + value = append(value, nextRune) + } + } + } + case escapingQuotedState: // the next rune after an escape character, in double quotes + { + switch nextRuneType { + case eofRuneClass: + { + err = fmt.Errorf("EOF found after escape character") + token := &Token{ + tokenType: tokenType, + value: string(value)} + return token, err + } + default: + { + state = quotingEscapingState + value = append(value, nextRune) + } + } + } + case quotingEscapingState: // in escaping double quotes + { + switch nextRuneType { + case eofRuneClass: + { + err = fmt.Errorf("EOF found when expecting closing quote") + token := &Token{ + tokenType: tokenType, + value: string(value)} + return token, err + } + case escapingQuoteRuneClass: + { + state = inWordState + } + case escapeRuneClass: + { + state = escapingQuotedState + } + default: + { + value = append(value, nextRune) + } + } + } + case quotingState: // in non-escaping single quotes + { + switch nextRuneType { + case eofRuneClass: + { + err = fmt.Errorf("EOF found when expecting closing quote") + token := &Token{ + tokenType: tokenType, + value: string(value)} + return token, err + } + case nonEscapingQuoteRuneClass: + { + state = inWordState + } + default: + { + value = append(value, nextRune) + } + } + } + case commentState: // in a comment + { + switch nextRuneType { + case eofRuneClass: + { + token := &Token{ + tokenType: tokenType, + value: string(value)} + return token, err + } + case spaceRuneClass: + { + if nextRune == '\n' { + state = startState + token := &Token{ + tokenType: tokenType, + value: string(value)} + return token, err + } else { + value = append(value, nextRune) + } + } + default: + { + value = append(value, nextRune) + } + } + } + default: + { + return nil, fmt.Errorf("Unexpected state: %v", state) + } + } + } +} + +// Next returns the next token in the stream. +func (t *Tokenizer) Next() (*Token, error) { + return t.scanStream() +} + +// Split partitions a string into a slice of strings. +func Split(s string) ([]string, error) { + l := NewLexer(strings.NewReader(s)) + subStrings := make([]string, 0) + for { + word, err := l.Next() + if err != nil { + if err == io.EOF { + return subStrings, nil + } + return subStrings, err + } + subStrings = append(subStrings, word) + } +} diff --git a/worker/oci/spec_unix.go b/worker/oci/spec_unix.go index 5d93ec54..03d6af66 100644 --- a/worker/oci/spec_unix.go +++ b/worker/oci/spec_unix.go @@ -13,7 +13,7 @@ import ( // Ideally we don't have to import whole containerd just for the default spec func GenerateSpec(ctx context.Context, meta worker.Meta, mounts map[string]cache.Mountable) (*specs.Spec, error) { - s, err := containerd.GenerateSpec() + s, err := containerd.GenerateSpec(containerd.WithHostNamespace(specs.NetworkNamespace)) if err != nil { return nil, err }