Documentation ¶
Overview ¶
Package build defines data types and utilities for defining CUE configuration instances.
This package enforces the rules regarding packages and instances as defined in the spec, but it leaves any other details, as well as handling of modules, up to the implementation.
A full implementation of instance loading can be found in the loader package.
WARNING: this packages may change. It is fine to use load and cue, who both use this package.
Package build defines collections of CUE files to build an instance.
Index ¶
- func IsLocalImport(path string) bool
- type Context
- type Instance
- func (inst *Instance) Abs(path string) string
- func (inst *Instance) AddFile(filename string, src interface{}) error
- func (inst *Instance) AddSyntax(file *ast.File) errors.Error
- func (inst *Instance) Complete() error
- func (inst *Instance) Context() *Context
- func (inst *Instance) Dependencies() []*Instance
- func (inst *Instance) LookupImport(path string) *Instance
- func (inst *Instance) ReportError(err errors.Error)
- type LoadFunc
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsLocalImport ¶
IsLocalImport reports whether the import path is a local import path, like ".", "..", "./foo", or "../foo".
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
A Context keeps track of state of building instances and caches work.
func NewContext ¶
NewContext creates a new build context.
All instances must be created with a context.
type Instance ¶
type Instance struct { // Files contains the AST for all files part of this instance. Files []*ast.File // Scope is another instance that may be used to resolve any unresolved // reference of this instance. For instance, tool and test instances // may refer to top-level fields in their package scope. Scope *Instance // PkgName is the name specified in the package clause. PkgName string // ImportPath returns the unique path to identify an imported instance. // // Instances created with NewInstance do not have an import path. ImportPath string // Imports lists the instances of all direct imports of this instance. Imports []*Instance // The Err for loading this package or nil on success. This does not // include any errors of dependencies. Incomplete will be set if there // were any errors in dependencies. Err errors.Error // Incomplete reports whether any dependencies had an error. Incomplete bool // ImportComment is the path in the import comment on the package statement. ImportComment string // DisplayPath is a user-friendly version of the package or import path. DisplayPath string // Dir is the package directory. Note that a package may also include files // from ancestor directories, up to the module file. Dir string // Module defines the module name of a package. It must be defined if // the packages within the directory structure of the module are to be // imported by other packages, including those within the module. Module string // Root is the root of the directory hierarchy, it may be "" if this an // instance has no imports. // If Module != "", this corresponds to the module root. // Root/pkg is the directory that holds third-party packages. Root string // root directory of hierarchy ("" if unknown) // AllTags are the build tags that can influence file selection in this // directory. AllTags []string Standard bool // Is a builtin package Local bool // Relative to Dir CUEFiles []string // .cue source files DataFiles []string // recognized data files (.json, .yaml, etc.) TestCUEFiles []string // .cue test files (_test.cue) ToolCUEFiles []string // .cue tool files (_tool.cue) IgnoredCUEFiles []string // .cue source files ignored for this build InvalidCUEFiles []string // .cue source files with detected problems (parse error, wrong package name, and so on) // Dependencies ImportPaths []string ImportPos map[string][]token.Pos // line information for Imports Deps []string DepsErrors []error Match []string // contains filtered or unexported fields }
An Instance describes the collection of files, and its imports, necessary to build a CUE instance.
A typical way to create an Instance is to use the loader package.
func (*Instance) Abs ¶
Abs converts relative path used in the one of the file fields to an absolute one.
func (*Instance) AddFile ¶
AddFile adds the file with the given name to the list of files for this instance. The file may be loaded from the cache of the instance's context. It does not process the file's imports. The package name of the file must match the package name of the instance.
func (*Instance) AddSyntax ¶ added in v0.0.5
AddSyntax adds the given file to list of files for this instance. The package name of the file must match the package name of the instance.
func (*Instance) Complete ¶
Complete finishes the initialization of an instance. All files must have been added with AddFile before this call.
func (*Instance) Context ¶
Context defines the build context for this instance. All files defined in Syntax as well as all imported instances must be created using the same build context.
func (*Instance) Dependencies ¶ added in v0.0.6
Dependencies reports all Instances on which this instance depends.
func (*Instance) LookupImport ¶
LookupImport defines a mapping from an ImportSpec's ImportPath to Instance.
func (*Instance) ReportError ¶
ReportError reports an error processing this instance.