Use -ldflags to set git commit version

This commit is contained in:
Clayton Coleman
2014-08-25 09:21:03 -04:00
parent 0a06de63dc
commit 9336373857
6 changed files with 33 additions and 72 deletions

View File

@@ -1,23 +0,0 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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
// This file is the template for the machine-edited autogenerated.go.
// Do not modify this file without also modifying hack/version-gen.sh.
var (
commitFromGit = `@@GIT_COMMIT@@`
)

View File

@@ -20,6 +20,10 @@ import (
"fmt"
)
// commitFromGit is a constant representing the source version that
// generated this build. It should be set during build via -ldflags.
var commitFromGit string
// Info contains versioning information.
// TODO: Add []string of api versions supported? It's still unclear
// how we'll want to distribute that information.
@@ -41,5 +45,9 @@ func Get() Info {
// String returns info as a human-friendly version string.
func (info Info) String() string {
return fmt.Sprintf("version %s.%s, build %s", info.Major, info.Minor, info.GitCommit)
commit := info.GitCommit
if commit == "" {
commit = "(unknown)"
}
return fmt.Sprintf("version %s.%s, build %s", info.Major, info.Minor, commit)
}