blob: 180b06a4d30ad77b2f7a00fdac27f10583e03e2b [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001From 1369178b497b12088ec4c2794606cc9f14cc327c Mon Sep 17 00:00:00 2001
2From: Matt Madison <matt@madison.systems>
3Date: Wed, 13 Sep 2017 08:15:03 -0700
4Subject: [PATCH 4/7] cmd/go: allow GOTOOLDIR to be overridden in the
5 environment
6
7For OE cross-builds, host-side tools reside in the native
8GOROOT, not the target GOROOT. Allow GOTOOLDIR to be set
9in the environment to allow that split, rather than always
10computing GOTOOLDIR relative to the GOROOT setting.
11
12Upstream-Status: Pending
13
14Signed-off-by: Khem Raj <raj.khem@gmail.com>
15Signed-off-by: Matt Madison <matt@madison.systems>
16---
17 src/cmd/go/internal/cfg/cfg.go | 7 ++++++-
18 src/cmd/go/internal/work/build.go | 2 +-
19 src/go/build/build.go | 2 +-
20 3 files changed, 8 insertions(+), 3 deletions(-)
21
22diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
23index b3ad1ce..c1dc974 100644
24--- a/src/cmd/go/internal/cfg/cfg.go
25+++ b/src/cmd/go/internal/cfg/cfg.go
26@@ -91,7 +91,12 @@ func init() {
27 // as the tool directory does not move based on environment variables.
28 // This matches the initialization of ToolDir in go/build,
29 // except for using GOROOT rather than runtime.GOROOT().
30- build.ToolDir = filepath.Join(GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
31+ s := os.Getenv("GOTOOLDIR")
32+ if s == "" {
33+ build.ToolDir = filepath.Join(GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
34+ } else {
35+ build.ToolDir = s
36+ }
37 }
38
39 func findGOROOT() string {
40diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
41index 85df0b3..7b9a69e 100644
42--- a/src/cmd/go/internal/work/build.go
43+++ b/src/cmd/go/internal/work/build.go
44@@ -1337,7 +1337,7 @@ func (b *Builder) build(a *Action) (err error) {
45 }
46
47 var cgoExe string
48- if a.cgo != nil && a.cgo.Target != "" {
49+ if a.cgo != nil && a.cgo.Target != "" && os.Getenv("GOTOOLDIR") == "" {
50 cgoExe = a.cgo.Target
51 } else {
52 cgoExe = base.Tool("cgo")
53diff --git a/src/go/build/build.go b/src/go/build/build.go
54index fd89871..e16145b 100644
55--- a/src/go/build/build.go
56+++ b/src/go/build/build.go
57@@ -1588,7 +1588,7 @@ func init() {
58 }
59
60 // ToolDir is the directory containing build tools.
61-var ToolDir = filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
62+var ToolDir = envOr("GOTOOLDIR", filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH))
63
64 // IsLocalImport reports whether the import path is
65 // a local import path, like ".", "..", "./foo", or "../foo".
66--
672.7.4
68