runner: fix empty CUE value check

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-11-24 16:08:40 -08:00
parent b92905e175
commit b5e2ba63c6
3 changed files with 13 additions and 16 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"cuelang.org/go/cue"
"github.com/docker/buildx/util/buildflags" "github.com/docker/buildx/util/buildflags"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -91,9 +92,9 @@ func FormatValue(val *compiler.Value) string {
return "dagger.#Secret" return "dagger.#Secret"
} }
if val.IsConcreteR() != nil { if val.IsConcreteR() != nil {
return val.IncompleteKindString() return val.IncompleteKind().String()
} }
if val.IncompleteKindString() == "struct" { if val.IncompleteKind() == cue.StructKind {
return "struct" return "struct"
} }

View File

@ -59,6 +59,11 @@ func (v *Value) Kind() cue.Kind {
return v.val.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 // Field represents a struct field
type Field struct { type Field struct {
Selector cue.Selector Selector cue.Selector
@ -145,6 +150,10 @@ func (v *Value) List() ([]*Value, error) {
return l, nil return l, nil
} }
func (v *Value) IsConcrete() bool {
return v.val.IsConcrete()
}
// Recursive concreteness check. // Recursive concreteness check.
func (v *Value) IsConcreteR(opts ...cue.Option) error { func (v *Value) IsConcreteR(opts ...cue.Option) error {
o := []cue.Option{cue.Concrete(true)} 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 { func (v *Value) Cue() cue.Value {
return v.val return v.val
} }
@ -275,7 +275,3 @@ func (v *Value) Default() (*Value, bool) {
func (v *Value) Doc() []*ast.CommentGroup { func (v *Value) Doc() []*ast.CommentGroup {
return v.Cue().Doc() return v.Cue().Doc()
} }
func (v *Value) IncompleteKindString() string {
return v.Cue().IncompleteKind().String()
}

View File

@ -155,7 +155,7 @@ func NewPipelineRunner(computed *compiler.Value, s solver.Solver, pctx *plancont
} }
// Mirror the computed values in both `Task` and `Result` // Mirror the computed values in both `Task` and `Result`
if p.Computed().IsEmptyStruct() { if !p.Computed().IsConcrete() {
return nil return nil
} }