// load typechecks the packages that match the given patterns and
// includes source for all transitive dependencies. The patterns are
// defined by the underlying build system. For the go tool, this is
// described at https://golang.org/cmd/go/#hdr-Package_lists_and_patterns
//
// wd is the working directory and env is the set of environment
// variables to use when loading the packages specified by patterns. If
// env is nil or empty, it is interpreted as an empty set of variables.
// In case of duplicate environment variables, the last one in the list
// takes precedence.
//
// Note this was copied from: github.com/google/wire@v0.4.0/internal/wire/parse.go
load typechecks the packages that match the given patterns and
includes source for all transitive dependencies. The patterns are
defined by the underlying build system.

wd is the working directory and env is the set of environment
variables to use when loading the packages specified by patterns. If
env is nil or empty, it is interpreted as an empty set of variables.
In case of duplicate environment variables, the last one in the list
takes precedence.

Note this was copied from: github.com/google/wire@v0.4.0/internal/wire/parse.go
// load typechecks the packages that match the given patterns and // includes source for all transitive dependencies . The patterns are // defined by the underlying build system . For the go tool this is // described at https : // golang . org / cmd / go / #hdr - Package_lists_and_patterns // // wd is the working directory and env is the set of environment // variables to use when loading the packages specified by patterns . If // env is nil or empty it is interpreted as an empty set of variables . // In case of duplicate environment variables the last one in the list // takes precedence . // // Note this was copied from : github . com / google / wire@v0 . 4 . 0 / internal / wire / parse . go
func load(ctx context.Context, wd string, env []string, pattern string) (*packages.Package, error) {
	mode := packages.NeedSyntax | packages.NeedImports | packages.NeedTypes |
		packages.NeedTypesInfo | packages.NeedDeps | packages.NeedName
	cfg := &packages.Config{
		Context:    ctx,
		Mode:       mode,
		Dir:        wd,
		Env:        env,
		BuildFlags: []string{"-tags=weld"},
		ParseFile: func(fset *token.FileSet, parseFilename string, src []byte) (*ast.File, error) {
			file, err := parser.ParseFile(fset, parseFilename, src, 0)
			if err != nil {
				return nil, err
			}
			for _, decl := range file.Decls {
				if fd, ok := decl.(*ast.FuncDecl); ok {
					fd.Body = nil
				}
			}
			return file, nil
		},
	}
	pkgs, err := packages.Load(cfg, "pattern="+pattern)
	if err != nil {
		return nil, err
	} else if len(pkgs) != 1 {
		return nil, errors.New("unexpected number of packages")
	}
	pkg := pkgs[0]
	var el []packages.Error
	for _, e := range pkg.Errors {
		if strings.Contains(e.Msg, "imported but not used") {
			continue
		}
		el = append(el, e)
	}
	pkg.Errors = el
	return pkg, nil
}
func load ( ctx context . Context , wd string , env [ ] string , pattern string ) ( * packages . Package , error ) { mode := packages . NeedSyntax | packages . NeedImports | packages . NeedTypes | packages . NeedTypesInfo | packages . NeedDeps | packages . NeedName cfg := & packages . Config { Context : ctx , Mode : mode , Dir : wd , Env : env , BuildFlags : [ ] string { " " } , ParseFile : func ( fset * token . FileSet , parseFilename string , src [ ] byte ) ( * ast . File , error ) { file , err := parser . ParseFile ( fset , parseFilename , src , 0 ) if err != nil { return nil , err } for _ , decl := range file . Decls { if fd , ok := decl . ( * ast . FuncDecl ) ; ok { fd . Body = nil } } return file , nil } , } pkgs , err := packages . Load ( cfg , " " + pattern ) if err != nil { return nil , err } else if len ( pkgs ) != 1 { return nil , errors . New ( " " ) } pkg := pkgs [ 0 ] var el [ ] packages . Error for _ , e := range pkg . Errors { if strings . Contains ( e . Msg , " " ) { continue } el = append ( el , e ) } pkg . Errors = el return pkg , nil }
load typechecks the packages that match the given patterns and
includes source for all transitive dependencies.
load typechecks the packages that match the given patterns and includes source for all transitive dependencies .
// Improve performance by clearing function // bodies so they do not get type checked. // Since we clear function bodies, filter "imported but not used" errors.