Documentation
¶
Index ¶
- Constants
- func Visit(pkgs []*Package, pre func(*Package) bool, post func(*Package))
- type Cached
- type Config
- type Deduper
- func (p Deduper) Check(id string) *Cached
- func (p Deduper) IsExported(id string) bool
- func (p Deduper) SetImportTypes(fn func(*Package, *token.FileSet) bool)
- func (p Deduper) SetLLGoFiles(files map[string][]string)
- func (p Deduper) SetPkgPath(fn func(path, name string) string)
- func (p Deduper) SetPreload(fn func(pkg *packages.Package))
- func (p Deduper) SetPrepare(fn func([]*Package, *Config) error)
- func (p Deduper) SetRewrite(fn func(*Package) (bool, error))
- type Error
- type LoadMode
- type Package
Constants ¶
const ( NeedName = packages.NeedName NeedFiles = packages.NeedFiles NeedSyntax = packages.NeedSyntax NeedImports = packages.NeedImports NeedDeps = packages.NeedDeps NeedModule = packages.NeedModule NeedExportFile = packages.NeedExportFile NeedEmbedFiles = packages.NeedEmbedFiles NeedEmbedPatterns = packages.NeedEmbedPatterns NeedCompiledGoFiles = packages.NeedCompiledGoFiles NeedTypes = packages.NeedTypes NeedTypesSizes = packages.NeedTypesSizes NeedTypesInfo = packages.NeedTypesInfo NeedForTest = packages.NeedForTest )
const (
DebugPackagesLoad = false
)
Variables ¶
This section is empty.
Functions ¶
func Visit ¶
Visit visits all the packages in the import graph whose roots are pkgs, calling the optional pre function the first time each package is encountered (preorder), and the optional post function after a package's dependencies have been visited (postorder). The boolean result of pre(pkg) determines whether the imports of package pkg are visited.
Types ¶
type Config ¶
A Config specifies details about how packages should be loaded. The zero value is a valid configuration. Calls to Load do not modify this struct.
type Deduper ¶
type Deduper = *aDeduper
func NewDeduper ¶
func NewDeduper() Deduper
func (Deduper) IsExported ¶ added in v1.0.10
func (Deduper) SetImportTypes ¶ added in v1.0.10
SetImportTypes installs a validated dependency type-export reader. Syntax is still parsed for compiler directives; a true result replaces type checking.
func (Deduper) SetLLGoFiles ¶
func (Deduper) SetPkgPath ¶
func (Deduper) SetPreload ¶
func (Deduper) SetPrepare ¶ added in v1.0.5
SetPrepare installs a graph preprocessing hook before parsing/type checking. The hook may add generated files and their imports (for example, coverage).
func (Deduper) SetRewrite ¶ added in v1.0.7
SetRewrite installs a typed source transformation. It runs after the initial check, before importing packages are checked. A changed package is checked again with fresh types and binding information; preload runs for that new package as well. The callback must add metadata for any injected imports.
type LoadMode ¶
A LoadMode controls the amount of detail to return when loading. The bits below can be combined to specify which fields should be filled in the result packages. The zero value is a special case, equivalent to combining the NeedName, NeedFiles, and NeedCompiledGoFiles bits. ID and Errors (if present) will always be filled. Load may return more information than requested.
type Package ¶
A Package describes a loaded Go package.
func LoadEx ¶
func LoadEx(dedup Deduper, sizes func(sizes types.Sizes, compiler, arch string) types.Sizes, cfg *Config, patterns ...string) ([]*Package, error)
LoadEx loads and returns the Go packages named by the given patterns.
Config specifies loading options; nil behaves the same as an empty Config.
If any of the patterns was invalid as defined by the underlying build system, Load returns an error. It may return an empty list of packages without an error, for instance for an empty expansion of a valid wildcard. Errors associated with a particular package are recorded in the corresponding Package's Errors list, and do not cause Load to return an error. Clients may need to handle such errors before proceeding with further analysis. The PrintErrors function is provided for convenient display of all errors.
func LoadExWithGoVersion ¶
func LoadExWithGoVersion(dedup Deduper, sizes func(sizes types.Sizes, compiler, arch string) types.Sizes, cfg *Config, goVersion string, patterns ...string) ([]*Package, error)
LoadExWithGoVersion is LoadEx with an optional go/types language version override. The version uses go/types syntax, such as "go1.22".
func LoadExWithSourceOverlay ¶ added in v1.0.7
func LoadExWithSourceOverlay(dedup Deduper, sizes func(sizes types.Sizes, compiler, arch string) types.Sizes, cfg *Config, goVersion string, sourceOverlay map[string][]byte, patterns ...string) ([]*Package, error)
LoadExWithSourceOverlay supplies an additional source view to LLGo's parser without changing the metadata driver's overlay. This lets a Go -overlay JSON select deleted and added files while native source patches and virtual files reach the parser without generating a conflicting go/packages overlay.
func LoadMetadata ¶ added in v1.0.7
LoadMetadata runs the unmodified go/packages driver with the selected GOROOT/bin first on its process PATH. Setting Config.Env alone cannot do this: x/tools resolves exec.Command("go") using the process environment, including for GO111MODULE=off release-tag probes. The parent's environment is untouched. This loader is for metadata only; LoadEx supplies LLGo's parser and typechecker.