aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/go/go-1.9/0004-cmd-go-allow-GOTOOLDIR-to-be-overridden-in-the-envir.patch
blob: 180b06a4d30ad77b2f7a00fdac27f10583e03e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 1369178b497b12088ec4c2794606cc9f14cc327c Mon Sep 17 00:00:00 2001
From: Matt Madison <matt@madison.systems>
Date: Wed, 13 Sep 2017 08:15:03 -0700
Subject: [PATCH 4/7] cmd/go: allow GOTOOLDIR to be overridden in the
 environment

For OE cross-builds, host-side tools reside in the native
GOROOT, not the target GOROOT.  Allow GOTOOLDIR to be set
in the environment to allow that split, rather than always
computing GOTOOLDIR relative to the GOROOT setting.

Upstream-Status: Pending

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Matt Madison <matt@madison.systems>
---
 src/cmd/go/internal/cfg/cfg.go    | 7 ++++++-
 src/cmd/go/internal/work/build.go | 2 +-
 src/go/build/build.go             | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
index b3ad1ce..c1dc974 100644
--- a/src/cmd/go/internal/cfg/cfg.go
+++ b/src/cmd/go/internal/cfg/cfg.go
@@ -91,7 +91,12 @@ func init() {
 	// 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)
+	s := os.Getenv("GOTOOLDIR")
+	if s == "" {
+		build.ToolDir = filepath.Join(GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+	} else {
+		build.ToolDir = s
+	}
 }
 
 func findGOROOT() string {
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index 85df0b3..7b9a69e 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -1337,7 +1337,7 @@ func (b *Builder) build(a *Action) (err error) {
 		}
 
 		var cgoExe string
-		if a.cgo != nil && a.cgo.Target != "" {
+		if a.cgo != nil && a.cgo.Target != "" && os.Getenv("GOTOOLDIR") == "" {
 			cgoExe = a.cgo.Target
 		} else {
 			cgoExe = base.Tool("cgo")
diff --git a/src/go/build/build.go b/src/go/build/build.go
index fd89871..e16145b 100644
--- a/src/go/build/build.go
+++ b/src/go/build/build.go
@@ -1588,7 +1588,7 @@ func init() {
 }
 
 // ToolDir is the directory containing build tools.
-var ToolDir = filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+var ToolDir = envOr("GOTOOLDIR", filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH))
 
 // IsLocalImport reports whether the import path is
 // a local import path, like ".", "..", "./foo", or "../foo".
-- 
2.7.4