//
// Special-purpose environment variables:
//
+// GCCGOTOOLDIR
+// If set, where to find gccgo tools, such as cgo.
+// The default is based on how gccgo was configured.
// GOROOT_FINAL
// The root of the installed Go tree, when it is
// installed in a location other than where it is built.
// Update build context to use our computed GOROOT.
func init() {
BuildContext.GOROOT = GOROOT
- // Note that we must use runtime.GOOS and runtime.GOARCH here,
- // as the tool directory does not move based on environment variables.
- // This matches the initialization of ToolDir in go/build,
- // except for using GOROOT rather than runtime.GOROOT().
- build.ToolDir = filepath.Join(GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+ if runtime.Compiler != "gccgo" {
+ // Note that we must use runtime.GOOS and runtime.GOARCH here,
+ // as the tool directory does not move based on environment
+ // variables. This matches the initialization of ToolDir in
+ // go/build, except for using GOROOT rather than
+ // runtime.GOROOT.
+ build.ToolDir = filepath.Join(GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+ }
}
func findGOROOT() string {
return filepath.Clean(env)
}
def := filepath.Clean(runtime.GOROOT())
+ if runtime.Compiler == "gccgo" {
+ // gccgo has no real GOROOT, and it certainly doesn't
+ // depend on the executable's location.
+ return def
+ }
exe, err := os.Executable()
if err == nil {
exe, err = filepath.Abs(exe)
Special-purpose environment variables:
+ GCCGOTOOLDIR
+ If set, where to find gccgo tools, such as cgo.
+ The default is based on how gccgo was configured.
GOROOT_FINAL
The root of the installed Go tree, when it is
installed in a location other than where it is built.
if InstallTargetDir(p) == ToTool {
// This is for 'go tool'.
// Override all the usual logic and force it into the tool directory.
- p.Target = filepath.Join(cfg.GOROOTpkg, "tool", full)
+ if cfg.BuildToolchainName == "gccgo" {
+ p.Target = filepath.Join(base.ToolDir, elem)
+ } else {
+ p.Target = filepath.Join(cfg.GOROOTpkg, "tool", full)
+ }
}
if p.Target != "" && cfg.BuildContext.GOOS == "windows" {
p.Target += ".exe"
var toolN bool
+// Return whether tool can be expected in the gccgo tool directory.
+// Other binaries could be in the same directory so don't
+// show those with the 'go tool' command.
+func isGccgoTool(tool string) bool {
+ switch tool {
+ case "cgo", "fix", "cover", "godoc", "vet":
+ return true
+ }
+ return false
+}
+
func init() {
CmdTool.Flag.BoolVar(&toolN, "n", false, "")
}
if base.ToolIsWindows && strings.HasSuffix(name, base.ToolWindowsExtension) {
name = name[:len(name)-len(base.ToolWindowsExtension)]
}
+ // The tool directory used by gccgo will have other binaries
+ // in addition to go tools. Only display go tools here.
+ if cfg.BuildToolchainName == "gccgo" && !isGccgoTool(name) {
+ continue
+ }
fmt.Println(name)
}
}
}
// ToolDir is the directory containing build tools.
-var ToolDir = filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+var ToolDir = getToolDir()
// IsLocalImport reports whether the import path is
// a local import path, like ".", "..", "./foo", or "../foo".
--- /dev/null
+// Copyright 2018 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.
+
+// +build gc
+
+package build
+
+import (
+ "path/filepath"
+ "runtime"
+)
+
+// getToolDir returns the default value of ToolDir.
+func getToolDir() string {
+ return filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+}
--- /dev/null
+// Copyright 2018 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.
+
+// +build gccgo
+
+package build
+
+import "runtime"
+
+// getToolDir returns the default value of ToolDir.
+func getToolDir() string {
+ return envOr("GCCGOTOOLDIR", runtime.GCCGOTOOLDIR)
+}