summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/go/go/0003-allow-GOTOOLDIR-to-be-overridden-in-the-environment.patch
blob: c3ccffc3e95f6e27e6144bf2794e09b2c2f3f5bb (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
From 8512964c0bfdfc3c9c3805743ea7de551a1d476a Mon Sep 17 00:00:00 2001
From: Alex Kube <alexander.j.kube@gmail.com>
Date: Wed, 23 Oct 2019 21:15:37 +0430
Subject: [PATCH] cmd/go: Allow GOTOOLDIR to be overridden in the environment

to allow for split host/target build roots

Adapted to Go 1.13 from patches originally submitted to
the meta/recipes-devtools/go tree by
Matt Madison <matt@madison.systems>.

Upstream-Status: Inappropriate [OE specific]

Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>

---
 src/cmd/dist/build.go          | 4 +++-
 src/cmd/go/internal/cfg/cfg.go | 6 +++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

--- a/src/cmd/dist/build.go
+++ b/src/cmd/dist/build.go
@@ -251,7 +251,9 @@ func xinit() {
 	}
 	xatexit(rmworkdir)
 
-	tooldir = pathf("%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch)
+	if tooldir = os.Getenv("GOTOOLDIR"); tooldir == "" {
+		tooldir = pathf("%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch)
+	}
 }
 
 // compilerEnv returns a map from "goos/goarch" to the
--- a/src/cmd/go/internal/cfg/cfg.go
+++ b/src/cmd/go/internal/cfg/cfg.go
@@ -76,7 +76,11 @@ func defaultContext() build.Context {
 		// variables. This matches the initialization of ToolDir in
 		// go/build, except for using ctxt.GOROOT rather than
 		// runtime.GOROOT.
-		build.ToolDir = filepath.Join(ctxt.GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+		if s := os.Getenv("GOTOOLDIR"); s != "" {
+			build.ToolDir = filepath.Clean(s)
+		} else {
+			build.ToolDir = filepath.Join(ctxt.GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+		}
 	}
 
 	ctxt.GOPATH = envOr("GOPATH", gopath(ctxt))