loader

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package loader loads Go packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlazeLoader

type BlazeLoader struct {
	// contains filtered or unexported fields
}

func NewBlazeLoader

func NewBlazeLoader(ctx context.Context, cfg *Config, dir string) (*BlazeLoader, error)

func (*BlazeLoader) Close

func (l *BlazeLoader) Close(context.Context) error

Close frees all resources that NewBlazeLoader() created. The BlazeLoader must not be used afterwards.

func (*BlazeLoader) LoadPackages

func (l *BlazeLoader) LoadPackages(ctx context.Context, targets []*Target, res chan LoadResult)

LoadPackage loads a batch of Go packages.

type Config

type Config struct {
}

Config configures the loader.

type File

type File struct {
	// Parsed file.
	AST *ast.File

	Path string

	// For go_test targets, this field indicates whether the file belongs to the
	// test code itself (one or more _test.go files), or whether the file
	// belongs to the package-under-test (via the go_test target’s library
	// attribute).
	//
	// For other targets (go_binary or go_library), this field is always false.
	LibraryUnderTest bool

	// Source code from the file.
	Code string

	// True if the file was generated (go_embed_data, genrule, etc.).
	Generated bool
}

File represents a single file in a loaded package.

type LoadResult

type LoadResult struct {
	Target  *Target
	Package *Package
	Err     error
}

LoadResult represents the result of loading an individual target. The Target field is always set. If something went wrong, Err is non-nil and Package is nil. Otherwise, Err is nil and Package is non-nil.

type Loader

type Loader interface {
	// LoadPackages loads a batch of Go packages.
	//
	// The method does not return a slice of results, but instead writes each
	// result to the specified result channel as the result arrives. This allows
	// for concurrency with loaders that support it, like the Compilations
	// Bigtable loader (processing results while the load is still ongoing).
	LoadPackages(context.Context, []*Target, chan LoadResult)
	Close(context.Context) error
}

Loader loads Go packages.

type Package

type Package struct {
	Files    []*File        // Files in the package.
	Fileset  *token.FileSet // For translating between positions and locations in files.
	TypeInfo *types.Info    // Type information for the package (e.g. object identity, identifier uses/declarations, expression types).
	TypePkg  *types.Package // Describes the package (e.g. import objects, package scope).
}

Package represents a loaded Go package.

func LoadOne

func LoadOne(ctx context.Context, l Loader, t *Target) (*Package, error)

LoadOne is a convenience function that loads precisely one target, saving the caller the mechanics of having to work with a batch of targets.

func (Package) String

func (p Package) String() string

type Target

type Target struct {
	// ID is an opaque identifier for the package when using the packages loader.
	ID string

	// Testonly indicates that this package should be considered test code. This
	// attribute needs to be passed in because go/packages does not have the
	// concept of test only code, only Blaze does.
	Testonly bool

	LibrarySrcs map[string]bool
}

Target represents a package to be loaded. It is identified by the opaque ID field, which is interpreted by the loader (which, in turn, delegates to the gopackagesdriver).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL