func FindExportData(r *bufio.Reader) (hdr string, size int64, err error)
FindExportData positions the reader r at the beginning of the export data section of an underlying GC-created object/archive file by reading from it. The reader must be positioned at the start of the file before calling this function. The hdr result is the string before the export data, either "$$" or "$$B". The size result is the length of the export data in bytes, or -1 if not known.
func FindPkg(path, srcDir string) (filename, id string)
FindPkg returns the filename and unique package id for an import path based on package information provided by build.Import (using the build.Default build.Context). A relative srcDir is interpreted relative to the current working directory. If no file was found, an empty filename is returned.
func IExportBundle(out io.Writer, fset *token.FileSet, pkgs []*types.Package) error
IExportBundle writes an indexed export bundle for pkgs to out.
func IExportData(out io.Writer, fset *token.FileSet, pkg *types.Package) error
IExportData writes indexed export data for pkg to out.
If no file set is provided, position info will be missing. The package path of the top-level package will not be recorded, so that calls to IImportData can override with a provided package path.
func IExportShallow(fset *token.FileSet, pkg *types.Package, reportf ReportFunc) ([]byte, error)
IExportShallow encodes "shallow" export data for the specified package.
No promises are made about the encoding other than that it can be decoded by the same version of IIExportShallow. If you plan to save export data in the file system, be sure to include a cryptographic digest of the executable in the key to avoid version skew.
If the provided reportf func is non-nil, it will be used for reporting bugs encountered during export. TODO(rfindley): remove reportf when we are confident enough in the new objectpath encoding.
func IImportBundle(fset *token.FileSet, imports map[string]*types.Package, data []byte) ([]*types.Package, error)
IImportBundle imports a set of packages from the serialized package bundle.
func IImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (int, *types.Package, error)
IImportData imports a package from the serialized package data and returns 0 and a reference to the package. If the export data version is not recognized or the format is otherwise compromised, an error is returned.
func IImportShallow(fset *token.FileSet, getPackages GetPackagesFunc, data []byte, path string, reportf ReportFunc) (*types.Package, error)
IImportShallow decodes "shallow" types.Package data encoded by IExportShallow in the same executable. This function cannot import data from cmd/compile or gcexportdata.Write.
The importer calls getPackages to obtain package symbols for all packages mentioned in the export data, including the one being decoded.
If the provided reportf func is non-nil, it will be used for reporting bugs encountered during import. TODO(rfindley): remove reportf when we are confident enough in the new objectpath encoding.
func Import(packages map[string]*types.Package, path, srcDir string, lookup func(path string) (io.ReadCloser, error)) (pkg *types.Package, err error)
Import imports a gc-generated package given its import path and srcDir, adds the corresponding package object to the packages map, and returns the object. The packages map must contain all packages already imported.
func UImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, pkg *types.Package, err error)
A GetPackagesFunc function obtains the non-nil symbols for a set of packages, creating and recursively importing them as needed. An implementation should store each package symbol is in the Pkg field of the items array.
Any error causes importing to fail. This can be used to quickly read the import manifest of an export data file without fully decoding it.
type GetPackagesFunc = func(items []GetPackagesItem) error
func GetPackagesFromMap(m map[string]*types.Package) GetPackagesFunc
GetPackagesFromMap returns a GetPackagesFunc that retrieves packages from the given map of package path to package.
The returned function may mutate m: each requested package that is not found is created with types.NewPackage and inserted into m.
A GetPackagesItem is a request from the importer for the package symbol of the specified name and path.
type GetPackagesItem struct { Name, Path string Pkg *types.Package // to be filled in by GetPackagesFunc call // contains filtered or unexported fields }
ReportFunc is the type of a function used to report formatted bugs.
type ReportFunc = func(string, ...interface{})