From b5e2ba63c632eefbfa767e5bdf716c4af87ffbc7 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Wed, 24 Nov 2021 16:08:40 -0800 Subject: [PATCH] runner: fix empty CUE value check Signed-off-by: Andrea Luzzardi --- cmd/dagger/cmd/common/common.go | 5 +++-- compiler/value.go | 22 +++++++++------------- environment/environment.go | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/cmd/dagger/cmd/common/common.go b/cmd/dagger/cmd/common/common.go index 9d4e1997..c9955894 100644 --- a/cmd/dagger/cmd/common/common.go +++ b/cmd/dagger/cmd/common/common.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" + "cuelang.org/go/cue" "github.com/docker/buildx/util/buildflags" "github.com/rs/zerolog/log" "github.com/spf13/viper" @@ -91,9 +92,9 @@ func FormatValue(val *compiler.Value) string { return "dagger.#Secret" } if val.IsConcreteR() != nil { - return val.IncompleteKindString() + return val.IncompleteKind().String() } - if val.IncompleteKindString() == "struct" { + if val.IncompleteKind() == cue.StructKind { return "struct" } diff --git a/compiler/value.go b/compiler/value.go index 167f3861..cfcddbc0 100644 --- a/compiler/value.go +++ b/compiler/value.go @@ -59,6 +59,11 @@ func (v *Value) Kind() cue.Kind { return v.val.Kind() } +// Proxy function to the underlying cue.Value +func (v *Value) IncompleteKind() cue.Kind { + return v.Cue().IncompleteKind() +} + // Field represents a struct field type Field struct { Selector cue.Selector @@ -145,6 +150,10 @@ func (v *Value) List() ([]*Value, error) { return l, nil } +func (v *Value) IsConcrete() bool { + return v.val.IsConcrete() +} + // Recursive concreteness check. func (v *Value) IsConcreteR(opts ...cue.Option) error { o := []cue.Option{cue.Concrete(true)} @@ -220,15 +229,6 @@ func (v *Value) Source(opts ...cue.Option) ([]byte, error) { ) } -func (v *Value) IsEmptyStruct() bool { - if st, err := v.Struct(); err == nil { - if st.Len() == 0 { - return true - } - } - return false -} - func (v *Value) Cue() cue.Value { return v.val } @@ -275,7 +275,3 @@ func (v *Value) Default() (*Value, bool) { func (v *Value) Doc() []*ast.CommentGroup { return v.Cue().Doc() } - -func (v *Value) IncompleteKindString() string { - return v.Cue().IncompleteKind().String() -} diff --git a/environment/environment.go b/environment/environment.go index cd290b54..d74d30e4 100644 --- a/environment/environment.go +++ b/environment/environment.go @@ -155,7 +155,7 @@ func NewPipelineRunner(computed *compiler.Value, s solver.Solver, pctx *plancont } // Mirror the computed values in both `Task` and `Result` - if p.Computed().IsEmptyStruct() { + if !p.Computed().IsConcrete() { return nil }