mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
imports: use LoadFiles everywhere
Since we don't really need type info, and want everything to be fast, use LoadFiles and do parsing manually. It would be nice if there were a mode for that. Change-Id: I33f8a85ffb87a70048c4775058bd0813cf677061 Reviewed-on: https://go-review.googlesource.com/c/155478 Run-TryBot: Heschi Kreinick <heschi@google.com> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
d12035dfdc
commit
537d06c362
@ -580,7 +580,7 @@ func scanGoPackages(refs map[string]map[string]bool) ([]*pkg, error) {
|
||||
loadQueries = append(loadQueries, "name="+pkgName)
|
||||
}
|
||||
sort.Strings(loadQueries)
|
||||
cfg := newPackagesConfig(packages.LoadTypes)
|
||||
cfg := newPackagesConfig(packages.LoadFiles)
|
||||
goPackages, err := packages.Load(cfg, loadQueries...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -846,19 +846,29 @@ func VendorlessPath(ipath string) string {
|
||||
// loadExports returns the set of exported symbols in the package at dir.
|
||||
// It returns nil on error or if the package name in dir does not match expectPackage.
|
||||
func loadExports(ctx context.Context, expectPackage string, pkg *pkg) (map[string]bool, error) {
|
||||
if Debug {
|
||||
log.Printf("loading exports in dir %s (seeking package %s)", pkg.dir, expectPackage)
|
||||
}
|
||||
if pkg.goPackage != nil {
|
||||
exports := map[string]bool{}
|
||||
for _, name := range pkg.goPackage.Types.Scope().Names() {
|
||||
if ast.IsExported(name) {
|
||||
exports[name] = true
|
||||
fset := token.NewFileSet()
|
||||
for _, fname := range pkg.goPackage.CompiledGoFiles {
|
||||
f, err := parser.ParseFile(fset, fname, nil, 0)
|
||||
if err != nil {
|
||||
if Debug {
|
||||
log.Printf("Parsing %s: %v", fname, err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
for name := range f.Scope.Objects {
|
||||
if ast.IsExported(name) {
|
||||
exports[name] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return exports, nil
|
||||
}
|
||||
|
||||
if Debug {
|
||||
log.Printf("loading exports in dir %s (seeking package %s)", pkg.dir, expectPackage)
|
||||
}
|
||||
exports := make(map[string]bool)
|
||||
|
||||
buildCtx := build.Default
|
||||
|
Loading…
x
Reference in New Issue
Block a user