dagger.Value: make compiler instance private

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-01-20 16:13:33 -08:00
parent 425bbace9e
commit 41515c931e
2 changed files with 5 additions and 10 deletions

View File

@ -158,7 +158,7 @@ func (c *Client) Compute(ctx context.Context) (*Value, error) {
// Retrieve output // Retrieve output
eg.Go(func() error { eg.Go(func() error {
defer outr.Close() defer outr.Close()
return c.outputfn(ctx, outr, out) return c.outputfn(ctx, outr, out, cc)
}) })
return out, eg.Wait() return out, eg.Wait()
} }
@ -218,7 +218,7 @@ func (c *Client) buildfn(ctx context.Context, ch chan *bk.SolveStatus, w io.Writ
} }
// Read tar export stream from buildkit Build(), and extract cue output // Read tar export stream from buildkit Build(), and extract cue output
func (c *Client) outputfn(ctx context.Context, r io.Reader, out *Value) error { func (c *Client) outputfn(ctx context.Context, r io.Reader, out *Value, cc *Compiler) error {
lg := log.Ctx(ctx) lg := log.Ctx(ctx)
tr := tar.NewReader(r) tr := tar.NewReader(r)
@ -242,7 +242,6 @@ func (c *Client) outputfn(ctx context.Context, r io.Reader, out *Value) error {
} }
lg.Debug().Msg("outputfn: compiling & merging") lg.Debug().Msg("outputfn: compiling & merging")
cc := out.Compiler()
v, err := cc.Compile(h.Name, tr) v, err := cc.Compile(h.Name, tr)
if err != nil { if err != nil {
return err return err

View File

@ -21,10 +21,6 @@ func (v *Value) CueInst() *cue.Instance {
return v.inst return v.inst
} }
func (v *Value) Compiler() *Compiler {
return v.cc
}
func (v *Value) Wrap(v2 cue.Value) *Value { func (v *Value) Wrap(v2 cue.Value) *Value {
return wrapValue(v2, v.inst, v.cc) return wrapValue(v2, v.inst, v.cc)
} }
@ -142,7 +138,7 @@ func (v *Value) RangeStruct(fn func(string, *Value) error) error {
// FIXME: receive string path? // FIXME: receive string path?
func (v *Value) Merge(x interface{}, path ...string) (*Value, error) { func (v *Value) Merge(x interface{}, path ...string) (*Value, error) {
if xval, ok := x.(*Value); ok { if xval, ok := x.(*Value); ok {
if xval.Compiler() != v.Compiler() { if xval.cc != v.cc {
return nil, fmt.Errorf("can't merge values from different compilers") return nil, fmt.Errorf("can't merge values from different compilers")
} }
x = xval.val x = xval.val
@ -242,7 +238,7 @@ func (v *Value) Validate(defs ...string) error {
if len(defs) == 0 { if len(defs) == 0 {
return nil return nil
} }
spec := v.Compiler().Spec() spec := v.cc.Spec()
for _, def := range defs { for _, def := range defs {
if err := spec.Validate(v, def); err != nil { if err := spec.Validate(v, def); err != nil {
return err return err
@ -321,7 +317,7 @@ func (v *Value) ScriptOrComponent() (interface{}, error) {
func (v *Value) Op() (*Op, error) { func (v *Value) Op() (*Op, error) {
// Merge #Op definition from spec to get default values // Merge #Op definition from spec to get default values
spec := v.Compiler().Spec() spec := v.cc.Spec()
v, err := spec.Get("#Op").Merge(v) v, err := spec.Get("#Op").Merge(v)
if err != nil { if err != nil {
return nil, err return nil, err