mirror of
https://github.com/golang/go
synced 2024-11-24 00:30:15 -07:00
f1778c28a9
Change the run.go driver to recognize the "gc" build tag. Change existing tests to use the "gc" build tag if they use some feature that seems specific to the gc compiler, such as passing specific options to or expecting specific behavior from "go tool compile". Change tests to use the "!gccgo" build tag if they use "go build" or "go run", as while those might work with compilers other than gc, they won't work with the way that gccgo runs its testsuite (which happens independently of the go command). For #43252 Change-Id: I666e04b6d7255a77dfc256ee304094e3a6bb15ad Reviewed-on: https://go-review.googlesource.com/c/go/+/279052 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
// +build !nacl,!js,!windows,gc
|
|
// run
|
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Test that compiling with optimization turned on produces faster code.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
|
|
check(err)
|
|
|
|
tmpDir, err := ioutil.TempDir("", "bug369")
|
|
check(err)
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
tmp := func(name string) string {
|
|
return filepath.Join(tmpDir, name)
|
|
}
|
|
|
|
run("go", "tool", "compile", "-N", "-o", tmp("slow.o"), "pkg.go")
|
|
run("go", "tool", "compile", "-o", tmp("fast.o"), "pkg.go")
|
|
run("go", "tool", "compile", "-D", tmpDir, "-o", tmp("main.o"), "main.go")
|
|
run("go", "tool", "link", "-o", tmp("a.exe"), tmp("main.o"))
|
|
run(tmp("a.exe"))
|
|
}
|
|
|
|
func run(name string, args ...string) {
|
|
cmd := exec.Command(name, args...)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
fmt.Println(string(out))
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func check(err error) {
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
}
|