1
0
mirror of https://github.com/golang/go synced 2024-11-20 01:04:40 -07:00

cmd/go: always link external test packages first when using gccgo

This CL is an amagamation of several fixes Canonical have made on their
fork of the cmd/go tool (packaged as gccgo-go.deb on Ubuntu 14.04+).

Additionally this CL brings gccgoToolchain.ldi() up to date with the version
that will ship in gccgo-5.0. As gccgo is most likely to be used with its
own version of the go tool that it supples it makes good sense that the libgo
version should dictate the contents of gccgotoolchain.ld()

Please see https://codereview.appspot.com/222890043/ for more details on the
issues fixed.

Change-Id: Icf7deb43f8e80b424757f1673e6bca7a0aa2a1ac
Reviewed-on: https://go-review.googlesource.com/8250
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Dave Cheney 2015-03-30 16:13:39 +11:00
parent 9c0375277c
commit 9d0239771a
3 changed files with 28 additions and 22 deletions

View File

@ -1968,35 +1968,39 @@ func (gccgoToolchain) pack(b *builder, p *Package, objDir, afile string, ofiles
func (tools gccgoToolchain) ld(b *builder, p *Package, out string, allactions []*action, mainpkg string, ofiles []string) error { func (tools gccgoToolchain) ld(b *builder, p *Package, out string, allactions []*action, mainpkg string, ofiles []string) error {
// gccgo needs explicit linking with all package dependencies, // gccgo needs explicit linking with all package dependencies,
// and all LDFLAGS from cgo dependencies. // and all LDFLAGS from cgo dependencies.
apackagesSeen := make(map[*Package]bool)
afiles := []string{} afiles := []string{}
xfiles := []string{}
ldflags := b.gccArchArgs() ldflags := b.gccArchArgs()
cgoldflags := []string{} cgoldflags := []string{}
usesCgo := false usesCgo := false
cxx := len(p.CXXFiles) > 0 || len(p.SwigCXXFiles) > 0 cxx := len(p.CXXFiles) > 0 || len(p.SwigCXXFiles) > 0
objc := len(p.MFiles) > 0 objc := len(p.MFiles) > 0
// For a given package import path: // Prefer the output of an install action to the output of a build action,
// 1) prefer a test package (created by (*builder).test) to a non-test package // because the install action will delete the output of the build action.
// 2) prefer the output of an install action to the output of a build action // Iterate over the list backward (reverse dependency order) so that we
// because the install action will delete the output of the build // always see the install before the build.
// action
// Iterating over the list backwards (reverse dependency order) ensures that we
// always see an install before a build.
importPathsSeen := make(map[string]bool)
for i := len(allactions) - 1; i >= 0; i-- { for i := len(allactions) - 1; i >= 0; i-- {
a := allactions[i] a := allactions[i]
if a.p.fake && !importPathsSeen[a.p.ImportPath] { if !a.p.Standard {
importPathsSeen[a.p.ImportPath] = true if a.p != nil && !apackagesSeen[a.p] {
afiles = append(afiles, a.target) apackagesSeen[a.p] = true
} if a.p.fake && a.p.external {
} // external _tests, if present must come before
for i := len(allactions) - 1; i >= 0; i-- { // internal _tests. Store these on a seperate list
a := allactions[i] // and place them at the head after this loop.
if !a.p.Standard && !importPathsSeen[a.p.ImportPath] { xfiles = append(xfiles, a.target)
importPathsSeen[a.p.ImportPath] = true } else if a.p.fake {
afiles = append(afiles, a.target) // move _test files to the top of the link order
afiles = append([]string{a.target}, afiles...)
} else {
afiles = append(afiles, a.target)
}
}
} }
} }
afiles = append(xfiles, afiles...)
for _, a := range allactions { for _, a := range allactions {
cgoldflags = append(cgoldflags, a.p.CgoLDFLAGS...) cgoldflags = append(cgoldflags, a.p.CgoLDFLAGS...)

View File

@ -83,6 +83,7 @@ type Package struct {
allgofiles []string // gofiles + IgnoredGoFiles, absolute paths allgofiles []string // gofiles + IgnoredGoFiles, absolute paths
target string // installed file for this package (may be executable) target string // installed file for this package (may be executable)
fake bool // synthesized package fake bool // synthesized package
external bool // synthesized external test package
forceBuild bool // this package must be rebuilt forceBuild bool // this package must be rebuilt
forceLibrary bool // this package is a library (even if named "main") forceLibrary bool // this package is a library (even if named "main")
cmdline bool // defined by files listed on command line cmdline bool // defined by files listed on command line

View File

@ -687,10 +687,11 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
build: &build.Package{ build: &build.Package{
ImportPos: p.build.XTestImportPos, ImportPos: p.build.XTestImportPos,
}, },
imports: ximports, imports: ximports,
pkgdir: testDir, pkgdir: testDir,
fake: true, fake: true,
Stale: true, external: true,
Stale: true,
} }
if pxtestNeedsPtest { if pxtestNeedsPtest {
pxtest.imports = append(pxtest.imports, ptest) pxtest.imports = append(pxtest.imports, ptest)