status-go/vendor/github.com/ethereum/go-ethereum/internal/version/vcs_go1.18.go

56 lines
1.5 KiB
Go
Raw Normal View History

2022-10-25 14:25:08 +00:00
// Copyright 2022 The go-ethereum Authors
2016-06-20 14:47:10 +00:00
// 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/>.
2022-10-25 14:25:08 +00:00
//go:build go1.18
// +build go1.18
package version
import (
2022-10-25 14:25:08 +00:00
"runtime/debug"
"time"
2022-10-25 14:25:08 +00:00
)
// In go 1.18 and beyond, the go tool embeds VCS information into the build.
2016-06-20 14:47:10 +00:00
2022-10-25 14:25:08 +00:00
const (
govcsTimeLayout = "2006-01-02T15:04:05Z"
ourTimeLayout = "20060102"
)
2022-10-25 14:25:08 +00:00
// buildInfoVCS returns VCS information of the build.
func buildInfoVCS(info *debug.BuildInfo) (s VCSInfo, ok bool) {
for _, v := range info.Settings {
switch v.Key {
case "vcs.revision":
s.Commit = v.Value
case "vcs.modified":
if v.Value == "true" {
s.Dirty = true
}
case "vcs.time":
t, err := time.Parse(govcsTimeLayout, v.Value)
if err == nil {
s.Date = t.Format(ourTimeLayout)
}
}
}
if s.Commit != "" && s.Date != "" {
ok = true
}
return
}