Skip to content

Commit a94d22f

Browse files
committed
cue/load: clarify the docs for Config.ModuleRoot
The previous docs were a bit unclear and outdated; they still referred to the old cue.mod file, and it wasn't particularly clear whether ModuleRoot was the cue.mod directory itself or its parent directory. The behavior when the field was left empty was also not documented. While here, point to cue/load from the cue API as it may otherwise not be clear why APIs like Context.CompileString are not able to load imports from dependencies declared in cue.mod/module.cue. Fixes #1380. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I73f851f5ca7a2be0b3165f64de7dd369faad6887 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196662 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Aram Hăvărneanu <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent fecf80d commit a94d22f

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

cue/context.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ import (
3434
// representations of values, and defines the set of supported builtins. Any
3535
// operation that involves two Values should originate from the same Context.
3636
//
37-
// Use
38-
//
39-
// ctx := cuecontext.New()
40-
//
41-
// to create a new Context.
37+
// Use [cuelang.org/go/cue/cuecontext.New] to create a new context.
4238
type Context runtime.Runtime
4339

4440
func (c *Context) runtime() *runtime.Runtime {

cue/cue.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
// Values created from the same Context are not safe for concurrent use,
2121
// which we intend to change in the future.
2222
//
23-
// A Context defines the set of active packages, the translations of field
24-
// names to unique codes, as well as the set of builtins. Use
23+
// [Context] defines the set of active packages, the translations of field
24+
// names to unique codes, as well as the set of builtins.
25+
// Use [cuelang.org/go/cue/cuecontext.New] to create a new context.
2526
//
26-
// import "cuelang.org/go/cue/cuecontext"
27-
//
28-
// ctx := cuecontext.New()
29-
//
30-
// to obtain a context.
27+
// While a context can be used to build values, note that loading a module and its
28+
// dependencies should be done with the [cuelang.org/go/cue/load] package.
3129
//
3230
// Note that the following types are DEPRECATED and their usage should be
3331
// avoided if possible:

cue/load/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ type Config struct {
128128
// Context specifies the context for the load operation.
129129
Context *build.Context
130130

131-
// A Module is a collection of packages and instances that are within the
132-
// directory hierarchy rooted at the module root. The module root can be
133-
// marked with a cue.mod file.
134-
// If this is a relative path, it will be interpreted relative to [Config.Dir].
131+
// ModuleRoot is the directory that contains the cue.mod directory
132+
// as well as all the packages which form part of the module being loaded.
133+
//
134+
// If left as the empty string, a module root is found by walking parent directories
135+
// starting from [Config.Dir] until one is found containing a cue.mod directory.
136+
// If it is a relative path, it will be interpreted relative to [Config.Dir].
135137
ModuleRoot string
136138

137139
// Module specifies the module prefix. If not empty, this value must match

0 commit comments

Comments
 (0)