github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/scripts/vendoring/vendoring.go (about) 1 // Package vendoring provides a several variables used in vendoring 2 // buildscripts and function that reports (without any external 3 // dependencies) if the current environment requires legacy-style 4 // vendoring, or if its safe to use new-style vendoring. 5 package vendoring 6 7 import ( 8 "fmt" 9 "os" 10 "path/filepath" 11 "runtime" 12 "strconv" 13 "strings" 14 ) 15 16 var ( 17 // Path to the vendored gopath component. 18 Path = filepath.Join("build", "vendor") 19 20 // Path to the legacy vendor source directory. 21 Src = filepath.Join(Path, "src") 22 ) 23 24 // NeedsLegacy determines what kind vendoring system to use. Returns 25 // true when using pre-go1.5 vendoring, and false otherwise. 26 func NeedsLegacy() bool { 27 var version []int 28 29 versionString := strings.TrimPrefix(runtime.Version(), "go") 30 31 // gccgo version strings need a bit more processing. 32 if strings.Contains(versionString, "gccgo") { 33 versionString = strings.Split(versionString, " ")[0] 34 } 35 36 // parse the version number. 37 for _, part := range strings.Split(versionString, ".") { 38 value, err := strconv.Atoi(part) 39 40 if err != nil { 41 // if it's a dev version, and a part of the 42 // version string isn't a number, then given 43 // that this script is written in the go1.6 44 // era, then let's assume that its new-style 45 // vendoring. 46 47 return false 48 } 49 50 version = append(version, value) 51 } 52 53 // determine what kind of vendoring we can use. 54 if version[0] > 1 || version[1] >= 7 { 55 // go 2.0 and greater, or go 1.7+, do not require 56 // legacy vendoring, and can use the top-level vendor 57 // directory. 58 return false 59 } else if version[1] <= 4 { 60 // everything less than or equal to go1.4 uses legacy 61 // vendoring (e.g. a modified GOPATH.) 62 return true 63 } 64 65 // for go1.5 and go1.6, use the environment variable to 66 // determine the vendoring configuration. 67 vendorExperiment := os.Getenv("GO15VENDOREXPERIMENT") 68 if version[1] == 6 { 69 return vendorExperiment == "0" 70 } else if version[1] == 5 { 71 return vendorExperiment != "1" 72 } 73 74 // last resort, shouldn't ever hit this. 75 panic(fmt.Sprintf("cannot determine vendoring requirements for this version of go. (%s)", 76 versionString)) 77 }