// Return filename, replacing a first occurrence of $GOROOT with the
// actual value of the GOROOT (because LSP does not speak "$GOROOT").
func uprootedPath(filename string) string {
- if !strings.HasPrefix(filename, "$GOROOT/") {
+ if buildcfg.GOROOT == "" || !strings.HasPrefix(filename, "$GOROOT/") {
return filename
}
return buildcfg.GOROOT + filename[len("$GOROOT"):]
// require being more consistent about when we use native vs UNIX
// file paths.
const dollarGOROOT = "$GOROOT"
- if strings.HasPrefix(filename, dollarGOROOT) {
+ if buildcfg.GOROOT != "" && strings.HasPrefix(filename, dollarGOROOT) {
filename = buildcfg.GOROOT + filename[len(dollarGOROOT):]
}
}
abs, rewritten := ApplyRewrites(abs, rewrites)
- if !rewritten && hasPathPrefix(abs, buildcfg.GOROOT) {
+ if !rewritten && buildcfg.GOROOT != "" && hasPathPrefix(abs, buildcfg.GOROOT) {
abs = "$GOROOT" + abs[len(buildcfg.GOROOT):]
}
suffix = "asan"
}
- Lflag(ctxt, filepath.Join(buildcfg.GOROOT, "pkg", fmt.Sprintf("%s_%s%s%s", buildcfg.GOOS, buildcfg.GOARCH, suffixsep, suffix)))
+ if buildcfg.GOROOT != "" {
+ Lflag(ctxt, filepath.Join(buildcfg.GOROOT, "pkg", fmt.Sprintf("%s_%s%s%s", buildcfg.GOOS, buildcfg.GOARCH, suffixsep, suffix)))
+ }
mayberemoveoutfile()
final := gorootFinal()
addstrdata1(ctxt, "runtime.defaultGOROOT="+final)
- addstrdata1(ctxt, "internal/buildcfg.defaultGOROOT="+final)
buildVersion := buildcfg.Version
if goexperiment := buildcfg.Experiment.String(); goexperiment != "" {
"fmt"
"os"
"path/filepath"
+ "runtime"
"strings"
)
var (
- defaultGOROOT string // set by linker
-
- GOROOT = envOr("GOROOT", defaultGOROOT)
+ GOROOT = runtime.GOROOT() // cached for efficiency
GOARCH = envOr("GOARCH", defaultGOARCH)
GOOS = envOr("GOOS", defaultGOOS)
GO386 = envOr("GO386", defaultGO386)