Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enrich version --long's output with build deps #7864

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features

* (types/coin.go) [\#6755](https://github.com/cosmos/cosmos-sdk/pull/6755) Add custom regex validation for `Coin` denom by overwriting `CoinDenomRegex` when using `/types/coin.go`.
* (version) [\#7835](https://github.com/cosmos/cosmos-sdk/issues/7835) The version --long command now shows the list of build dependencies and their versioning information.

### Bug Fixes

Expand Down
39 changes: 32 additions & 7 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package version

import (
"encoding/json"
"fmt"
"runtime"
"runtime/debug"
)

var (
Expand All @@ -39,13 +41,14 @@ var (

// Info defines the application version information.
type Info struct {
Name string `json:"name" yaml:"name"`
ServerName string `json:"server_name" yaml:"server_name"`
ClientName string `json:"client_name" yaml:"client_name"`
Version string `json:"version" yaml:"version"`
GitCommit string `json:"commit" yaml:"commit"`
BuildTags string `json:"build_tags" yaml:"build_tags"`
GoVersion string `json:"go" yaml:"go"`
Name string `json:"name" yaml:"name"`
ServerName string `json:"server_name" yaml:"server_name"`
ClientName string `json:"client_name" yaml:"client_name"`
Version string `json:"version" yaml:"version"`
GitCommit string `json:"commit" yaml:"commit"`
BuildTags string `json:"build_tags" yaml:"build_tags"`
GoVersion string `json:"go" yaml:"go"`
BuildDeps []buildDep `json:"build_deps" yaml:"build_deps"`
}

func NewInfo() Info {
Expand All @@ -57,6 +60,7 @@ func NewInfo() Info {
GitCommit: Commit,
BuildTags: BuildTags,
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
BuildDeps: depsFromBuildInfo(),
}
}

Expand All @@ -68,3 +72,24 @@ build tags: %s
vi.Name, vi.Version, vi.GitCommit, vi.BuildTags, vi.GoVersion,
)
}

func depsFromBuildInfo() (deps []buildDep) {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return nil
}

for _, dep := range buildInfo.Deps {
deps = append(deps, buildDep{dep})
}

return
}

type buildDep struct {
*debug.Module
}

func (d buildDep) String() string { return fmt.Sprintf("%s@%s", d.Path, d.Version) }
func (d buildDep) MarshalJSON() ([]byte, error) { return json.Marshal(d.String()) }
func (d buildDep) MarshalYAML() (interface{}, error) { return d.String(), nil }