]> Cypherpunks repositories - gostls13.git/commitdiff
test/run: use go tool compile + link instead of go run when possible
authorRuss Cox <rsc@golang.org>
Fri, 27 Oct 2017 18:11:21 +0000 (14:11 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 31 Oct 2017 13:21:05 +0000 (13:21 +0000)
This cuts 6 seconds off all.bash with the new go command.
Not a ton, but also an easy 6 seconds to grab.

The -tags=use_go_run in the misc/cgo tests is just some
go command flag that will make run.go use go run,
but without making everything look stale.
(Those tests have relative imports,
so go tool compile+link is not enough.)

Change-Id: I43bf4bb661d3adde2b2d4aad5e8f64b97bc69ba9
Reviewed-on: https://go-review.googlesource.com/73994
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/life/main.go
misc/cgo/stdio/chain.go
misc/cgo/stdio/fib.go
misc/cgo/stdio/hello.go
test/run.go

index aa2f6d116b392b6150d3a2a94736e55d48c71184..45376fd05a97fde57588e534105dd144e41c1ae3 100644 (file)
@@ -1,4 +1,4 @@
-// cmpout
+// cmpout -tags=use_go_run
 
 // Copyright 2010 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 package main
 
 import (
-       "."
        "flag"
        "fmt"
+
+       "."
 )
 
 const MAXDIM = 100
index 03cddb76888e2faabe0ee65032ec45bfedf2d5a7..0fa813cab7082631cead57fb392b29c701d00684 100644 (file)
@@ -1,4 +1,4 @@
-// cmpout
+// cmpout -tags=use_go_run
 
 // Copyright 2009 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 61a1b83728c1528c08c457477d2b724276471575..56e32552ee6dea6500406b418b76733b21bb9eca 100644 (file)
@@ -1,4 +1,4 @@
-// cmpout
+// cmpout -tags=use_go_run
 
 // Copyright 2009 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 47179ba48278684b45eaff9503728da1be4c2fdf..63bff4c617a1371a152c4cec51896ed318585011 100644 (file)
@@ -1,4 +1,4 @@
-// cmpout
+// cmpout -tags=use_go_run
 
 // Copyright 2009 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 921a8ee33200f1720f7431ecf636c9f4f101b46e..e33539eb0f226791d3f6845f0e796b86e16c75d9 100644 (file)
@@ -799,13 +799,38 @@ func (t *test) run() {
 
        case "run":
                useTmp = false
-               cmd := []string{"go", "run", goGcflags()}
-               if *linkshared {
-                       cmd = append(cmd, "-linkshared")
+               var out []byte
+               var err error
+               if len(flags)+len(args) == 0 && goGcflags() == "" && !*linkshared {
+                       // If we're not using special go command flags,
+                       // skip all the go command machinery.
+                       // This avoids any time the go command would
+                       // spend checking whether, for example, the installed
+                       // package runtime is up to date.
+                       // Because we run lots of trivial test programs,
+                       // the time adds up.
+                       pkg := filepath.Join(t.tempDir, "pkg.a")
+                       if _, err := runcmd("go", "tool", "compile", "-o", pkg, t.goFileName()); err != nil {
+                               t.err = err
+                               return
+                       }
+                       exe := filepath.Join(t.tempDir, "test.exe")
+                       cmd := []string{"go", "tool", "link", "-s", "-w"}
+                       cmd = append(cmd, "-o", exe, pkg)
+                       if _, err := runcmd(cmd...); err != nil {
+                               t.err = err
+                               return
+                       }
+                       out, err = runcmd(append([]string{exe}, args...)...)
+               } else {
+                       cmd := []string{"go", "run", goGcflags()}
+                       if *linkshared {
+                               cmd = append(cmd, "-linkshared")
+                       }
+                       cmd = append(cmd, flags...)
+                       cmd = append(cmd, t.goFileName())
+                       out, err = runcmd(append(cmd, args...)...)
                }
-               cmd = append(cmd, flags...)
-               cmd = append(cmd, t.goFileName())
-               out, err := runcmd(append(cmd, args...)...)
                if err != nil {
                        t.err = err
                        return