diff --git a/dagger/environment.go b/dagger/environment.go index 93e4cf7a..8e690c4c 100644 --- a/dagger/environment.go +++ b/dagger/environment.go @@ -10,7 +10,6 @@ import ( "cuelang.org/go/cue" cueflow "cuelang.org/go/tools/flow" "dagger.io/go/dagger/compiler" - "dagger.io/go/pkg/cuetils" "dagger.io/go/stdlib" "github.com/opentracing/opentracing-go" @@ -297,8 +296,8 @@ func newPipelineRunner(computed *compiler.Value, s Solver) cueflow.RunnerFunc { }) } -func (e *Environment) ScanInputs() ([]cue.Value, error) { - vals, err := cuetils.ScanForInputs(e.plan.Cue()) +func (e *Environment) ScanInputs() ([]*compiler.Value, error) { + vals, err := ScanInputs(e.plan) if err != nil { return nil, err } diff --git a/dagger/inputs_scan.go b/dagger/inputs_scan.go new file mode 100644 index 00000000..a7f7ca43 --- /dev/null +++ b/dagger/inputs_scan.go @@ -0,0 +1,82 @@ +package dagger + +import ( + "fmt" + + "cuelang.org/go/cue" + "dagger.io/go/dagger/compiler" +) + +// func isReference(val cue.Value) bool { +// _, ref := val.ReferencePath() +// isRef := len(ref.Selectors()) > 0 + +// if isRef { +// return true +// } + +// _, vals := val.Expr() +// for _, v := range vals { +// // walk recursively +// if v.Path().String() == val.Path().String() { +// // avoid loop by checking the same value +// continue +// } +// return isReference(v) +// } + +// return isRef +// } + +// walk recursively to find references +// func isReference(val cue.Value) bool { +// _, vals := val.Expr() +// for _, v := range vals { +// // walk recursively +// if v.Path().String() == val.Path().String() { +// // avoid loop by checking the same value +// continue +// } +// return isReference(v) +// } + +// _, ref := val.ReferencePath() +// return len(ref.Selectors()) > 0 +// } + +func isReference(val cue.Value) bool { + checkRef := func(vv cue.Value) bool { + _, ref := vv.ReferencePath() + return len(ref.Selectors()) > 0 + } + + _, vals := val.Expr() + for _, v := range vals { + if checkRef(v) { + return true + } + } + + return checkRef(val) +} + +func ScanInputs(value *compiler.Value) ([]*compiler.Value, error) { + vals := []*compiler.Value{} + + value.Walk( + func(val *compiler.Value) bool { + // if isReference(val.Cue()) { + // fmt.Println("### isReference ->", val.Cue().Path()) + // return false + // } + + if val.HasAttr("input") && !isReference(val.Cue()) { + fmt.Printf("#### FOUND: %s\n", val.Path()) + vals = append(vals, val) + } + return true + }, nil, + ) + + return vals, nil +}