From b3c4be016d9fc6056da661c2d8e7d08da6aaafd7 Mon Sep 17 00:00:00 2001 From: Michael de Hoog Date: Wed, 26 Jul 2023 14:53:33 -1000 Subject: [PATCH] Set op-geth version at build --- build/ci.go | 3 +++ params/version.go | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/build/ci.go b/build/ci.go index 3950f7d12c..596192206f 100644 --- a/build/ci.go +++ b/build/ci.go @@ -251,6 +251,9 @@ func buildFlags(env build.Environment, staticLinking bool, buildTags []string) ( ld = append(ld, "-X", "github.com/ethereum/go-ethereum/internal/version.gitCommit="+env.Commit) ld = append(ld, "-X", "github.com/ethereum/go-ethereum/internal/version.gitDate="+env.Date) } + if env.Tag != "" { + ld = append(ld, "-X", "github.com/ethereum/go-ethereum/params.gitTag="+env.Tag) + } // Strip DWARF on darwin. This used to be required for certain things, // and there is no downside to this, so we just keep doing it. if runtime.GOOS == "darwin" { diff --git a/params/version.go b/params/version.go index f5785230ec..ed8eedc2ed 100644 --- a/params/version.go +++ b/params/version.go @@ -18,6 +18,8 @@ package params import ( "fmt" + "regexp" + "strconv" ) // Version is the version of upstream geth @@ -29,13 +31,33 @@ const ( ) // OPVersion is the version of op-geth -const ( +var ( OPVersionMajor = 0 // Major version component of the current release OPVersionMinor = 1 // Minor version component of the current release OPVersionPatch = 0 // Patch version component of the current release OPVersionMeta = "unstable" // Version metadata to append to the version string ) +// This is set at build-time by the linker when the build is done by build/ci.go. +var gitTag string + +// Override the version variables if the gitTag was set at build time. +var _ = func() (_ string) { + semver := regexp.MustCompile("^v([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$") + version := semver.FindStringSubmatch(gitTag) + if version == nil { + return + } + if version[4] == "" { + version[4] = "stable" + } + OPVersionMajor, _ = strconv.Atoi(version[1]) + OPVersionMinor, _ = strconv.Atoi(version[2]) + OPVersionPatch, _ = strconv.Atoi(version[3]) + OPVersionMeta = version[4] + return +}() + // Version holds the textual version string. var Version = func() string { return fmt.Sprintf("%d.%d.%d", OPVersionMajor, OPVersionMinor, OPVersionPatch)