2012-02-16 21:49:59 -07:00
|
|
|
// run
|
2011-10-03 15:46:36 -06:00
|
|
|
|
2023-10-17 13:07:58 -06:00
|
|
|
//go:build !nacl && !js && !wasip1 && gc
|
|
|
|
|
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
|
|
|
|
2022-03-23 13:22:50 -06:00
|
|
|
check(os.Mkdir(tmp("test"), 0777))
|
|
|
|
|
2022-09-21 13:51:27 -06:00
|
|
|
stdlibimportcfg, err := os.ReadFile(os.Getenv("STDLIB_IMPORTCFG"))
|
|
|
|
check(err)
|
|
|
|
importcfg := string(stdlibimportcfg) + "\npackagefile test/slow=" + tmp("test/slow.o") + "\npackagefile test/fast=" + tmp("test/fast.o")
|
|
|
|
os.WriteFile(tmp("importcfg"), []byte(importcfg), 0644)
|
|
|
|
|
|
|
|
run("go", "tool", "compile", "-importcfg="+tmp("importcfg"), "-p=test/slow", "-N", "-o", tmp("test/slow.o"), "pkg.go")
|
|
|
|
run("go", "tool", "compile", "-importcfg="+tmp("importcfg"), "-p=test/fast", "-o", tmp("test/fast.o"), "pkg.go")
|
|
|
|
run("go", "tool", "compile", "-importcfg="+tmp("importcfg"), "-p=main", "-D", "test", "-o", tmp("main.o"), "main.go")
|
|
|
|
run("go", "tool", "link", "-importcfg="+tmp("importcfg"), "-o", tmp("a.exe"), tmp("main.o"))
|
2019-11-18 06:58:58 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|