github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/version/version.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // Package version contains versioning information for juju. It also 5 // acts as guardian of the current client Juju version number. 6 package version 7 8 import ( 9 "fmt" 10 "io/ioutil" 11 "os" 12 "path/filepath" 13 "runtime" 14 "strings" 15 16 semversion "github.com/juju/version" 17 ) 18 19 // The presence and format of this constant is very important. 20 // The debian/rules build recipe uses this value for the version 21 // number of the release package. 22 const version = "2.6-beta1" 23 24 // The version that we switched over from old style numbering to new style. 25 var switchOverVersion = semversion.MustParse("1.19.9") 26 27 // Current gives the current version of the system. If the file 28 // "FORCE-VERSION" is present in the same directory as the running 29 // binary, it will override this. 30 var Current = semversion.MustParse(version) 31 32 var Compiler = runtime.Compiler 33 34 func init() { 35 toolsDir := filepath.Dir(os.Args[0]) 36 v, err := ioutil.ReadFile(filepath.Join(toolsDir, "FORCE-VERSION")) 37 if err != nil { 38 if !os.IsNotExist(err) { 39 fmt.Fprintf(os.Stderr, "WARNING: cannot read forced version: %v\n", err) 40 } 41 return 42 } 43 Current = semversion.MustParse(strings.TrimSpace(string(v))) 44 } 45 46 func isOdd(x int) bool { 47 return x%2 != 0 48 } 49 50 // IsDev returns whether the version represents a development version. A 51 // version with a tag or a nonzero build component is considered to be a 52 // development version. Versions older than or equal to 1.19.3 (the switch 53 // over time) check for odd minor versions. 54 func IsDev(v semversion.Number) bool { 55 if v.Compare(switchOverVersion) <= 0 { 56 return isOdd(v.Minor) || v.Build > 0 57 } 58 return v.Tag != "" || v.Build > 0 59 }