1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:57:57 -07:00

go/build: separate test imports out when scanning

This fixes goinstall so it doesn't try to install unneeded
packages or get confused with non-existent loops.

R=golang-dev, adg, gustavo
CC=golang-dev
https://golang.org/cl/4958046
This commit is contained in:
Gustavo Niemeyer 2011-08-25 21:00:20 -03:00
parent 825f8c147a
commit 77db5ff501
5 changed files with 30 additions and 3 deletions

View File

@ -28,6 +28,8 @@ var buildPkgs = []struct {
GoFiles: []string{"pkgtest.go"},
SFiles: []string{"sqrt_" + runtime.GOARCH + ".s"},
PkgName: "pkgtest",
Imports: []string{"os"},
TestImports: []string{"fmt", "pkgtest"},
TestGoFiles: sortstr([]string{"sqrt_test.go", "sqrt_" + runtime.GOARCH + "_test.go"}),
XTestGoFiles: []string{"xsqrt_test.go"},
},

View File

@ -45,7 +45,8 @@ type DirInfo struct {
CgoFiles []string // .go files that import "C"
CFiles []string // .c files in dir
SFiles []string // .s files in dir
Imports []string // All packages imported by goFiles
Imports []string // All packages imported by GoFiles
TestImports []string // All packages imported by (X)TestGoFiles
PkgName string // Name of package in dir
TestGoFiles []string // _test.go files in package
XTestGoFiles []string // _test.go files outside package
@ -76,6 +77,7 @@ func (ctxt *Context) ScanDir(dir string, allowMain bool) (info *DirInfo, err os.
var di DirInfo
imported := make(map[string]bool)
testImported := make(map[string]bool)
fset := token.NewFileSet()
for _, d := range dirs {
if strings.HasPrefix(d.Name, "_") ||
@ -134,7 +136,11 @@ func (ctxt *Context) ScanDir(dir string, allowMain bool) (info *DirInfo, err os.
if err != nil {
log.Panicf("%s: parser returned invalid quoted string: <%s>", filename, quoted)
}
imported[path] = true
if isTest {
testImported[path] = true
} else {
imported[path] = true
}
if path == "C" {
if isTest {
return nil, os.NewError("use of cgo in test " + filename)
@ -160,8 +166,15 @@ func (ctxt *Context) ScanDir(dir string, allowMain bool) (info *DirInfo, err os.
di.Imports[i] = p
i++
}
di.TestImports = make([]string, len(testImported))
i = 0
for p := range testImported {
di.TestImports[i] = p
i++
}
// File name lists are sorted because ioutil.ReadDir sorts.
sort.Strings(di.Imports)
sort.Strings(di.TestImports)
return &di, nil
}

View File

@ -4,6 +4,10 @@
package pkgtest
func Foo() {}
import "os"
func Foo() os.Error {
return nil
}
func Sqrt(x float64) float64

View File

@ -1 +1,5 @@
package pkgtest
import "fmt"
var _ = fmt.Printf

View File

@ -1 +1,5 @@
package pkgtest_test
import "pkgtest"
var _ = pkgtest.Foo