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