Skip to content

Commit

Permalink
cmd/guru: if built with gccgo, switch to gc mode if GOROOT is valid
Browse files Browse the repository at this point in the history
The gccgo compiler does not provide a gc-style GOROOT with standard
library sources. The effect is that guru may not fully work when using
gccgo. However, it can fully work if the GOROOT environment variable
points to valid gc-style GOROOT. In that case, make it work by telling
the go/build package to use gc mode.

Change-Id: Iadff8be61be8cc9a7ff2ca0a067b116b62895451
Reviewed-on: https://go-review.googlesource.com/117997
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
  • Loading branch information
ianlancetaylor committed Jun 11, 2018
1 parent f961572 commit 2475cf1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/guru/main.go
Expand Up @@ -19,6 +19,8 @@ import (
"io"
"log"
"os"
"path/filepath"
"runtime"
"runtime/pprof"
"strings"
"sync"
Expand All @@ -38,6 +40,14 @@ var (

func init() {
flag.Var((*buildutil.TagsFlag)(&build.Default.BuildTags), "tags", buildutil.TagsFlagDoc)

// gccgo does not provide a GOROOT with standard library sources.
// If we have one in the environment, force gc mode.
if build.Default.Compiler == "gccgo" {
if _, err := os.Stat(filepath.Join(runtime.GOROOT(), "src", "runtime", "runtime.go")); err == nil {
build.Default.Compiler = "gc"
}
}
}

const useHelp = "Run 'guru -help' for more information.\n"
Expand Down

0 comments on commit 2475cf1

Please sign in to comment.