...
1
2
3
4
5 package packagestest
6
7 import (
8 "path"
9 "path/filepath"
10 )
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 var GOPATH = gopath{}
43
44 func init() {
45 All = append(All, GOPATH)
46 }
47
48 type gopath struct{}
49
50 func (gopath) Name() string {
51 return "GOPATH"
52 }
53
54 func (gopath) Filename(exported *Exported, module, fragment string) string {
55 return filepath.Join(gopathDir(exported, module), "src", module, fragment)
56 }
57
58 func (gopath) Finalize(exported *Exported) error {
59 exported.Config.Env = append(exported.Config.Env, "GO111MODULE=off")
60 gopath := ""
61 for module := range exported.written {
62 if gopath != "" {
63 gopath += string(filepath.ListSeparator)
64 }
65 dir := gopathDir(exported, module)
66 gopath += dir
67 if module == exported.primary {
68 exported.Config.Dir = filepath.Join(dir, "src")
69 }
70 }
71 exported.Config.Env = append(exported.Config.Env, "GOPATH="+gopath)
72 return nil
73 }
74
75 func gopathDir(exported *Exported, module string) string {
76 dir := path.Base(module)
77 if versionSuffixRE.MatchString(dir) {
78 dir = path.Base(path.Dir(module)) + "_" + dir
79 }
80 return filepath.Join(exported.temp, dir)
81 }
82
View as plain text