From d08a8848bb0833cfe0dcf6f0fcc3e9f0c1b05e10 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 2 Mar 2012 11:27:36 -0500 Subject: [PATCH] cmd/go: fix test import dependency bug 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 | 2 +- src/cmd/go/pkg.go | 6 +++--- src/cmd/go/test.go | 22 ++++++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index 62c7dd1dfa8..d14278acbc4 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -363,7 +363,7 @@ func goFilesPackage(gofiles []string) *Package { pkg.Target = "" pkg.Stale = true - computeStale([]*Package{pkg}) + computeStale(pkg) return pkg } diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go index a159e455906..7973c8e7cc9 100644 --- a/src/cmd/go/pkg.go +++ b/src/cmd/go/pkg.go @@ -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 } diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go index da7d60b76af..b4e54207a3c 100644 --- a/src/cmd/go/test.go +++ b/src/cmd/go/test.go @@ -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)