diff options
-rw-r--r-- | BUILD.md | 37 | ||||
-rw-r--r-- | cmd/gobgp/main.go | 5 | ||||
-rw-r--r-- | cmd/gobgpd/main.go | 5 | ||||
-rw-r--r-- | internal/pkg/version/version.go | 51 |
4 files changed, 92 insertions, 6 deletions
@@ -15,6 +15,43 @@ Now ready to modify the code and build two binaries, `cmd/gobgp` and `cmd/gobgpd GoBGP releases are time-based. Minor releases will occur every month ([Semantic Versioning](https://semver.org/)). Major releases occur only when absolutely necessary. +## Versioning + +GoBGP has a internal module for version information. +```internal/pkg/version/version.go``` defines the following variables + +```MAJOR``` ```MINOR``` ```PATCH``` these constants are for the Semantic Versioning scheme. +These will be updated upon release by maintainer. + +There is also two more variables that are ment to be changed by ldflags; + +```TAG``` is supposed to be used to denote which branch the build is based upon. +```SHA``` is supposed to be used to inform about which git sha sum the build is based on. + +### Examples + +A normal release version of GoBGP Version 2.5.0 should should have; + +```golang +const MAJOR uint = 2 +const MINOR uint = 5 +const PATCH uint = 0 +``` + +If you have a non-standard release and want to have more build information there is some flags to be used. +`COMMIT`, `IDENTIFIER` and `METADATA`. + +```bash +go build -ldflags \ + "-X github.com/osrg/gobgp/internal/pkg/version.COMMIT=`git rev-parse --short HEAD` \ + -X github.com/osrg/gobgp/internal/pkg/version.METADATA="date.`date "+%Y%m%d"`" \ + -X github.com/osrg/gobgp/internal/pkg/version.IDENTIFIER=alpha" +``` + +This will produce a version number of + +```2.5.0-alpaha+commit.XXXYYYZZ.date.20190526``` + ## Layout The GoBGP project adopts [Standard Go Project Layout](https://github.com/golang-standards/project-layout). diff --git a/cmd/gobgp/main.go b/cmd/gobgp/main.go index 41f95ab2..079b1d4a 100644 --- a/cmd/gobgp/main.go +++ b/cmd/gobgp/main.go @@ -19,14 +19,13 @@ import ( "fmt" "os" + "github.com/osrg/gobgp/internal/pkg/version" "google.golang.org/grpc" ) -var version = "master" - func main() { if len(os.Args) > 1 && os.Args[1] == "--version" { - fmt.Println("gobgp version", version) + fmt.Println("gobgp version", version.Version()) os.Exit(0) } grpc.EnableTracing = false diff --git a/cmd/gobgpd/main.go b/cmd/gobgpd/main.go index 015b0a4b..7ad06434 100644 --- a/cmd/gobgpd/main.go +++ b/cmd/gobgpd/main.go @@ -39,12 +39,11 @@ import ( "github.com/osrg/gobgp/internal/pkg/apiutil" "github.com/osrg/gobgp/internal/pkg/config" "github.com/osrg/gobgp/internal/pkg/table" + "github.com/osrg/gobgp/internal/pkg/version" "github.com/osrg/gobgp/pkg/packet/bgp" "github.com/osrg/gobgp/pkg/server" ) -var version = "master" - func marshalRouteTargets(l []string) ([]*any.Any, error) { rtList := make([]*any.Any, 0, len(l)) for _, rtString := range l { @@ -132,7 +131,7 @@ func main() { } if opts.Version { - fmt.Println("gobgpd version", version) + fmt.Println("gobgpd version", version.Version()) os.Exit(0) } diff --git a/internal/pkg/version/version.go b/internal/pkg/version/version.go new file mode 100644 index 00000000..5aeee453 --- /dev/null +++ b/internal/pkg/version/version.go @@ -0,0 +1,51 @@ +// Copyright (C) 2018 Nippon Telegraph and Telephone Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package version + +import "fmt" + +const MAJOR uint = 2 +const MINOR uint = 5 +const PATCH uint = 0 + +var COMMIT string = "" +var IDENTIFIER string = "" +var METADATA string = "" + +func Version() string { + var suffix string = "" + if len(IDENTIFIER) > 0 { + suffix = fmt.Sprintf("-%s", IDENTIFIER) + } + + if len(COMMIT) > 0 || len(METADATA) > 0 { + suffix = suffix + "+" + } + + if len(COMMIT) > 0 { + suffix = fmt.Sprintf("%s"+"commit.%s", suffix, COMMIT) + + } + + if len(METADATA) > 0 { + if len(COMMIT) > 0 { + suffix = suffix + "." + } + suffix = suffix + METADATA + } + + return fmt.Sprintf("%d.%d.%d%s", MAJOR, MINOR, PATCH, suffix) +} |