mirror of
https://github.com/golang/go
synced 2024-11-21 16:34:42 -07:00
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
This commit is contained in:
parent
11e7eabb7e
commit
d08a8848bb
@ -363,7 +363,7 @@ func goFilesPackage(gofiles []string) *Package {
|
||||
pkg.Target = ""
|
||||
pkg.Stale = true
|
||||
|
||||
computeStale([]*Package{pkg})
|
||||
computeStale(pkg)
|
||||
return pkg
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user