this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/load: use cue package to interpret module.cue file

Since cue/load already depends on the CUE package, it
seems better and easier to depend on the public API
rather than the internal API, making the code a little
easier to understand and more amenable to changes
that make the schema more complex.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I113c0b17aad41fa7639fb6bf27674cbfe1149755
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/549000
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>

+12 -17
+12 -17
cue/load/config.go
··· 22 22 "path/filepath" 23 23 "strings" 24 24 25 + "cuelang.org/go/cue" 25 26 "cuelang.org/go/cue/ast" 26 27 "cuelang.org/go/cue/build" 27 28 "cuelang.org/go/cue/errors" 28 29 "cuelang.org/go/cue/parser" 29 30 "cuelang.org/go/cue/token" 30 31 "cuelang.org/go/internal" 31 - "cuelang.org/go/internal/core/compile" 32 - "cuelang.org/go/internal/core/eval" 33 32 "cuelang.org/go/internal/core/runtime" 34 33 ) 35 34 ··· 562 561 if err != nil { 563 562 return errors.Wrapf(err, token.NoPos, "invalid cue.mod file") 564 563 } 564 + // TODO disallow non-data-mode CUE. 565 565 566 - r := runtime.New() 567 - v, err := compile.Files(nil, r, "_", file) 568 - if err != nil { 566 + ctx := (*cue.Context)(runtime.New()) 567 + v := ctx.BuildFile(file) 568 + if err := v.Validate(); err != nil { 569 569 return errors.Wrapf(err, token.NoPos, "invalid cue.mod file") 570 570 } 571 - ctx := eval.NewContext(r, v) 572 - v.Finalize(ctx) 573 - prefix := v.Lookup(ctx.StringLabel("module")) 574 - if prefix == nil { 571 + prefix := v.LookupPath(cue.MakePath(cue.Str("module"))) 572 + if prefix.Err() != nil { 573 + // TODO check better for not-found? 575 574 return nil 576 575 } 577 - name := ctx.StringValue(prefix.Value()) 578 - if err := ctx.Err(); err != nil { 579 - return err.Err 576 + name, err := prefix.String() 577 + if err != nil { 578 + return err 580 579 } 581 580 if c.Module == "" { 582 581 c.Module = name ··· 585 584 if c.Module == name { 586 585 return nil 587 586 } 588 - pos := token.NoPos 589 - if src := prefix.Value().Source(); src != nil { 590 - pos = src.Pos() 591 - } 592 - return errors.Newf(pos, "inconsistent modules: got %q, want %q", name, c.Module) 587 + return errors.Newf(prefix.Pos(), "inconsistent modules: got %q, want %q", name, c.Module) 593 588 } 594 589 595 590 func (c Config) isRoot(dir string) bool {