1
2
3
4
5
6
7
8
9
10 package work
11
12 import (
13 "cmd/go/internal/cfg"
14 "cmd/go/internal/search"
15 "fmt"
16 "os"
17 "path/filepath"
18 "runtime"
19 )
20
21 func init() {
22 if v := os.Getenv("TESTGO_VERSION"); v != "" {
23 runtimeVersion = v
24 }
25
26 if testGOROOT := os.Getenv("TESTGO_GOROOT"); testGOROOT != "" {
27
28
29 allowInstall = func(a *Action) error {
30 if cfg.BuildN {
31 return nil
32 }
33
34 rel := search.InDir(a.Target, testGOROOT)
35 if rel == "" {
36 return nil
37 }
38
39 callerPos := ""
40 if _, file, line, ok := runtime.Caller(1); ok {
41 if shortFile := search.InDir(file, filepath.Join(testGOROOT, "src")); shortFile != "" {
42 file = shortFile
43 }
44 callerPos = fmt.Sprintf("%s:%d: ", file, line)
45 }
46 return fmt.Errorf("%stestgo must not write to GOROOT (installing to %s)", callerPos, filepath.Join("GOROOT", rel))
47 }
48 }
49 }
50
View as plain text