]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: separate test imports out when scanning
authorGustavo Niemeyer <gustavo@niemeyer.net>
Fri, 26 Aug 2011 00:00:20 +0000 (21:00 -0300)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Fri, 26 Aug 2011 00:00:20 +0000 (21:00 -0300)
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

src/pkg/go/build/build_test.go
src/pkg/go/build/dir.go
src/pkg/go/build/pkgtest/pkgtest.go
src/pkg/go/build/pkgtest/sqrt_test.go
src/pkg/go/build/pkgtest/xsqrt_test.go

index 867078544280badf3d260c6e12aefc3580bf9dbc..592ebbd9eaba74ed592ddacc1daed61d4393bbfd 100644 (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"},
                },
index 558b6cf957e451a8967e661d6ed7688c4426ec2f..fa4d9e913f3f59ffa29822ccac953a333b19a040 100644 (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
 }
 
index 9322f5ebd716a6fb1d6eebc628082b8ee1216979..03ebb9893aafb6c0f7a6a4ede5b1b35e0ae90c45 100644 (file)
@@ -4,6 +4,10 @@
 
 package pkgtest
 
-func Foo() {}
+import "os"
+
+func Foo() os.Error {
+       return nil
+}
 
 func Sqrt(x float64) float64
index 26b483fa0bac3bc934851004d80e5e2246462e17..95fb625525cef0f9975972f63f907fc983c186b0 100644 (file)
@@ -1 +1,5 @@
 package pkgtest
+
+import "fmt"
+
+var _ = fmt.Printf
index bd2964e03e4b479728b878b07c8ca40e59b3becf..77e903d96ca745fdf7ad7c9056c36ad29f98bf00 100644 (file)
@@ -1 +1,5 @@
 package pkgtest_test
+
+import "pkgtest"
+
+var _ = pkgtest.Foo