github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/scripts/render-gopath.go (about)

     1  // Simple script to print the current GOPATH with additional vendoring
     2  // component for legacy vendoring, as needed. Use in conjunction with
     3  // makefile configuration and the "make-vendor" script.
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"path/filepath"
    10  	"runtime"
    11  	"strings"
    12  
    13  	"./vendoring"
    14  )
    15  
    16  func main() {
    17  	currentGoPath := os.Getenv("GOPATH")
    18  	pwd, err := os.Getwd()
    19  
    20  	// print error and exit if there's an error
    21  	if err != nil {
    22  		fmt.Println(err)
    23  		os.Exit(1)
    24  	}
    25  
    26  	if runtime.GOOS == "windows" {
    27  		for _, cygPath := range []string{"/cygdrive/c/data", "/data"} {
    28  			if strings.HasPrefix(currentGoPath, cygPath) {
    29  				currentGoPath = strings.Replace(currentGoPath, cygPath, "c:\\data", -1)
    30  				break
    31  			}
    32  		}
    33  		currentGoPath = strings.Replace(currentGoPath, `:\`, `:\\`, 1)
    34  
    35  		currentGoPath = strings.Replace(currentGoPath, "/", `\\`, -1)
    36  	}
    37  
    38  	// initialize the gopath components.
    39  	goPathParts := []string{currentGoPath}
    40  
    41  	// if this version of go does not support new-style vendoring,
    42  	// then we need to mangle the gopath so that the build can use
    43  	// vendored dependencies.
    44  	if vendoring.NeedsLegacy() {
    45  		goPathParts = append(goPathParts, filepath.Join(pwd, vendoring.Path))
    46  
    47  		// add any additional paths to nested vendored gopaths.
    48  		for _, path := range os.Args[1:] {
    49  			absPath, err := filepath.Abs(path)
    50  
    51  			if err == nil {
    52  				goPathParts = append(goPathParts, absPath)
    53  			} else {
    54  				goPathParts = append(goPathParts, path)
    55  			}
    56  		}
    57  	}
    58  
    59  	fmt.Printf("GOPATH=%s", strings.Join(goPathParts, ":"))
    60  }