1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:54:43 -07:00

go.tools/imports: recognize exports in cgo files

Fixes golang/go#8815.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/143660044
This commit is contained in:
Josh Bleecher Snyder 2014-09-29 12:46:11 -07:00 committed by Brad Fitzpatrick
parent e62e5f9885
commit b6c30b58fc

View File

@ -283,15 +283,17 @@ func loadExportsGoPath(dir string) map[string]bool {
return nil
}
fset := token.NewFileSet()
for _, file := range buildPkg.GoFiles {
f, err := parser.ParseFile(fset, filepath.Join(dir, file), nil, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "could not parse %q: %v\n", file, err)
continue
}
for name := range f.Scope.Objects {
if ast.IsExported(name) {
exports[name] = true
for _, files := range [...][]string{buildPkg.GoFiles, buildPkg.CgoFiles} {
for _, file := range files {
f, err := parser.ParseFile(fset, filepath.Join(dir, file), nil, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "could not parse %q: %v\n", file, err)
continue
}
for name := range f.Scope.Objects {
if ast.IsExported(name) {
exports[name] = true
}
}
}
}