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

Commit

Permalink
Record / Update only the major go version
Browse files Browse the repository at this point in the history
After some issue discussion (heroku/heroku-buildpack-go/100 and another
I can't find atm) I generally think that we should really only care
about the major version of Go and let downstream systems care about
selecting the minor version (the user or build systems). There are
probably exceptions to that, hence I also stopped auto-updating the go
version on save, allowing people to specify whatever they want if they
manually want to manage the file.
  • Loading branch information
Edward Muller committed Dec 16, 2015
1 parent cd25263 commit 2721f68
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 22 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v39 2015/12/16

* Record only the major go version (ex. go1.5) instead of the complete string.

# v38 2015/12/16

* Replace `go get`, further fix up restore error handling/reporting.
Expand Down
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,17 @@ func uniq(a []string) []string {
return a[:i]
}

// goVersion returns the version string of the Go compiler
// currently installed, e.g. "go1.1rc3".
// trimGoVersion and return the major version
func trimGoVersion(version string) (string, error) {
p := strings.Split(version, ".")
if len(p) < 2 {
return "", fmt.Errorf("Error determing major go version from: %q", version)
}
return p[0] + "." + p[1], nil
}

// goVersion returns the major version string of the Go compiler
// currently installed, e.g. "go1.5".
func goVersion() (string, error) {
// Godep might have been compiled with a different
// version, so we can't just use runtime.Version here.
Expand All @@ -79,9 +88,9 @@ func goVersion() (string, error) {
if err != nil {
return "", err
}
p := strings.Split(string(out), " ")
if len(p) < 3 {
gv := strings.Split(string(out), " ")
if len(gv) < 3 {
return "", fmt.Errorf("Error splitting output of `go version`: Expected 3 or more elements, but there are < 3: %q", string(out))
}
return p[2], nil
return trimGoVersion(gv[2])
}
7 changes: 1 addition & 6 deletions diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ func runDiff(cmd *Command, args []string) {
log.Fatalln(err)
}

ver, err := goVersion()
if err != nil {
log.Fatalln(err)
}

gnew := &Godeps{
ImportPath: dot[0].ImportPath,
GoVersion: ver,
GoVersion: gold.GoVersion,
}

err = gnew.fill(dot, dot[0].ImportPath)
Expand Down
37 changes: 34 additions & 3 deletions save.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,25 @@ func save(pkgs []string) error {
}
debugln("dotPackageImportPath:", dip)

ver, err := goVersion()
cv, err := goVersion()
if err != nil {
return err
}
debugln("goVersion:", ver)
debugln("goVersion:", cv)

gold, err := loadDefaultGodepsFile()
if err != nil {
if !os.IsNotExist(err) {
return err
}
gold.GoVersion = cv
}

printVersionWarnings(gold.GoVersion)

gnew := &Godeps{
ImportPath: dip,
GoVersion: ver,
GoVersion: gold.GoVersion,
}

switch len(pkgs) {
Expand Down Expand Up @@ -191,6 +194,34 @@ func save(pkgs []string) error {
return rewrite(a, dip, rewritePaths)
}

func printVersionWarnings(ov string) {
var warning bool
cv, err := goVersion()
if err != nil {
return
}
tov, err := trimGoVersion(ov)
if err != nil {
return
}
tcv, err := trimGoVersion(cv)
if err != nil {
return
}

if tov != ov {
log.Printf("WARNING: Recorded go version (%s) with minor version string found.\n", ov)
warning = true
}
if tcv != tov {
log.Printf("WARNING: Recorded major go version (%s) and in-use major go version (%s) differ.\n", tov, tcv)
warning = true
}
if warning {
log.Println("To record current major go version run `godep update -goversion`.")
}
}

type revError struct {
ImportPath string
WantRev string
Expand Down
49 changes: 43 additions & 6 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"go/parser"
"go/token"
"log"
"os"
"path"
"path/filepath"
"strconv"
Expand All @@ -12,30 +13,66 @@ import (

var cmdUpdate = &Command{
Name: "update",
Args: "[packages]",
Short: "use different revision of selected packages",
Args: "[-goversion] [packages]",
Short: "update selected packages or the go version",
Long: `
Update changes the named dependency packages to use the
revision of each currently installed in GOPATH. New code will
be copied into Godeps and the new revision will be written to
the manifest.
be copied into the Godeps workspace or vendor folder and the
new revision will be written to the manifest.
For more about specifying packages, see 'go help packages'.
If -goversion is specified, update the recorded go version.
If -d is given, debug output is enabled (you probably don't want this).
For more about specifying packages, see 'go help packages'.
`,
Run: runUpdate,
}
var (
updateGoVer bool
)

func init() {
cmdUpdate.Flag.BoolVar(&saveT, "t", false, "save test files during update")
cmdUpdate.Flag.BoolVar(&updateGoVer, "goversion", false, "update the recorded go version")
}

func runUpdate(cmd *Command, args []string) {
err := update(args)
if updateGoVer {
updateGoVersion()
}
if len(args) > 0 {
err := update(args)
if err != nil {
log.Fatalln(err)
}
}
}

func updateGoVersion() {
gold, err := loadDefaultGodepsFile()
if err != nil {
if !os.IsNotExist(err) {
log.Fatalln(err)
}
}
cv, err := goVersion()
if err != nil {
log.Fatalln(err)
}

gv := gold.GoVersion
gold.GoVersion = cv
_, err = gold.save()
if err != nil {
log.Fatalln(err)
}

if gv != cv {
log.Println("Updated major go version to", cv)
}

}

func update(args []string) error {
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 = 38
const version = 39

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

0 comments on commit 2721f68

Please sign in to comment.