Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
Disable VendorExperiment if we have a workspace
Browse files Browse the repository at this point in the history
Several people have asked for this and it's what most people will
probably expect.

Fixes #411
  • Loading branch information
Edward Muller committed Feb 12, 2016
1 parent 3020345 commit 955e36c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
28 changes: 23 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log"
"os"
"path/filepath"
"runtime/pprof"
"strings"
"text/template"
Expand Down Expand Up @@ -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()
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime"
)

const version = 52
const version = 53

var cmdVersion = &Command{
Name: "version",
Expand Down

0 comments on commit 955e36c

Please sign in to comment.