From a8b41c06b77823438373309bce01cbceb7327468 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Wed, 31 Mar 2021 13:14:36 -0700 Subject: [PATCH] cue: Use FillPath everywhere since Fill is now deprecated Signed-off-by: Andrea Luzzardi --- dagger/client.go | 3 ++- dagger/compiler/value.go | 34 +++++----------------------------- dagger/deployment.go | 7 +++---- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/dagger/client.go b/dagger/client.go index 265ecffb..c18e3cd5 100644 --- a/dagger/client.go +++ b/dagger/client.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" + "cuelang.org/go/cue" "golang.org/x/sync/errgroup" "github.com/opentracing/opentracing-go" @@ -206,7 +207,7 @@ func (c *Client) outputfn(ctx context.Context, r io.Reader) (*compiler.Value, er if err != nil { return nil, err } - if err := out.Fill(v); err != nil { + if err := out.FillPath(cue.MakePath(), v); err != nil { return nil, fmt.Errorf("%s: %w", h.Name, err) } } diff --git a/dagger/compiler/value.go b/dagger/compiler/value.go index d0ee9477..0b3626e5 100644 --- a/dagger/compiler/value.go +++ b/dagger/compiler/value.go @@ -31,19 +31,19 @@ func wrapValue(v cue.Value, inst *cue.Instance, cc *Compiler) *Value { } } -// Fill the value in-place, unlike Merge which returns a copy. -func (v *Value) Fill(x interface{}) error { +// FillPath fills the value in-place +func (v *Value) FillPath(p cue.Path, x interface{}) error { v.cc.lock() defer v.cc.unlock() // If calling Fill() with a Value, we want to use the underlying // cue.Value to fill. if val, ok := x.(*Value); ok { - v.val = v.val.Fill(val.val) + v.val = v.val.FillPath(p, val.val) } else { - v.val = v.val.Fill(x) + v.val = v.val.FillPath(p, x) } - return v.Validate() + return v.val.Err() } // LookupPath is a concurrency safe wrapper around cue.Value.LookupPath @@ -146,30 +146,6 @@ func (v *Value) List() ([]*Value, error) { return l, nil } -// FIXME: receive string path? -func (v *Value) Merge(x interface{}, path ...string) (*Value, error) { - if xval, ok := x.(*Value); ok { - x = xval.val - } - - v.cc.lock() - result := v.Wrap(v.val.Fill(x, path...)) - v.cc.unlock() - - return result, result.Validate() -} - -func (v *Value) MergePath(x interface{}, p cue.Path) (*Value, error) { - // FIXME: array indexes and defs are not supported, - // they will be silently converted to regular fields. - // eg. `foo.#bar[0]` will become `foo["#bar"]["0"]` - return v.Merge(x, cuePathToStrings(p)...) -} - -func (v *Value) MergeTarget(x interface{}, target string) (*Value, error) { - return v.MergePath(x, cue.ParsePath(target)) -} - // Recursive concreteness check. func (v *Value) IsConcreteR() error { return v.val.Validate(cue.Concrete(true)) diff --git a/dagger/deployment.go b/dagger/deployment.go index e813d3a6..24a09d61 100644 --- a/dagger/deployment.go +++ b/dagger/deployment.go @@ -93,9 +93,9 @@ func NewDeployment(st *DeploymentState) (*Deployment, error) { return nil, err } if input.Key == "" { - d.input, err = d.input.Merge(v) + err = d.input.FillPath(cue.MakePath(), v) } else { - d.input, err = d.input.MergeTarget(v, input.Key) + err = d.input.FillPath(cue.ParsePath(input.Key), v) } if err != nil { return nil, err @@ -277,8 +277,7 @@ func (d *Deployment) Up(ctx context.Context, s Solver, _ *UpOpts) error { return nil } // Merge task value into output - var err error - d.output, err = d.output.MergePath(t.Value(), t.Path()) + err := d.output.FillPath(t.Path(), t.Value()) if err != nil { lg. Error().