diff mbox

libgo patch committed: Fix go tool to put external tests first

Message ID CAOyqgcX7MvWhw59eKM9Aj5EjobJ3jwbZtw0-skkJtBUSTv5bdg@mail.gmail.com
State New
Headers show

Commit Message

Ian Lance Taylor March 31, 2015, 5:54 p.m. UTC
When a complex package has both external and internal tests, we need
to link against the external tests first.  This patch from Dave Cheney
fixes this.  Bootstrapped on x86_64-unknown-linux-gnu.  Committed to
mainline.

Ian
diff mbox

Patch

diff -r c601118c5169 libgo/go/cmd/go/build.go
--- a/libgo/go/cmd/go/build.go	Tue Mar 31 10:25:51 2015 -0700
+++ b/libgo/go/cmd/go/build.go	Tue Mar 31 10:53:19 2015 -0700
@@ -1921,6 +1921,7 @@ 
 	// and all LDFLAGS from cgo dependencies.
 	apackagesSeen := make(map[*Package]bool)
 	afiles := []string{}
+	xfiles := []string{}
 	ldflags := b.gccArchArgs()
 	cgoldflags := []string{}
 	usesCgo := false
@@ -1936,7 +1937,12 @@ 
 		if !a.p.Standard {
 			if a.p != nil && !apackagesSeen[a.p] {
 				apackagesSeen[a.p] = true
-				if a.p.fake {
+				if a.p.fake && a.p.external {
+					// external _tests, if present must come before
+					// internal _tests. Store these on a seperate list
+					// and place them at the head after this loop.
+					xfiles = append(xfiles, a.target)
+				} else if a.p.fake {
 					// move _test files to the top of the link order
 					afiles = append([]string{a.target}, afiles...)
 				} else {
@@ -1945,6 +1951,7 @@ 
 			}
 		}
 	}
+	afiles = append(xfiles, afiles...)
 
 	for _, a := range allactions {
 		if a.p != nil {
diff -r c601118c5169 libgo/go/cmd/go/pkg.go
--- a/libgo/go/cmd/go/pkg.go	Tue Mar 31 10:25:51 2015 -0700
+++ b/libgo/go/cmd/go/pkg.go	Tue Mar 31 10:53:19 2015 -0700
@@ -83,6 +83,7 @@ 
 	allgofiles   []string             // gofiles + IgnoredGoFiles, absolute paths
 	target       string               // installed file for this package (may be executable)
 	fake         bool                 // synthesized package
+	external     bool                 // synthesized external test package
 	forceBuild   bool                 // this package must be rebuilt
 	forceLibrary bool                 // this package is a library (even if named "main")
 	cmdline      bool                 // defined by files listed on command line
diff -r c601118c5169 libgo/go/cmd/go/test.go
--- a/libgo/go/cmd/go/test.go	Tue Mar 31 10:25:51 2015 -0700
+++ b/libgo/go/cmd/go/test.go	Tue Mar 31 10:53:19 2015 -0700
@@ -692,10 +692,11 @@ 
 			build: &build.Package{
 				ImportPos: p.build.XTestImportPos,
 			},
-			imports: ximports,
-			pkgdir:  testDir,
-			fake:    true,
-			Stale:   true,
+			imports:  ximports,
+			pkgdir:   testDir,
+			fake:     true,
+			external: true,
+			Stale:    true,
 		}
 		if pxtestNeedsPtest {
 			pxtest.imports = append(pxtest.imports, ptest)