2022-09-19 10:04:16 +02:00
|
|
|
// Copyright 2022 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package version
|
|
|
|
|
2022-09-23 14:08:25 +02:00
|
|
|
import (
|
|
|
|
"runtime/debug"
|
|
|
|
"time"
|
|
|
|
)
|
2022-09-19 10:04:16 +02:00
|
|
|
|
|
|
|
// In go 1.18 and beyond, the go tool embeds VCS information into the build.
|
|
|
|
|
2022-09-23 14:08:25 +02:00
|
|
|
const (
|
|
|
|
govcsTimeLayout = "2006-01-02T15:04:05Z"
|
|
|
|
ourTimeLayout = "20060102"
|
|
|
|
)
|
|
|
|
|
|
|
|
// buildInfoVCS returns VCS information of the build.
|
|
|
|
func buildInfoVCS(info *debug.BuildInfo) (s VCSInfo, ok bool) {
|
2022-09-19 10:04:16 +02:00
|
|
|
for _, v := range info.Settings {
|
|
|
|
switch v.Key {
|
|
|
|
case "vcs.revision":
|
2022-09-23 14:08:25 +02:00
|
|
|
s.Commit = v.Value
|
2022-09-19 10:04:16 +02:00
|
|
|
case "vcs.modified":
|
|
|
|
if v.Value == "true" {
|
2022-09-23 14:08:25 +02:00
|
|
|
s.Dirty = true
|
2022-09-19 10:04:16 +02:00
|
|
|
}
|
|
|
|
case "vcs.time":
|
2022-09-23 14:08:25 +02:00
|
|
|
t, err := time.Parse(govcsTimeLayout, v.Value)
|
|
|
|
if err == nil {
|
|
|
|
s.Date = t.Format(ourTimeLayout)
|
|
|
|
}
|
2022-09-19 10:04:16 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-23 14:08:25 +02:00
|
|
|
if s.Commit != "" && s.Date != "" {
|
2022-09-19 10:04:16 +02:00
|
|
|
ok = true
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|