forked from evergreen-ci/evergreen
/
render-gopath.go
60 lines (49 loc) · 1.47 KB
/
render-gopath.go
1
2
3
4
5
6
7
8
9
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Simple script to print the current GOPATH with additional vendoring
// component for legacy vendoring, as needed. Use in conjunction with
// makefile configuration and the "make-vendor" script.
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"./vendoring"
)
func main() {
currentGoPath := os.Getenv("GOPATH")
pwd, err := os.Getwd()
// print error and exit if there's an error
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if runtime.GOOS == "windows" {
for _, cygPath := range []string{"/cygdrive/c/data", "/data"} {
if strings.HasPrefix(currentGoPath, cygPath) {
currentGoPath = strings.Replace(currentGoPath, cygPath, "c:\\data", -1)
break
}
}
currentGoPath = strings.Replace(currentGoPath, `:\`, `:\\`, 1)
currentGoPath = strings.Replace(currentGoPath, "/", `\\`, -1)
}
// initialize the gopath components.
goPathParts := []string{currentGoPath}
// if this version of go does not support new-style vendoring,
// then we need to mangle the gopath so that the build can use
// vendored dependencies.
if vendoring.NeedsLegacy() {
goPathParts = append(goPathParts, filepath.Join(pwd, vendoring.Path))
// add any additional paths to nested vendored gopaths.
for _, path := range os.Args[1:] {
absPath, err := filepath.Abs(path)
if err == nil {
goPathParts = append(goPathParts, absPath)
} else {
goPathParts = append(goPathParts, path)
}
}
}
fmt.Printf("GOPATH=%s", strings.Join(goPathParts, ":"))
}