detect reference on cue conjunction

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-05-21 17:38:33 -07:00
parent 7484df45cd
commit 6b73de7ea3

View File

@ -3,14 +3,16 @@ package dagger
import (
"context"
"cuelang.org/go/cue"
"dagger.io/go/dagger/compiler"
"github.com/rs/zerolog/log"
)
func isReference(val *compiler.Value) bool {
_, ref := val.ReferencePath()
func isReference(val cue.Value) bool {
isRef := func(v cue.Value) bool {
_, ref := v.ReferencePath()
if ref.String() == "" || val.Path().String() == ref.String() {
if ref.String() == "" || v.Path().String() == ref.String() {
// not a reference
return false
}
@ -23,6 +25,21 @@ func isReference(val *compiler.Value) bool {
}
return true
}
op, vals := val.Expr()
if op == cue.NoOp {
return isRef(val)
}
for _, v := range vals {
// if the expr has an op (& or |, etc...), check the expr values, recursively
if isReference(v) {
return true
}
}
return isRef(val)
}
func ScanInputs(ctx context.Context, value *compiler.Value) []*compiler.Value {
@ -31,7 +48,7 @@ func ScanInputs(ctx context.Context, value *compiler.Value) []*compiler.Value {
value.Walk(
func(val *compiler.Value) bool {
if isReference(val) {
if isReference(val.Cue()) {
lg.Debug().Str("value.Path", val.Path().String()).Msg("found reference, stop walk")
return false
}