]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix test import dependency bug
authorRuss Cox <rsc@golang.org>
Fri, 2 Mar 2012 16:27:36 +0000 (11:27 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 2 Mar 2012 16:27:36 +0000 (11:27 -0500)
Fixes a problem Rob is having with goprotobuf.
Cannot add a test because the same case is more broken
when using ./ imports.  That still needs to be fixed,
and is one aspect of issue 3169.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5725043

src/cmd/go/build.go
src/cmd/go/pkg.go
src/cmd/go/test.go

index 62c7dd1dfa8b658bb4acfbff1f6b8119f975d042..d14278acbc44a4cb1b893b4d15062d2d0b3acbdf 100644 (file)
@@ -363,7 +363,7 @@ func goFilesPackage(gofiles []string) *Package {
        pkg.Target = ""
        pkg.Stale = true
 
-       computeStale([]*Package{pkg})
+       computeStale(pkg)
        return pkg
 }
 
index a159e4559060890fbcb42ecb426ad524c1030cf6..7973c8e7cc97289e6e3c19fc7f72097901a930f5 100644 (file)
@@ -376,7 +376,7 @@ func packageList(roots []*Package) []*Package {
                        return
                }
                seen[p] = true
-               for _, p1 := range p.deps {
+               for _, p1 := range p.imports {
                        walk(p1)
                }
                all = append(all, p)
@@ -389,7 +389,7 @@ func packageList(roots []*Package) []*Package {
 
 // computeStale computes the Stale flag in the package dag that starts
 // at the named pkgs (command-line arguments).
-func computeStale(pkgs []*Package) {
+func computeStale(pkgs ...*Package) {
        topRoot := map[string]bool{}
        for _, p := range pkgs {
                topRoot[p.Root] = true
@@ -579,7 +579,7 @@ func packagesAndErrors(args []string) []*Package {
                pkgs = append(pkgs, loadPackage(arg, &stk))
        }
 
-       computeStale(pkgs)
+       computeStale(pkgs...)
 
        return pkgs
 }
index da7d60b76af7b62e9038d8620fdaeef42ba66993..b4e54207a3c2c3fbcc64935fab555bfd8c1ca715 100644 (file)
@@ -396,6 +396,9 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                imports = append(imports, p1)
        }
        for _, path := range p.XTestImports {
+               if path == p.ImportPath {
+                       continue
+               }
                p1 := loadImport(path, p.Dir, &stk, p.build.XTestImportPos[path])
                if p1.Error != nil {
                        return nil, nil, nil, p1.Error
@@ -447,6 +450,7 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                ptest.imports = append(append([]*Package{}, p.imports...), imports...)
                ptest.pkgdir = testDir
                ptest.fake = true
+               ptest.Stale = true
                ptest.build = new(build.Package)
                *ptest.build = *p.build
                m := map[string][]token.Position{}
@@ -457,6 +461,7 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                        m[k] = append(m[k], v...)
                }
                ptest.build.ImportPos = m
+               computeStale(ptest)
                a := b.action(modeBuild, modeBuild, ptest)
                a.objdir = testDir + string(filepath.Separator)
                a.objpkg = ptestObj
@@ -480,7 +485,9 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                        imports: append(ximports, ptest),
                        pkgdir:  testDir,
                        fake:    true,
+                       Stale:   true,
                }
+               computeStale(pxtest)
                a := b.action(modeBuild, modeBuild, pxtest)
                a.objdir = testDir + string(filepath.Separator)
                a.objpkg = buildToolchain.pkgpath(testDir, pxtest)
@@ -489,12 +496,14 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
 
        // Action for building pkg.test.
        pmain = &Package{
-               Name:    "main",
-               Dir:     testDir,
-               GoFiles: []string{"_testmain.go"},
-               imports: []*Package{ptest},
-               build:   &build.Package{},
-               fake:    true,
+               Name:       "main",
+               Dir:        testDir,
+               GoFiles:    []string{"_testmain.go"},
+               ImportPath: "testmain",
+               imports:    []*Package{ptest},
+               build:      &build.Package{},
+               fake:       true,
+               Stale:      true,
        }
        if pxtest != nil {
                pmain.imports = append(pmain.imports, pxtest)
@@ -511,6 +520,7 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                return nil, nil, nil, pregexp.Error
        }
        pmain.imports = append(pmain.imports, ptesting, pregexp)
+       computeStale(pmain)
 
        a := b.action(modeBuild, modeBuild, pmain)
        a.objdir = testDir + string(filepath.Separator)