main: make $GOROOT more robust and configurable

Check various locations that $GOROOT may live, including the location of
the go binary. But make it possible to override this autodetection by
setting GOROOT manually as an environment variable.
This commit is contained in:
Ayke van Laethem
2019-05-05 17:24:36 +02:00
committed by Ron Evans
parent a79edf416c
commit 141a70f401
4 changed files with 75 additions and 12 deletions
+6 -1
View File
@@ -76,6 +76,10 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
ldflags = append(ldflags, strings.Replace(flag, "{root}", root, -1))
}
goroot := getGoroot()
if goroot == "" {
return errors.New("cannot locate $GOROOT, please set it manually")
}
compilerConfig := compiler.Config{
Triple: spec.Triple,
CPU: spec.CPU,
@@ -87,7 +91,8 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
LDFlags: ldflags,
Debug: config.debug,
DumpSSA: config.dumpSSA,
RootDir: root,
TINYGOROOT: root,
GOROOT: goroot,
GOPATH: getGopath(),
BuildTags: spec.BuildTags,
}