2018-03-04 04:15:37 -07:00
|
|
|
// +build !nacl,!js,!windows
|
2012-02-16 21:49:59 -07:00
|
|
|
// run
|
2011-10-03 15:46:36 -06:00
|
|
|
|
2016-04-10 15:32:26 -06:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
2011-10-03 15:46:36 -06:00
|
|
|
// 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 (
|
2014-12-18 11:34:12 -07:00
|
|
|
"fmt"
|
2019-11-18 06:58:58 -07:00
|
|
|
"io/ioutil"
|
2011-10-03 15:46:36 -06:00
|
|
|
"os"
|
2014-12-18 11:34:12 -07:00
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2011-10-03 15:46:36 -06:00
|
|
|
)
|
|
|
|
|
2014-12-18 11:34:12 -07:00
|
|
|
func main() {
|
2015-05-21 11:28:17 -06:00
|
|
|
err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
|
2014-12-18 11:34:12 -07:00
|
|
|
check(err)
|
|
|
|
|
2019-11-18 06:58:58 -07:00
|
|
|
tmpDir, err := ioutil.TempDir("", "bug369")
|
|
|
|
check(err)
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
|
|
|
|
tmp := func(name string) string {
|
|
|
|
return filepath.Join(tmpDir, name)
|
|
|
|
}
|
2014-12-18 11:34:12 -07:00
|
|
|
|
2019-11-18 06:58:58 -07:00
|
|
|
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"))
|
2011-10-03 15:46:36 -06:00
|
|
|
}
|
|
|
|
|
2014-12-18 11:34:12 -07:00
|
|
|
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)
|
2011-10-03 15:46:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 11:34:12 -07:00
|
|
|
func check(err error) {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
2011-10-03 15:46:36 -06:00
|
|
|
}
|
|
|
|
}
|