forked from cerc-io/plugeth
internal/version: use gitCommit injection in version handling code (#25851)
This changes the CI build to store the git commit and date into package internal/version instead of package main. Doing this essentially merges our two ways of tracking the go-ethereum version into a single place, achieving two objectives: - Bad block reports, which use version.Info(), will now have the git commit information even when geth is built in an environment such as launchpad.net where git access is unavailable. - For geth builds created by `go build ./cmd/geth` (i.e. not using `go run build/ci.go install`), git information stored by the go tool is now used in the p2p node name as well as in `geth version` and `geth version-check`.
This commit is contained in:
@@ -19,6 +19,7 @@ package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
@@ -27,6 +28,43 @@ import (
|
||||
|
||||
const ourPath = "github.com/ethereum/go-ethereum" // Path to our module
|
||||
|
||||
// These variables are set at build-time by the linker when the build is
|
||||
// done by build/ci.go.
|
||||
var gitCommit, gitDate string
|
||||
|
||||
// VCSInfo represents the git repository state.
|
||||
type VCSInfo struct {
|
||||
Commit string // head commit hash
|
||||
Date string // commit time in YYYYMMDD format
|
||||
Dirty bool
|
||||
}
|
||||
|
||||
// VCS returns version control information of the current executable.
|
||||
func VCS() (VCSInfo, bool) {
|
||||
if gitCommit != "" {
|
||||
// Use information set by the build script if present.
|
||||
return VCSInfo{Commit: gitCommit, Date: gitDate}, true
|
||||
}
|
||||
if buildInfo, ok := debug.ReadBuildInfo(); ok {
|
||||
if buildInfo.Main.Path == ourPath {
|
||||
return buildInfoVCS(buildInfo)
|
||||
}
|
||||
}
|
||||
return VCSInfo{}, false
|
||||
}
|
||||
|
||||
// ClientName creates a software name/version identifier according to common
|
||||
// conventions in the Ethereum p2p network.
|
||||
func ClientName(clientIdentifier string) string {
|
||||
git, _ := VCS()
|
||||
return fmt.Sprintf("%s/v%v/%v-%v/%v",
|
||||
strings.Title(clientIdentifier),
|
||||
params.VersionWithCommit(git.Commit, git.Date),
|
||||
runtime.GOOS, runtime.GOARCH,
|
||||
runtime.Version(),
|
||||
)
|
||||
}
|
||||
|
||||
// runtimeInfo returns build and platform information about the current binary.
|
||||
//
|
||||
// If the package that is currently executing is a prefixed by our go-ethereum
|
||||
@@ -40,22 +78,20 @@ func Info() (version, vcs string) {
|
||||
return version, ""
|
||||
}
|
||||
version = versionInfo(buildInfo)
|
||||
if status, ok := vcsInfo(buildInfo); ok {
|
||||
if status, ok := VCS(); ok {
|
||||
modified := ""
|
||||
if status.modified {
|
||||
if status.Dirty {
|
||||
modified = " (dirty)"
|
||||
}
|
||||
vcs = status.revision + "-" + status.time + modified
|
||||
commit := status.Commit
|
||||
if len(commit) > 8 {
|
||||
commit = commit[:8]
|
||||
}
|
||||
vcs = commit + "-" + status.Date + modified
|
||||
}
|
||||
return version, vcs
|
||||
}
|
||||
|
||||
type gitStatus struct {
|
||||
revision string
|
||||
time string
|
||||
modified bool
|
||||
}
|
||||
|
||||
// versionInfo returns version information for the currently executing
|
||||
// implementation.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user