mirror of
https://github.com/golang/go
synced 2024-11-22 04:24:39 -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.Target = ""
|
||||||
pkg.Stale = true
|
pkg.Stale = true
|
||||||
|
|
||||||
computeStale([]*Package{pkg})
|
computeStale(pkg)
|
||||||
return pkg
|
return pkg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ func packageList(roots []*Package) []*Package {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
seen[p] = true
|
seen[p] = true
|
||||||
for _, p1 := range p.deps {
|
for _, p1 := range p.imports {
|
||||||
walk(p1)
|
walk(p1)
|
||||||
}
|
}
|
||||||
all = append(all, p)
|
all = append(all, p)
|
||||||
@ -389,7 +389,7 @@ func packageList(roots []*Package) []*Package {
|
|||||||
|
|
||||||
// computeStale computes the Stale flag in the package dag that starts
|
// computeStale computes the Stale flag in the package dag that starts
|
||||||
// at the named pkgs (command-line arguments).
|
// at the named pkgs (command-line arguments).
|
||||||
func computeStale(pkgs []*Package) {
|
func computeStale(pkgs ...*Package) {
|
||||||
topRoot := map[string]bool{}
|
topRoot := map[string]bool{}
|
||||||
for _, p := range pkgs {
|
for _, p := range pkgs {
|
||||||
topRoot[p.Root] = true
|
topRoot[p.Root] = true
|
||||||
@ -579,7 +579,7 @@ func packagesAndErrors(args []string) []*Package {
|
|||||||
pkgs = append(pkgs, loadPackage(arg, &stk))
|
pkgs = append(pkgs, loadPackage(arg, &stk))
|
||||||
}
|
}
|
||||||
|
|
||||||
computeStale(pkgs)
|
computeStale(pkgs...)
|
||||||
|
|
||||||
return pkgs
|
return pkgs
|
||||||
}
|
}
|
||||||
|
@ -396,6 +396,9 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
|
|||||||
imports = append(imports, p1)
|
imports = append(imports, p1)
|
||||||
}
|
}
|
||||||
for _, path := range p.XTestImports {
|
for _, path := range p.XTestImports {
|
||||||
|
if path == p.ImportPath {
|
||||||
|
continue
|
||||||
|
}
|
||||||
p1 := loadImport(path, p.Dir, &stk, p.build.XTestImportPos[path])
|
p1 := loadImport(path, p.Dir, &stk, p.build.XTestImportPos[path])
|
||||||
if p1.Error != nil {
|
if p1.Error != nil {
|
||||||
return nil, nil, nil, p1.Error
|
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.imports = append(append([]*Package{}, p.imports...), imports...)
|
||||||
ptest.pkgdir = testDir
|
ptest.pkgdir = testDir
|
||||||
ptest.fake = true
|
ptest.fake = true
|
||||||
|
ptest.Stale = true
|
||||||
ptest.build = new(build.Package)
|
ptest.build = new(build.Package)
|
||||||
*ptest.build = *p.build
|
*ptest.build = *p.build
|
||||||
m := map[string][]token.Position{}
|
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...)
|
m[k] = append(m[k], v...)
|
||||||
}
|
}
|
||||||
ptest.build.ImportPos = m
|
ptest.build.ImportPos = m
|
||||||
|
computeStale(ptest)
|
||||||
a := b.action(modeBuild, modeBuild, ptest)
|
a := b.action(modeBuild, modeBuild, ptest)
|
||||||
a.objdir = testDir + string(filepath.Separator)
|
a.objdir = testDir + string(filepath.Separator)
|
||||||
a.objpkg = ptestObj
|
a.objpkg = ptestObj
|
||||||
@ -480,7 +485,9 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
|
|||||||
imports: append(ximports, ptest),
|
imports: append(ximports, ptest),
|
||||||
pkgdir: testDir,
|
pkgdir: testDir,
|
||||||
fake: true,
|
fake: true,
|
||||||
|
Stale: true,
|
||||||
}
|
}
|
||||||
|
computeStale(pxtest)
|
||||||
a := b.action(modeBuild, modeBuild, pxtest)
|
a := b.action(modeBuild, modeBuild, pxtest)
|
||||||
a.objdir = testDir + string(filepath.Separator)
|
a.objdir = testDir + string(filepath.Separator)
|
||||||
a.objpkg = buildToolchain.pkgpath(testDir, pxtest)
|
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.
|
// Action for building pkg.test.
|
||||||
pmain = &Package{
|
pmain = &Package{
|
||||||
Name: "main",
|
Name: "main",
|
||||||
Dir: testDir,
|
Dir: testDir,
|
||||||
GoFiles: []string{"_testmain.go"},
|
GoFiles: []string{"_testmain.go"},
|
||||||
imports: []*Package{ptest},
|
ImportPath: "testmain",
|
||||||
build: &build.Package{},
|
imports: []*Package{ptest},
|
||||||
fake: true,
|
build: &build.Package{},
|
||||||
|
fake: true,
|
||||||
|
Stale: true,
|
||||||
}
|
}
|
||||||
if pxtest != nil {
|
if pxtest != nil {
|
||||||
pmain.imports = append(pmain.imports, pxtest)
|
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
|
return nil, nil, nil, pregexp.Error
|
||||||
}
|
}
|
||||||
pmain.imports = append(pmain.imports, ptesting, pregexp)
|
pmain.imports = append(pmain.imports, ptesting, pregexp)
|
||||||
|
computeStale(pmain)
|
||||||
|
|
||||||
a := b.action(modeBuild, modeBuild, pmain)
|
a := b.action(modeBuild, modeBuild, pmain)
|
||||||
a.objdir = testDir + string(filepath.Separator)
|
a.objdir = testDir + string(filepath.Separator)
|
||||||
|
Loading…
Reference in New Issue
Block a user