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