From 955e36c90cb22b2315f48ab773b653532627d53d Mon Sep 17 00:00:00 2001 From: Edward Muller Date: Thu, 11 Feb 2016 14:42:35 -0800 Subject: [PATCH] Disable VendorExperiment if we have a workspace Several people have asked for this and it's what most people will probably expect. Fixes #411 --- Changelog.md | 4 ++++ main.go | 28 +++++++++++++++++++++++----- version.go | 2 +- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index 6274191..ec13013 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +# v53 2016/02/11 + +* Disable VendorExperiment if a godep workspace already exists. + # v52 2016/01/27 * Trim 'rc' out of go version strings when determining major version. diff --git a/main.go b/main.go index de7f78e..47a74fa 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io" "log" "os" + "path/filepath" "runtime/pprof" "strings" "text/template" @@ -65,6 +66,27 @@ var commands = []*Command{ cmdVersion, } +// VendorExperiment is the Go 1.5 vendor directory experiment flag, see +// https://github.com/golang/go/commit/183cc0cd41f06f83cb7a2490a499e3f9101befff +// Honor the env var unless the project already has an old school godep workspace +func determineVendor(v string) bool { + go15ve := os.Getenv("GO15VENDOREXPERIMENT") + ev := (v == "go1.5" && go15ve == "1") || + (v == "go1.6" && go15ve != "0") || + (v == "devel" && go15ve != "0") + + ws := filepath.Join("Godeps", "_workspace") + s, err := os.Stat(ws) + if err == nil && s.IsDir() { + if ev { + log.Printf("WARNING: Go version (%s) & $GO15VENDOREXPERIMENT=%s wants to enable the vendor experiment, but disabling because a Godep workspace (%s) exists\n", v, go15ve, ws) + } + return false + } + + return ev +} + func main() { flag.Usage = usageExit flag.Parse() @@ -86,11 +108,7 @@ func main() { log.Fatal(err) } - // VendorExperiment is the Go 1.5 vendor directory experiment flag, see - // https://github.com/golang/go/commit/183cc0cd41f06f83cb7a2490a499e3f9101befff - VendorExperiment = (majorGoVersion == "go1.5" && os.Getenv("GO15VENDOREXPERIMENT") == "1") || - (majorGoVersion == "go1.6" && os.Getenv("GO15VENDOREXPERIMENT") != "0") || - (majorGoVersion == "devel" && os.Getenv("GO15VENDOREXPERIMENT") != "0") + VendorExperiment = determineVendor(majorGoVersion) // sep is the signature set of path elements that // precede the original path of an imported package. diff --git a/version.go b/version.go index aa5d57e..3079a15 100644 --- a/version.go +++ b/version.go @@ -5,7 +5,7 @@ import ( "runtime" ) -const version = 52 +const version = 53 var cmdVersion = &Command{ Name: "version",