Documentation
¶
Overview ¶
Package gomod reads and edits the XGo-specific parts of a go.mod file.
XGo stores two kinds of extra information in go.mod, both as trailing comments so that the file stays valid for the go command.
A class module marker on a require line tells XGo to load the classfile projects declared by that dependency, for example:
require github.com/goplus/yap v0.8.0 //xgo:class
The legacy //gop:class marker is also recognized. See IsClass and File.AddRequire.
A custom compiler is recorded on the go directive, for example:
go 1.18 // llgo 0.9
See Compiler and File.AddCompiler.
File wraps a golang.org/x/mod/modfile.File to create, load, edit and save a go.mod with these markers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compiler ¶
Compiler reads a trailing comment on the go directive that names a custom compiler, for example:
go 1.18 // llgo 0.9 go 1.18 // tinygo 0.32
Leading whitespace after "//" is ignored and the version is trimmed. The first matching comment wins. It returns nil if there is none, or if f has no go directive.
func IsClass ¶
IsClass reports whether a require is marked as a class module by a trailing //xgo:class (or the legacy //gop:class) comment. The marker is matched after leading whitespace is trimmed, as a prefix, so "// xgo:class" is accepted too. A require without syntax information is never a class module.
Types ¶
type File ¶
File wraps a modfile.File and provides higher-level operations for editing go.mod. File is a small value type; copies share the same underlying modfile.File, so edits made through any copy are visible to all of them.
func Create ¶
Create creates a new, in-memory go.mod for module modPath with a go directive of goVer. gomod is the file name used later by File.Save; nothing is written to disk until then. It fails if goVer is not a valid Go version; modPath is not validated.
func Load ¶
Load reads and parses the go.mod at the given path. The path is remembered so that File.Save writes back to the same file.
func (File) AddCompiler ¶
AddCompiler records a compiler directive (llgo/tinygo) as a comment on the go directive in go.mod, the way the XGo toolchain reads it (see Compiler). For example, AddCompiler("llgo", "0.9") produces "go 1.18 // llgo 0.9". If there is no go directive, one with the default Go version is added first. Any existing trailing comment on the go directive is replaced.
func (File) AddRequire ¶
AddRequire adds a require line for path at version vers, or updates the version if path is already required. When hasProj is set (the dependency declares classfile projects), the require is also marked as a class module with a trailing //xgo:class comment, unless it is already marked (see IsClass). An existing marker is kept even when hasProj is false.