File tools-packaging.patch of Package go1.12.12320
Index: go/src/cmd/go/internal/load/pkg.go
===================================================================
--- go.orig/src/cmd/go/internal/load/pkg.go
+++ go/src/cmd/go/internal/load/pkg.go
@@ -1281,7 +1281,13 @@ func (p *Package) load(stk *ImportStack,
if cfg.BuildToolchainName == "gccgo" {
p.Target = filepath.Join(base.ToolDir, elem)
} else {
- p.Target = filepath.Join(cfg.GOROOTpkg, "tool", full)
+ // If GOROOT_TARGET is set, then write to it for packaging purpose
+ gorootTarget := os.Getenv("GOROOT_TARGET")
+ if gorootTarget == "" {
+ p.Target = filepath.Join(cfg.GOROOTpkg, "tool", full)
+ } else {
+ p.Target = filepath.Join(gorootTarget, "pkg/tool", full)
+ }
}
}
if p.Target != "" && cfg.BuildContext.GOOS == "windows" {