Skip to content

Commit

Permalink
cli: add cgo compiler, os and arch info to version output
Browse files Browse the repository at this point in the history
also hide the dep versions unless requested with --all since they are usually captured by the tag
thanks to glock, and thus just clutter up submitted issue reports.

```
$ ./cockroach version
Build Tag:   beta-20160331-dirty
Build Time:  2016/03/31 14:42:04
Platform:  darwin amd64
Go Version:  go1.6
C Compiler:  4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.29)
```
  • Loading branch information
dt committed Mar 31, 2016
1 parent 16754d2 commit 9cb1e88
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 34 deletions.
12 changes: 9 additions & 3 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
// Proxy to allow overrides in tests.
var osStderr = os.Stderr

var versionIncludesDeps bool

var versionCmd = &cobra.Command{
Use: "version",
Short: "output version information",
Expand All @@ -39,11 +41,15 @@ Output build version information.
Run: func(cmd *cobra.Command, args []string) {
info := util.GetBuildInfo()
tw := tabwriter.NewWriter(os.Stdout, 2, 1, 2, ' ', 0)
fmt.Fprintf(tw, "Build Vers: %s\n", info.Vers)
fmt.Fprintf(tw, "Build Tag: %s\n", info.Tag)
fmt.Fprintf(tw, "Build Time: %s\n", info.Time)
fmt.Fprintf(tw, "Build Deps:\n\t%s\n",
strings.Replace(strings.Replace(info.Deps, " ", "\n\t", -1), ":", "\t", -1))
fmt.Fprintf(tw, "Platform: %s\n", info.Platform)
fmt.Fprintf(tw, "Go Version: %s\n", info.GoVersion)
fmt.Fprintf(tw, "C Compiler: %s\n", info.CgoCompiler)
if versionIncludesDeps {
fmt.Fprintf(tw, "Build Deps:\n\t%s\n",
strings.Replace(strings.Replace(info.Deps, " ", "\n\t", -1), ":", "\t", -1))
}
_ = tw.Flush()
},
}
Expand Down
1 change: 1 addition & 0 deletions cli/cliflags/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
AttrsName = "attrs"
CacheName = "cache"
DatabaseName = "database"
DepsName = "deps"
ExecuteName = "execute"
JoinName = "join"
HostName = "host"
Expand Down
8 changes: 8 additions & 0 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Database server port to connect to for HTTP requests.`),
cliflags.DatabaseName: wrapText(`
The name of the database to connect to.`),

cliflags.DepsName: wrapText(`
Include all dependency versions`),

cliflags.ExecuteName: wrapText(`
Execute the SQL statement(s) on the command line, then exit. This flag may be
specified multiple times and each value may contain multiple semicolon
Expand Down Expand Up @@ -474,6 +477,11 @@ func initFlags(ctx *Context) {
f.BoolVar(&cliContext.debug.raw, cliflags.RawName, false, usage(cliflags.RawName))
f.BoolVar(&cliContext.debug.values, cliflags.ValuesName, false, usage(cliflags.ValuesName))
}

{
f := versionCmd.Flags()
f.BoolVar(&versionIncludesDeps, cliflags.DepsName, false, usage(cliflags.DepsName))
}
}

func init() {
Expand Down
4 changes: 2 additions & 2 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func runStart(_ *cobra.Command, _ []string) error {
}

info := util.GetBuildInfo()
log.Infof("[build] %s @ %s (%s)", info.Tag, info.Time, info.Vers)
log.Infof("[build] %s @ %s (%s)", info.Tag, info.Time, info.GoVersion)

// Default user for servers.
cliContext.User = security.NodeUser
Expand Down Expand Up @@ -194,7 +194,7 @@ func runStart(_ *cobra.Command, _ []string) error {
}

tw := tabwriter.NewWriter(os.Stdout, 2, 1, 2, ' ', 0)
fmt.Fprintf(tw, "build:\t%s @ %s (%s)\n", info.Tag, info.Time, info.Vers)
fmt.Fprintf(tw, "build:\t%s @ %s (%s)\n", info.Tag, info.Time, info.GoVersion)
fmt.Fprintf(tw, "admin:\t%s\n", cliContext.AdminURL())
fmt.Fprintf(tw, "sql:\t%s\n", pgURL)
if len(cliContext.SocketFile) != 0 {
Expand Down
34 changes: 26 additions & 8 deletions util/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,40 @@

package util

import "runtime"
import (
"fmt"
"runtime"
)

// const char* compilerVersion() {
// #if defined(__clang__)
// return __VERSION__;
// #elif defined(__GNUC__) || defined(__GNUG__)
// return "gcc " __VERSION__;
// #else
// return "unknown";
// #endif
// }
import "C"

var (
// These variables are initialized via the linker -X flag in the
// top-level Makefile when compiling release binaries.
buildTag string // Tag of this build (git describe)
buildTime string // Build time in UTC (year/month/day hour:min:sec)
buildDeps string // Git SHAs of dependencies
buildTag string // Tag of this build (git describe)
buildTime string // Build time in UTC (year/month/day hour:min:sec)
buildDeps string // Git SHAs of dependencies
buildCgoCompiler = C.GoString(C.compilerVersion())
buildPlatform = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)
)

// GetBuildInfo ...
func GetBuildInfo() BuildInfo {
return BuildInfo{
Vers: runtime.Version(),
Tag: buildTag,
Time: buildTime,
Deps: buildDeps,
GoVersion: runtime.Version(),
Tag: buildTag,
Time: buildTime,
Deps: buildDeps,
CgoCompiler: buildCgoCompiler,
Platform: buildPlatform,
}
}
115 changes: 95 additions & 20 deletions util/build.pb.go

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

4 changes: 3 additions & 1 deletion util/build.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import weak "gogoproto/gogo.proto";

// BuildInfo describes build information for this CockroachDB binary.
message BuildInfo {
optional string vers = 1 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "goVersion"];
optional string go_version = 1 [(gogoproto.nullable) = false];
optional string tag = 2 [(gogoproto.nullable) = false];
optional string time = 3 [(gogoproto.nullable) = false];
optional string deps = 4 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "dependencies"];
optional string cgo_compiler = 5 [(gogoproto.nullable) = false];
optional string platform = 6 [(gogoproto.nullable) = false];
}

0 comments on commit 9cb1e88

Please sign in to comment.