diff --git a/cmd/compilebench/main.go b/cmd/compilebench/main.go index d2cd70b2..4d3b74ef 100644 --- a/cmd/compilebench/main.go +++ b/cmd/compilebench/main.go @@ -67,9 +67,9 @@ package main import ( "bytes" + "encoding/json" "flag" "fmt" - "go/build" "io/ioutil" "log" "os" @@ -144,6 +144,7 @@ func main() { log.Fatalf("%s env GOROOT: %v", *flagGoCmd, err) } goroot = strings.TrimSpace(string(s)) + os.Setenv("GOROOT", goroot) // for any subcommands compiler = *flagCompiler if compiler == "" { @@ -250,11 +251,28 @@ func runBuild(name, dir string, count int) { return } - pkg, err := build.Import(dir, ".", 0) + // Make sure dependencies needed by go tool compile are installed to GOROOT/pkg. + out, err := exec.Command(*flagGoCmd, "build", "-i", dir).CombinedOutput() if err != nil { - log.Print(err) + log.Printf("go build -i %s: %v\n%s", dir, err, out) return } + + // Find dir and source file list. + var pkg struct { + Dir string + GoFiles []string + } + out, err = exec.Command(*flagGoCmd, "list", "-json", dir).Output() + if err != nil { + log.Printf("go list -json %s: %v\n", dir, err) + return + } + if err := json.Unmarshal(out, &pkg); err != nil { + log.Printf("go list -json %s: unmarshal: %v", dir, err) + return + } + args := []string{"-o", "_compilebench_.o"} if is6g { *flagMemprofilerate = -1