1From 8512964c0bfdfc3c9c3805743ea7de551a1d476a Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:15:37 +0430
4Subject: [PATCH] cmd/go: Allow GOTOOLDIR to be overridden in the environment
5
6to allow for split host/target build roots
7
8Adapted to Go 1.13 from patches originally submitted to
9the meta/recipes-devtools/go tree by
10Matt Madison <matt@madison.systems>.
11
12Upstream-Status: Inappropriate [OE specific]
13
14Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
15
16---
17 src/cmd/dist/build.go          | 4 +++-
18 src/cmd/go/internal/cfg/cfg.go | 6 +++++-
19 2 files changed, 8 insertions(+), 2 deletions(-)
20
21diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
22index bec1769..d82f612 100644
23--- a/src/cmd/dist/build.go
24+++ b/src/cmd/dist/build.go
25@@ -248,7 +248,9 @@ func xinit() {
26 	}
27 	xatexit(rmworkdir)
28
29-	tooldir = pathf("%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch)
30+	if tooldir = os.Getenv("GOTOOLDIR"); tooldir == "" {
31+		tooldir = pathf("%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch)
32+	}
33 }
34
35 // compilerEnv returns a map from "goos/goarch" to the
36diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
37index 57a3c1f..825d8c7 100644
38--- a/src/cmd/go/internal/cfg/cfg.go
39+++ b/src/cmd/go/internal/cfg/cfg.go
40@@ -67,7 +67,11 @@ func defaultContext() build.Context {
41 		// variables. This matches the initialization of ToolDir in
42 		// go/build, except for using ctxt.GOROOT rather than
43 		// runtime.GOROOT.
44-		build.ToolDir = filepath.Join(ctxt.GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
45+		if s := os.Getenv("GOTOOLDIR"); s != "" {
46+			build.ToolDir = filepath.Clean(s)
47+		} else {
48+			build.ToolDir = filepath.Join(ctxt.GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
49+		}
50 	}
51
52 	ctxt.GOPATH = envOr("GOPATH", ctxt.GOPATH)
53