env: get GOROOT from env variable or go env GOROOT
This commit is contained in:
@@ -135,7 +135,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
cfg.Overlay = make(map[string][]byte)
|
cfg.Overlay = make(map[string][]byte)
|
||||||
for file, src := range overlayFiles {
|
for file, src := range overlayFiles {
|
||||||
overlay := unsafe.Slice(unsafe.StringData(src), len(src))
|
overlay := unsafe.Slice(unsafe.StringData(src), len(src))
|
||||||
cfg.Overlay[filepath.Join(runtime.GOROOT(), "src", file)] = overlay
|
cfg.Overlay[filepath.Join(env.GOROOT(), "src", file)] = overlay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
compiler/internal/env/env.go
vendored
17
compiler/internal/env/env.go
vendored
@@ -1,7 +1,9 @@
|
|||||||
package env
|
package env
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -12,6 +14,21 @@ const (
|
|||||||
LLGoRuntimePkg = LLGoCompilerPkg + "/" + LLGoRuntimePkgName
|
LLGoRuntimePkg = LLGoCompilerPkg + "/" + LLGoRuntimePkgName
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GOROOT() string {
|
||||||
|
root := os.Getenv("GOROOT")
|
||||||
|
if root != "" {
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
cmd := exec.Command("go", "env", "GOROOT")
|
||||||
|
var out bytes.Buffer
|
||||||
|
cmd.Stdout = &out
|
||||||
|
err := cmd.Run()
|
||||||
|
if err == nil {
|
||||||
|
return strings.TrimSpace(out.String())
|
||||||
|
}
|
||||||
|
panic("cannot get GOROOT: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
func LLGoRuntimeDir() string {
|
func LLGoRuntimeDir() string {
|
||||||
root := LLGoROOT()
|
root := LLGoROOT()
|
||||||
if root != "" {
|
if root != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user