]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go, go/build: add support for gccgo tooldir
authorIan Lance Taylor <iant@golang.org>
Wed, 2 May 2018 23:42:58 +0000 (16:42 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 4 May 2018 00:46:12 +0000 (00:46 +0000)
The gccgo toolchain does not put tools (cgo, vet, etc.) in
$GOROOT/pkg/tool, but instead in a directory available at
runtime.GCCGOTOOLDIR.

Update the go/build package and the cmd/go tool to use this tool
directory when using gccgo.

Change-Id: Ib827336ff53601208300aceb77f76c2e1b069859
Reviewed-on: https://go-review.googlesource.com/111097
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/alldocs.go
src/cmd/go/internal/cfg/cfg.go
src/cmd/go/internal/help/helpdoc.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/tool/tool.go
src/go/build/build.go
src/go/build/gc.go [new file with mode: 0644]
src/go/build/gccgo.go [new file with mode: 0644]

index e911fa01abe030b69cbc89602d4f779bbb17989e..6832203f3555af5ea8ddc68690f94d95dc34a3c8 100644 (file)
 //
 // 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.
index 85494e34f0f9306cdb799130dd1fd12f41214c9e..3df5905d02691b9d69cb4e0e19a5b9a7f490c8ff 100644 (file)
@@ -93,11 +93,14 @@ var (
 // 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 {
@@ -105,6 +108,11 @@ 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)
index 60c1346e1d0e8145f881f9b549c2b3040983d801..a90d19e976cbc71994baff23e4f2c3f13fe2fa4b 100644 (file)
@@ -533,6 +533,9 @@ Architecture-specific environment variables:
 
 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.
index af5ffcd1035214de456afcd222e8fb50dbd7e1df..e496ce90f004c88cd61f250124f8e5eaf113f47b 100644 (file)
@@ -975,7 +975,11 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
                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"
index db92884f6aa53b9950c2b4d355920764c1308262..4c7d0897e054a6f587af8752df20edc69258120d 100644 (file)
@@ -33,6 +33,17 @@ For more about each tool command, see 'go doc cmd/<command>'.
 
 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, "")
 }
@@ -114,6 +125,11 @@ func listTools() {
                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)
        }
 }
index 30b5283400490ad8c3c48a9e39c081c32087d309..ef43888fc544cf16b9d960b8dd45ee768c66869f 100644 (file)
@@ -1595,7 +1595,7 @@ func init() {
 }
 
 // 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".
diff --git a/src/go/build/gc.go b/src/go/build/gc.go
new file mode 100644 (file)
index 0000000..3025cd5
--- /dev/null
@@ -0,0 +1,17 @@
+// 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)
+}
diff --git a/src/go/build/gccgo.go b/src/go/build/gccgo.go
new file mode 100644 (file)
index 0000000..c6aac9a
--- /dev/null
@@ -0,0 +1,14 @@
+// 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)
+}